Skip to content

Commit

Permalink
simplified use of suffix update and removed extra prints
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklise committed Apr 30, 2024
1 parent c7f3634 commit 539d62d
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ def label_model(self):
m = self.model

m.experiment_outputs = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.experiment_outputs.update([(m.x1, self.data['x1'])])
m.experiment_outputs.update([(m.x2, self.data['x2'])])
m.experiment_outputs.update([(m.y, self.data['y'])])
m.experiment_outputs.update([(m.x1, self.data['x1']),
(m.x2, self.data['x2']),
(m.y, self.data['y'])])

return m

Expand Down Expand Up @@ -156,7 +156,7 @@ def main():

# View one model
# exp0_model = exp_list[0].get_labeled_model()
# print(exp0_model.pprint())
# exp0_model.pprint()

# =======================================================================
# Parameter estimation without covariance estimate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def main():

# View one model
# exp0_model = exp_list[0].get_labeled_model()
# print(exp0_model.pprint())
# exp0_model.pprint()

pest = parmest.Estimator(exp_list, obj_function='SSE')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ___________________________________________________________________________
#
# Pyomo: Python Optimization Modeling Objects
# Copyright (c) 2008-2022
# Copyright (c) 2008-2024
# National Technology and Engineering Solutions of Sandia, LLC
# Under the terms of Contract DE-NA0003525 with National Technology and
# Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
Expand Down Expand Up @@ -31,7 +31,7 @@ def main():

# View one model
# exp0_model = exp_list[0].get_labeled_model()
# print(exp0_model.pprint())
# exp0_model.pprint()

pest = parmest.Estimator(exp_list, obj_function='SSE')

Expand Down
24 changes: 12 additions & 12 deletions pyomo/contrib/parmest/examples/reactor_design/datarec_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ def label_model(self):

# experiment outputs
m.experiment_outputs = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.experiment_outputs.update([(m.ca, self.data_i['ca'])])
m.experiment_outputs.update([(m.cb, self.data_i['cb'])])
m.experiment_outputs.update([(m.cc, self.data_i['cc'])])
m.experiment_outputs.update([(m.cd, self.data_i['cd'])])
m.experiment_outputs.update([(m.ca, self.data_i['ca']),
(m.cb, self.data_i['cb']),
(m.cc, self.data_i['cc']),
(m.cd, self.data_i['cd'])])

# experiment standard deviations
m.experiment_outputs_std = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.experiment_outputs_std.update([(m.ca, self.data_std['ca'])])
m.experiment_outputs_std.update([(m.cb, self.data_std['cb'])])
m.experiment_outputs_std.update([(m.cc, self.data_std['cc'])])
m.experiment_outputs_std.update([(m.cd, self.data_std['cd'])])
m.experiment_outputs_std.update([(m.ca, self.data_std['ca']),
(m.cb, self.data_std['cb']),
(m.cc, self.data_std['cc']),
(m.cd, self.data_std['cd'])])

# no unknowns (theta names)
m.unknown_parameters = pyo.Suffix(direction=pyo.Suffix.LOCAL)
Expand All @@ -71,10 +71,10 @@ def label_model(self):

# add experiment standard deviations
m.experiment_outputs_std = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.experiment_outputs_std.update([(m.ca, self.data_std['ca'])])
m.experiment_outputs_std.update([(m.cb, self.data_std['cb'])])
m.experiment_outputs_std.update([(m.cc, self.data_std['cc'])])
m.experiment_outputs_std.update([(m.cd, self.data_std['cd'])])
m.experiment_outputs_std.update([(m.ca, self.data_std['ca']),
(m.cb, self.data_std['cb']),
(m.cc, self.data_std['cc']),
(m.cd, self.data_std['cd'])])

return m

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def main():

# View one model
# exp0_model = exp_list[0].get_labeled_model()
# print(exp0_model.pprint())
# exp0_model.pprint()

pest = parmest.Estimator(exp_list, obj_function='SSE')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def main():

# View one model
# exp0_model = exp_list[0].get_labeled_model()
# print(exp0_model.pprint())
# exp0_model.pprint()

pest = parmest.Estimator(exp_list, obj_function='SSE')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ def label_model(self):
m = self.model

m.experiment_outputs = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.experiment_outputs.update(
[(m.ca, [self.data_i['ca1'], self.data_i['ca2'], self.data_i['ca3']])]
)
m.experiment_outputs.update([(m.cb, [self.data_i['cb']])])
m.experiment_outputs.update([(m.cc, [self.data_i['cc1'], self.data_i['cc2']])])
m.experiment_outputs.update([(m.cd, [self.data_i['cd']])])
m.experiment_outputs.update([
(m.ca, [self.data_i['ca1'], self.data_i['ca2'], self.data_i['ca3']]),
(m.cb, [self.data_i['cb']]),
(m.cc, [self.data_i['cc1'], self.data_i['cc2']]),
(m.cd, [self.data_i['cd']])])

