-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding regularization feature in parmest as an option to the default SSE objective #3550
Draft
sscini
wants to merge
10
commits into
Pyomo:main
Choose a base branch
from
sscini:parmest_obj_regularization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+47
−1
Draft
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b3486ca
Add regularize term function, and modified SSE to add option
sscini 76ffb22
Fixed term in function
sscini 50d6417
Merge branch 'main' into parmest_obj_regularization
sscini 055f14c
Update parmest.py
sscini 626c1b9
Revert "Update parmest.py"
sscini e853cc2
Reapply "Update parmest.py"
sscini 77c2832
Add theta_ref and prior_FIM to keyword args
sscini cfe6460
Merge branch 'Pyomo:main' into parmest_obj_regularization
sscini 7d0c956
Adjust naming convention to ensure consistency.
sscini fae8500
Update parmest.py, DoE meeting work
sscini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,6 +234,21 @@ def SSE(model): | |
expr = sum((y - y_hat) ** 2 for y, y_hat in model.experiment_outputs.items()) | ||
return expr | ||
|
||
def regularize_term(model, prior_FIM, theta_ref): | ||
""" | ||
Regularization term for the objective function, which is used to penalize deviation from a | ||
reference theta | ||
(theta - theta_ref).transpose() * prior_FIM * (theta - theta_ref) | ||
|
||
theta_ref: Reference parameter value, element of matrix | ||
prior_FIM: Fisher Information Matrix from prior experimental design, matrix | ||
theta: Parameter value, matrix | ||
|
||
Added to SSE objective function | ||
""" | ||
expr = ((theta - theta_ref).transpose() * prior_FIM * (theta - theta_ref) for theta in model.unknown_parameters.items()) | ||
return expr | ||
|
||
|
||
class Estimator(object): | ||
""" | ||
|
@@ -270,6 +285,8 @@ def __init__( | |
self, | ||
experiment_list, | ||
obj_function=None, | ||
prior_FIM=None, | ||
theta_ref=None, | ||
tee=False, | ||
diagnostic_mode=False, | ||
solver_options=None, | ||
|
@@ -296,6 +313,8 @@ def __init__( | |
|
||
# populate keyword argument options | ||
self.obj_function = obj_function | ||
self.prior_FIM = prior_FIM | ||
self.theta_ref = theta_ref | ||
self.tee = tee | ||
self.diagnostic_mode = diagnostic_mode | ||
self.solver_options = solver_options | ||
|
@@ -427,7 +446,18 @@ def _create_parmest_model(self, experiment_number): | |
# TODO, this needs to be turned into an enum class of options that still support | ||
# custom functions | ||
if self.obj_function == 'SSE': | ||
second_stage_rule = SSE | ||
|
||
if self.prior_FIM and self.theta_ref is not None: | ||
# Regularize the objective function | ||
second_stage_rule = SSE + regularize_term(prior_FIM = self.prior_FIM, theta_ref = self.theta_ref) | ||
elif self.prior_FIM: | ||
theta_ref = model.unknown_parameters.values() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this line needed? |
||
second_stage_rule = SSE + regularize_term(prior_FIM = self.prior_FIM, theta_ref = self.theta_ref) | ||
|
||
else: | ||
# Sum of squared errors | ||
second_stage_rule = SSE | ||
|
||
else: | ||
# A custom function uses model.experiment_outputs as data | ||
second_stage_rule = self.obj_function | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this run? My intuition is that you need to write out the matrix multiplication and cannot use matrix multiplication.