Skip to content

Commit

Permalink
Data formatting moved to create_model
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklise committed Feb 16, 2024
1 parent edfc620 commit 2bcb0e0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def SSE(model):
# Create an experiment list
exp_list = []
for i in range(data.shape[0]):
exp_list.append(RooneyBieglerExperiment(data.loc[i, :].to_frame().transpose()))
exp_list.append(RooneyBieglerExperiment(data.loc[i, :]))

# View one model
# exp0_model = exp_list[0].get_labeled_model()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def SSE(model):
# Create an experiment list
exp_list = []
for i in range(data.shape[0]):
exp_list.append(RooneyBieglerExperiment(data.loc[i, :].to_frame().transpose()))
exp_list.append(RooneyBieglerExperiment(data.loc[i, :]))

# View one model
# exp0_model = exp_list[0].get_labeled_model()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def SSE(model):
# Create an experiment list
exp_list = []
for i in range(data.shape[0]):
exp_list.append(RooneyBieglerExperiment(data.loc[i, :].to_frame().transpose()))
exp_list.append(RooneyBieglerExperiment(data.loc[i, :]))

# View one model
# exp0_model = exp_list[0].get_labeled_model()
Expand Down
12 changes: 7 additions & 5 deletions pyomo/contrib/parmest/examples/rooney_biegler/rooney_biegler.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ def __init__(self, data):
self.model = None

def create_model(self):
self.model = rooney_biegler_model(self.data)
# rooney_biegler_model expects a dataframe
data_df = self.data.to_frame().transpose()
self.model = rooney_biegler_model(data_df)

def label_model(self):

m = self.model

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

m.unknown_parameters = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.unknown_parameters.update(
Expand All @@ -72,8 +74,8 @@ def finalize_model(self):
m = self.model

# Experiment output values
m.hour = self.data.iloc[0]['hour']
m.y = self.data.iloc[0]['y']
m.hour = self.data['hour']
m.y = self.data['y']

def get_labeled_model(self):
self.create_model()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,17 @@ def __init__(self, data):
self.model = None

def create_model(self):
self.model = rooney_biegler_model_with_constraint(self.data)
# rooney_biegler_model_with_constraint expects a dataframe
data_df = self.data.to_frame().transpose()
self.model = rooney_biegler_model_with_constraint(data_df)

def label_model(self):

m = self.model

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

m.unknown_parameters = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.unknown_parameters.update(
Expand All @@ -76,8 +78,8 @@ def finalize_model(self):
m = self.model

# Experiment output values
m.hour = self.data.iloc[0]['hour']
m.y = self.data.iloc[0]['y']
m.hour = self.data['hour']
m.y = self.data['y']

def get_labeled_model(self):
self.create_model()
Expand Down
32 changes: 18 additions & 14 deletions pyomo/contrib/parmest/tests/test_parmest.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def SSE(model):
exp_list = []
for i in range(data.shape[0]):
exp_list.append(
RooneyBieglerExperiment(data.loc[i, :].to_frame().transpose())
RooneyBieglerExperiment(data.loc[i, :])
)

# Create an instance of the parmest estimator
Expand Down Expand Up @@ -386,13 +386,14 @@ def response_rule(m, h):
class RooneyBieglerExperimentParams(RooneyBieglerExperiment):

def create_model(self):
self.model = rooney_biegler_params(self.data)
data_df = self.data.to_frame().transpose()
self.model = rooney_biegler_params(data_df)

rooney_biegler_params_exp_list = []
for i in range(self.data.shape[0]):
rooney_biegler_params_exp_list.append(
RooneyBieglerExperimentParams(
self.data.loc[i, :].to_frame().transpose()
self.data.loc[i, :]
)
)

Expand Down Expand Up @@ -422,15 +423,16 @@ def response_rule(m, h):
class RooneyBieglerExperimentIndexedParams(RooneyBieglerExperiment):

def create_model(self):
self.model = rooney_biegler_indexed_params(self.data)
data_df = self.data.to_frame().transpose()
self.model = rooney_biegler_indexed_params(data_df)

def label_model(self):

m = self.model

m.experiment_outputs = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.experiment_outputs.update([(m.hour, self.data.iloc[0]['hour'])])
m.experiment_outputs.update([(m.y, self.data.iloc[0]['y'])])
m.experiment_outputs.update([(m.hour, self.data['hour'])])
m.experiment_outputs.update([(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 All @@ -439,7 +441,7 @@ def label_model(self):
for i in range(self.data.shape[0]):
rooney_biegler_indexed_params_exp_list.append(
RooneyBieglerExperimentIndexedParams(
self.data.loc[i, :].to_frame().transpose()
self.data.loc[i, :]
)
)

Expand All @@ -465,12 +467,13 @@ def response_rule(m, h):
class RooneyBieglerExperimentVars(RooneyBieglerExperiment):

def create_model(self):
self.model = rooney_biegler_vars(self.data)
data_df = self.data.to_frame().transpose()
self.model = rooney_biegler_vars(data_df)

rooney_biegler_vars_exp_list = []
for i in range(self.data.shape[0]):
rooney_biegler_vars_exp_list.append(
RooneyBieglerExperimentVars(self.data.loc[i, :].to_frame().transpose())
RooneyBieglerExperimentVars(self.data.loc[i, :])
)

def rooney_biegler_indexed_vars(data):
Expand Down Expand Up @@ -501,15 +504,16 @@ def response_rule(m, h):
class RooneyBieglerExperimentIndexedVars(RooneyBieglerExperiment):

def create_model(self):
self.model = rooney_biegler_indexed_vars(self.data)
data_df = self.data.to_frame().transpose()
self.model = rooney_biegler_indexed_vars(data_df)

def label_model(self):

m = self.model

m.experiment_outputs = pyo.Suffix(direction=pyo.Suffix.LOCAL)
m.experiment_outputs.update([(m.hour, self.data.iloc[0]['hour'])])
m.experiment_outputs.update([(m.y, self.data.iloc[0]['y'])])
m.experiment_outputs.update([(m.hour, self.data['hour'])])
m.experiment_outputs.update([(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 All @@ -518,7 +522,7 @@ def label_model(self):
for i in range(self.data.shape[0]):
rooney_biegler_indexed_vars_exp_list.append(
RooneyBieglerExperimentIndexedVars(
self.data.loc[i, :].to_frame().transpose()
self.data.loc[i, :]
)
)

Expand Down Expand Up @@ -985,7 +989,7 @@ def SSE(model):
exp_list = []
for i in range(data.shape[0]):
exp_list.append(
RooneyBieglerExperiment(data.loc[i, :].to_frame().transpose())
RooneyBieglerExperiment(data.loc[i, :])
)

solver_options = {"tol": 1e-8}
Expand Down

0 comments on commit 2bcb0e0

Please sign in to comment.