@@ -107,65 +107,10 @@ The experiment class has one required method:
107107This step shows how to create the :class: `~pyomo.contrib.parmest.experiment.Experiment ` class using the
108108mathematical model outlined in the introduction section of this Quick Start.
109109
110- .. doctest ::
111-
112- >>> class RooneyBieglerExperiment (Experiment ):
113- ... def __init__ (self , data ):
114- ... self .data = data
115- ... self .model = None
116- ...
117- ... def create_model (self ):
118- ... # the model expects a dataframe
119- ... data_df = self .data.to_frame().transpose()
120- ...
121- ... # create the pyomo model
122- ... m = self .model = pyo.ConcreteModel()
123- ...
124- ... # add asymptote and rate constant to the model
125- ... m.asymptote = pyo.Var(initialize = 15 )
126- ... m.rate_constant = pyo.Var(initialize = 0.5 )
127- ...
128- ... # add the measured variable, y, to the model
129- ... m.y = pyo.Var(data_df.hour, within = pyo.PositiveReals, initialize = 5 )
130- ...
131- ... # add the mathematical equation for predicting y
132- ... def response_rule (m , h ):
133- ... return m.y[h] == m.asymptote * (1 - pyo.exp(- m.rate_constant * h))
134- ...
135- ... m.response_function = pyo.Constraint(data_df.hour, rule = response_rule)
136- ...
137- ... return m
138- ...
139- ... def label_model (self ):
140- ...
141- ... m = self .model
142- ...
143- ... # label the experiment outputs
144- ... m.experiment_outputs = pyo.Suffix(direction = pyo.Suffix.LOCAL )
145- ... m.experiment_outputs.update([(m.y[self .data[' hour' ]], self .data[' y' ])])
146- ...
147- ... # label the unknown parameters in the model
148- ... m.unknown_parameters = pyo.Suffix(direction = pyo.Suffix.LOCAL )
149- ... m.unknown_parameters.update(
150- ... (k, pyo.ComponentUID(k)) for k in [m.asymptote, m.rate_constant]
151- ... )
152- ...
153- ... # add the measurement error assumed to be constant and 0.1
154- ... m.measurement_error = pyo.Suffix(direction = pyo.Suffix.LOCAL )
155- ... m.measurement_error.update([(m.y[self .data[' hour' ]], 0.1 )])
156- ...
157- ... def finalize_model (self ):
158- ...
159- ... m = self .model
160- ... pass
161- ...
162- ... def get_labeled_model (self ):
163- ... self .create_model()
164- ... self .label_model()
165- ... self .finalize_model()
166- ...
167- ... return self .model
168-
110+ .. literalinclude :: ../../../pyomo/contrib/parmest/examples/rooney_biegler/rooney_biegler.py
111+ :language: python
112+ :pyobject: RooneyBieglerExperiment
113+ :caption: RooneyBieglerExperiment class from the parmest example
169114
170115Step 2: Load the Data and Create a List of Experiments
171116------------------------------------------------------
0 commit comments