Repository navigation
Conversation
|
@blnicho @mrmundt @jsiirola @adowling2. This PR is ready for review. This PR enables parameter covariance and Fisher Information Matrix estimation for indexed parameters across ParmEst and Pyomo.DoE. Additionally, it adds support for complex measurement-error structures (such as correlated or proportional errors) by building a full measurement-error covariance matrix for parameter estimation and optimal experimental design. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3996 +/- ##
=======================================
Coverage 90.17% 90.17%
=======================================
Files 918 918
Lines 109411 109450 +39
=======================================
+ Hits 98659 98698 +39
Misses 10752 10752
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@slilonfe5 could you resolve the conflict in test_parmest when you have a minute? |
|
@blnicho, I have resolved the conflict. Thank you |
blnicho
left a comment
There was a problem hiding this comment.
@slilonfe5 here are some initial comments. I think this still needs some work so I'm going to take it off the release board for today.
…fe5/pyomo into parmest-measurement-error
|
@blnicho, thank you for your comments; I have addressed them. The test failures are unrelated to this PR; they come from the GAMS solver. |
I merged in |
|
@mrmundt, more solver-related failures. |
sscini
left a comment
There was a problem hiding this comment.
Really minor comments. Otherwise looks good.
| # when computing the covariance matrix from the hessian | ||
| # the 2 in the formula comes from using 1/2 in the SSE function | ||
| measurement_var = ( | ||
| 2 * self.obj_value / (n - l) |
There was a problem hiding this comment.
Thank you for catching this. I think this might need to be fixed in the documentation too. Otherwise I don't see any issues.
| # was applied to the objective function when computing | ||
| # the inverse of the reduced hessian. | ||
| # the first value of the measurement errors is used because the | ||
| # 'SSE' objective is applied to constant measurement-error systems |
There was a problem hiding this comment.
I think there should be a check before this for SSE that they all use the same error. Or we had also potentially discussed a warning and using the mean? If there are different known errors that would need to use a diagonal matrix in the SSE_weighted function according to earlier comments.
| @@ -462,7 +462,7 @@ def test_get_measurement_error_without_blocks(self): | |||
|
|
|||
| count = 0 | |||
| for k, v in doe_obj.compute_FIM_model.measurement_error.items(): | |||
There was a problem hiding this comment.
The doe changes look fine as long as they don't conflict with Shuvo's simultaneous PR. That would be a nice sanity check.
| ---------- | ||
| model : ConcreteModel | ||
| Annotated Pyomo model | ||
| estimated_var: float or int, optional |
There was a problem hiding this comment.
I think instead of naming it as estimated_var, it'd be clearer to use estimated_variance since var is used in Pyomo for specific things
|
|
||
| if hasattr(model, "measurement_error"): | ||
| all_known_errors = all( | ||
| model.measurement_error[y_hat] is not None |
There was a problem hiding this comment.
What happens if a measurement_error is 0? Will that cause problems downstream?
| if yi.name not in outputs_name or yj.name not in outputs_name: | ||
| raise ValueError( | ||
| "Measurement-error covariance must be defined only between " | ||
| "experiment output variables." |
There was a problem hiding this comment.
"Measurement-error covariance must be defined only between variables passed to experiment_outputs suffix." would be clearer message
| # update the measurement-error covariance matrix which | ||
| # is a symmetric matrix | ||
| Sigma_y[i, j] = err_cov | ||
| Sigma_y[j, i] = err_cov |
There was a problem hiding this comment.
I think you need to check whether the user passed a symmetric matrix and raise an error for a non-symmetric matrix instead of building one, or make sure the user only passes the upper or lower triangular covariance matrix.
| # is a symmetric matrix | ||
| Sigma_y[i, j] = err_cov | ||
| Sigma_y[j, i] = err_cov | ||
| elif not isinstance(key, tuple) and not hasattr(key, "name"): |
There was a problem hiding this comment.
Instead of elif you need an else. For example, if the key is a tuple and has name attribute, but the length is not 2, then what?
| Returns an expression that is used to compute the sum of squared errors | ||
| ('SSE') objective, assuming Gaussian i.i.d. errors | ||
| ('SSE') objective, assuming Gaussian i.i.d. errors (i.e., the measurements | ||
| are assumed to have equal variance, for example, when they are collected |
There was a problem hiding this comment.
If one piece of equipment can take multiple measurements (say T and P), then it kind of means that T and P will have the same variance (Var T = Var P), which is not required. I think you want to clarify that. Or just say iid and remove the explanation, as iid is well-known
| or covariance of the measurement errors defined in the annotated Pyomo model | ||
|
|
||
| This objective function is applicable to both homoscedastic | ||
| (constant-variance) and heteroskedastic (non-constant-variance, e.g., |
| model.measurement_error[y_hat] is not None for y_hat in model.experiment_outputs | ||
| ) | ||
| try: | ||
| all_known_errors = all( |
There was a problem hiding this comment.
You are checking this in model_utils._build_meas_error_covariance_matrix. Is this check necessary again?
| model = _get_labeled_model(experiment) | ||
|
|
||
| # get the parameter data objects | ||
| param_data_objects, _, _ = expanded_unknown_parameters(model) |
There was a problem hiding this comment.
You are calling this param_data_objects here, but in line 231, you are calling it theta_components. Be consistent.
| try: | ||
| meas_error = [ | ||
| ref_model.measurement_error[y_hat] | ||
| for y_hat, y in ref_model.experiment_outputs.items() |
There was a problem hiding this comment.
for y_hat ref_model.experiment_outputs.keys(). No need to call the unused values here.
Fixes # .
Summary/Motivation:
Changes proposed in this PR:
_compute_jacobian,_kaug_FIM, and_cov_at_thetain ParmEst to support covariance matrix estimation for indexed parametersSSE_weightedin ParmEst to use the MCM in computing the "SSE_weighted" objective function_kaug_FIMand_finite_difference_FIMin ParmEst to use the MCM in computing the parameter covariance matrix_kaug_FIMand_sequential_FIMin Pyomo.DoE to use the MCMcreate_doe_modelin Pyomo.DoE to use the MCM_expanded_unknown_parameter_infoin Pyomo.DoEmodel.unknown_parametersormodel.scenario_blocks.unknown_parametersto use the expanded parameter objectstest_parmest.pyandtest_doe_solve.pyto exercise the new capabilitiesAI-Use Disclosure
or
AI tools contributed to the development of this PR
Review process (select ONE):
Notes for reviewers (optional):
Legal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: