Skip to content

Commit

Permalink
ready to add extra index
Browse files Browse the repository at this point in the history
  • Loading branch information
jialuw96 committed Oct 6, 2021
1 parent d40a618 commit 59ae4c7
Show file tree
Hide file tree
Showing 2 changed files with 628 additions and 1,119 deletions.
28 changes: 25 additions & 3 deletions pyomo/contrib/doe/fim_doe.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ def __init__(self, param_init, design_variable_timepoints, measurement_variable_
self.create_model = create_model
self.args = args
self.measurement_extra_index = measurement_extra_index
extra_measure_name = list(measurement_extra_index.keys())
extra_measure_value = list(measurement_extra_index.values())
# check if measurement variables need to be flattened
if self.measurement_extra_index is not None:
flatten_measure_name=[]
for j in self.measurement_variables:
if j in extra_measure_name:
for ind in measurement_extra_index[j]:
flatten_name = j + str(ind)
flatten_measure_name.append(flatten_name)
else:
flatten_measure_name.append(j)
else:
flatten_measure_name = self.measurement_variables.copy()

self.flatten_measure_name = flatten_measure_name
print('The flattend measurements include:', self.flatten_measure_name)

# check if user-defined solver is given
if solver is not None:
self.solver = solver
Expand Down Expand Up @@ -697,9 +715,12 @@ def __finite_calculation(self, output_record, scena_gen):
Returns:
'''
# dictionary form of jacobian
jac = {}
# 3-D array form of jacobian
#jac_3Darray = np.zeors((len(self.flatten_measure_name), len(self.param_name), len(self.measurement_timeset[0])))
# After collecting outputs from all scenarios, calculate sensitivity
for para in self.param_name:
for no_p, para in enumerate(self.param_name):
# extract involved scenario No. for each parameter from scenario class
involved_s = scena_gen.scenario_para[para]
# each parameter has two involved scenarios
Expand All @@ -714,6 +735,7 @@ def __finite_calculation(self, output_record, scena_gen):
sensi = (output_record[s1][i] - output_record[s2][i]) / scena_gen.eps_abs[
para] * self.scale_constant_value
list_jac.append(sensi)
#jac_3Darray[,no_p,]
# get Jacobian dict, keys are parameter name, values are sensitivity info
jac[para] = list_jac

Expand Down Expand Up @@ -1591,7 +1613,7 @@ def create_scenario(self):


class FIM_result:
def __init__(self, para_name, measurement_variables, measurement_timeset, measurement_extra_index, prior_FIM=None, store_FIM=None, scale_constant_value=1, max_condition_number=1.0E12,
def __init__(self, para_name, measurement_variables, measurement_timeset, prior_FIM=None, store_FIM=None, scale_constant_value=1, max_condition_number=1.0E12,
verbose=True):
'''
Analyze the FIM result for a single run
Expand All @@ -1611,7 +1633,7 @@ def __init__(self, para_name, measurement_variables, measurement_timeset, measur
self.para_name = para_name
self.measurement_variables = measurement_variables
self.measurement_timeset = measurement_timeset
self.measurement_extra_index = measurement_extra_index
#self.measurement_extra_index = measurement_extra_index
self.prior_FIM = prior_FIM
self.store_FIM = store_FIM
self.scale_constant_value = scale_constant_value
Expand Down
Loading

0 comments on commit 59ae4c7

Please sign in to comment.