os.path.join( os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))), '..', '..', 'data_sets')) filename = os.path.join(dataDirectory, 'Dij.txt') D_frame = read_spectral_data_from_txt(filename) ###################################### builder = TemplateBuilder() components = {'A': 1e-3, 'B': 0, 'C': 0} builder.add_mixture_component(components) # note the parameter is not fixed builder.add_parameter('k1', bounds=(0.0, 5.0)) builder.add_parameter('k2', bounds=(0.0, 1.0)) builder.add_spectral_data(D_frame) # define explicit system of ODEs def rule_odes(m, t): exprs = dict() exprs['A'] = -m.P['k1'] * m.Z[t, 'A'] exprs['B'] = m.P['k1'] * m.Z[t, 'A'] - m.P['k2'] * m.Z[t, 'B'] exprs['C'] = m.P['k2'] * m.Z[t, 'B'] return exprs builder.set_odes_rule(rule_odes) pyomo_model = builder.create_pyomo_model(0.0, 10.0) optimizer = ParameterEstimator(pyomo_model) optimizer.apply_discretization('dae.collocation',
tee=True, variances=sigmas, seed=123453256) if with_plots: results_sim.C.plot.line() results_sim.S.plot.line() plt.show() ################################################################################# builder = TemplateBuilder() builder.add_mixture_component(concentrations) builder.add_parameter('k', bounds=(0.0, 1.0)) builder.add_spectral_data(results_sim.D) builder.set_odes_rule(rule_odes) opt_model = builder.create_pyomo_model(0.0, 200.0) v_estimator = VarianceEstimator(opt_model) v_estimator.apply_discretization('dae.collocation', nfe=4, ncp=1, scheme='LAGRANGE-RADAU') v_estimator.initialize_from_trajectory('Z', results_sim.Z) v_estimator.initialize_from_trajectory('S', results_sim.S) v_estimator.scale_variables_from_trajectory('Z', results_sim.Z) v_estimator.scale_variables_from_trajectory('S', results_sim.S)