m.unknown_parameters = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.unknown_parameters.update(
Expand Down Expand Up @@ -80,8 +79,8 @@ def SSE_multisensor(model):

# View one model
# exp0_model = exp_list[0].get_labeled_model()
# print(exp0_model.pprint())
# print(SSE_multisensor(exp0_model))
# exp0_model.pprint()
# SSE_multisensor(exp0_model)

pest = parmest.Estimator(exp_list, obj_function=SSE_multisensor)
obj, theta = pest.theta_est()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def main():

# View one model
# exp0_model = exp_list[0].get_labeled_model()
# print(exp0_model.pprint())
# exp0_model.pprint()

pest = parmest.Estimator(exp_list, obj_function='SSE')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ def label_model(self):
m = self.model

m.experiment_outputs = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.experiment_outputs.update([(m.ca, self.data_i['ca'])])
m.experiment_outputs.update([(m.cb, self.data_i['cb'])])
m.experiment_outputs.update([(m.cc, self.data_i['cc'])])
m.experiment_outputs.update([(m.cd, self.data_i['cd'])])
m.experiment_outputs.update([(m.ca, self.data_i['ca']),
(m.cb, self.data_i['cb']),
(m.cc, self.data_i['cc']),
(m.cd, self.data_i['cd'])])

m.unknown_parameters = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.unknown_parameters.update(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def SSE_timeseries(model):

# View one model & SSE
# exp0_model = exp_list[0].get_labeled_model()
# print(exp0_model.pprint())
# exp0_model.pprint()
# print(SSE_timeseries(exp0_model))

pest = parmest.Estimator(exp_list, obj_function=SSE_timeseries)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def SSE(model):

# View one model
# exp0_model = exp_list[0].get_labeled_model()
# print(exp0_model.pprint())
# exp0_model.pprint()

# Create an instance of the parmest estimator
pest = parmest.Estimator(exp_list, obj_function=SSE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def SSE(model):

# View one model
# exp0_model = exp_list[0].get_labeled_model()
# print(exp0_model.pprint())
# exp0_model.pprint()

# Create an instance of the parmest estimator
pest = parmest.Estimator(exp_list, obj_function=SSE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def SSE(model):

# View one model
# exp0_model = exp_list[0].get_labeled_model()
# print(exp0_model.pprint())
# exp0_model.pprint()

# Create an instance of the parmest estimator
pest = parmest.Estimator(exp_list, obj_function=SSE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def label_model(self):
m = self.model

m.experiment_outputs = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.experiment_outputs.update([(m.hour, self.data['hour'])])
m.experiment_outputs.update([(m.y, self.data['y'])])
m.experiment_outputs.update([(m.hour, self.data['hour']),
(m.y, self.data['y'])])

m.unknown_parameters = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.unknown_parameters.update(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def label_model(self):
m = self.model

m.experiment_outputs = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.experiment_outputs.update([(m.hour, self.data['hour'])])
m.experiment_outputs.update([(m.y, self.data['y'])])
m.experiment_outputs.update([(m.hour, self.data['hour']),
(m.y, self.data['y'])])

m.unknown_parameters = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.unknown_parameters.update(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def main():

# View one model
# exp0_model = exp_list[0].get_labeled_model()
# print(exp0_model.pprint())
# exp0_model.pprint()

# Note, the model already includes a 'SecondStageCost' expression
# for sum of squared error that will be used in parameter estimation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def main():

# View one model
# exp0_model = exp_list[0].get_labeled_model()
# print(exp0_model.pprint())
# exp0_model.pprint()

pest = parmest.Estimator(exp_list)

Expand Down
8 changes: 4 additions & 4 deletions pyomo/contrib/parmest/tests/test_parmest.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ def label_model(self):
m = self.model

m.experiment_outputs = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.experiment_outputs.update([(m.hour, self.data["hour"])])
m.experiment_outputs.update([(m.y, self.data["y"])])
m.experiment_outputs.update([(m.hour, self.data["hour"]),
(m.y, self.data["y"])])

m.unknown_parameters = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.unknown_parameters.update((k, pyo.ComponentUID(k)) for k in [m.theta])
Expand Down Expand Up @@ -506,8 +506,8 @@ def label_model(self):
m = self.model

m.experiment_outputs = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.experiment_outputs.update([(m.hour, self.data["hour"])])
m.experiment_outputs.update([(m.y, self.data["y"])])
m.experiment_outputs.update([(m.hour, self.data["hour"]),
(m.y, self.data["y"])])

m.unknown_parameters = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.unknown_parameters.update((k, pyo.ComponentUID(k)) for k in [m.theta])
Expand Down

0 comments on commit 539d62d

Please sign in to comment.