Skip to content

Enable More Complex Error Structures in ParmEst and Pyomo.DoE - #3996

Open
slilonfe5 wants to merge 48 commits into
Pyomo:mainfrom
slilonfe5:parmest-measurement-error
Open

slilonfe5 wants to merge 48 commits into
Pyomo:mainfrom
slilonfe5:parmest-measurement-error

Conversation

@slilonfe5

@slilonfe5 slilonfe5 commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

Fixes # .

Summary/Motivation:

  1. Currently, ParmEst and Pyomo.DoE support only independent and identically distributed (i.i.d.) measurement errors. This PR adds support for correlated measurement errors by enabling the construction of a full measurement-error covariance matrix (MCM), allowing correlations across time and between measurements collected at the same time point. The new implementation also supports proportional (heteroskedastic) error structures.
  2. Currently, the calculation of the parameter covariance/Fisher information matrix in ParmEst/Pyomo.DoE is not supported for indexed parameters. This PR develops the capability to compute these matrices for indexed parameters.

Changes proposed in this PR:

  • Update _compute_jacobian, _kaug_FIM, and _cov_at_theta in ParmEst to support covariance matrix estimation for indexed parameters
  • Add a helper function in both ParmEst and Pyomo.DoE that builds the MCM from the user-supplied standard deviation and covariances
  • Update SSE_weighted in ParmEst to use the MCM in computing the "SSE_weighted" objective function
  • Update _kaug_FIM and _finite_difference_FIM in ParmEst to use the MCM in computing the parameter covariance matrix
  • Update _kaug_FIM and _sequential_FIM in Pyomo.DoE to use the MCM
  • Update create_doe_model in Pyomo.DoE to use the MCM
  • Replicate ParmEst's _expanded_unknown_parameter_info in Pyomo.DoE
  • Update all appearances of model.unknown_parameters or model.scenario_blocks.unknown_parameters to use the expanded parameter objects
  • Add tests in test_parmest.py and test_doe_solve.py to exercise the new capabilities

AI-Use Disclosure

  • AI tools were NOT used during the preparation of this PR

or

  • AI tools contributed to the development of this PR

    • AI tools generated documentation (including the PR description/comments, code comments, and/or Sphinx documentation)
    • AI tools generated tests (baselines, examples, and/or code)
    • AI tools generated code (apart from tests)

    Review process (select ONE):

    • Rewritten: All AI-generated content was rewritten by me before being committed.
    • Reviewed/verified: I retained AI-generated content and verified it before committing. Verification included (as applicable):
      • Ran the code and fixed issues
      • Added and ran tests
      • Checked correctness/logic of code and tests
      • Checked for alignment with the contribution guide
      • Considered security implications
    • As-is: AI-generated content was commited directly to the repository

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:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@slilonfe5
slilonfe5 marked this pull request as ready for review July 20, 2026 23:52
@slilonfe5

Copy link
Copy Markdown
Member Author

@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

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.49123% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.17%. Comparing base (0c6bc22) to head (67ce280).
⚠️ Report is 124 commits behind head on main.

Files with missing lines Patch % Lines
pyomo/contrib/parmest/utils/model_utils.py 91.42% 3 Missing ⚠️
pyomo/contrib/doe/doe.py 98.03% 1 Missing ⚠️
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           
Flag Coverage Δ
builders 29.13% <53.50%> (+0.01%) ⬆️
default 86.39% <96.49%> (?)
expensive 35.18% <53.50%> (?)
linux 87.68% <96.49%> (-1.99%) ⬇️
linux_other 87.68% <96.49%> (+<0.01%) ⬆️
oldsolvers 28.02% <5.26%> (-0.01%) ⬇️
osx 83.16% <96.49%> (+<0.01%) ⬆️
win 85.48% <96.49%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@blnicho

blnicho commented Nov 17, 2026

Copy link
Copy Markdown
Member

@slilonfe5 could you resolve the conflict in test_parmest when you have a minute?

@slilonfe5

Copy link
Copy Markdown
Member Author

@blnicho, I have resolved the conflict. Thank you

@blnicho blnicho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Comment thread pyomo/contrib/doe/doe.py Resolved
Comment thread pyomo/contrib/doe/doe.py Resolved
@slilonfe5

Copy link
Copy Markdown
Member Author

@blnicho, thank you for your comments; I have addressed them. The test failures are unrelated to this PR; they come from the GAMS solver.

@mrmundt

mrmundt commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@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 main - we fixed the GAMS problem there.

@slilonfe5

Copy link
Copy Markdown
Member Author

@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 main - we fixed the GAMS problem there.

Thank you @mrmundt

@slilonfe5

Copy link
Copy Markdown
Member Author

@mrmundt, more solver-related failures.

@sscini sscini left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heteroscedastic

model.measurement_error[y_hat] is not None for y_hat in model.experiment_outputs
)
try:
all_known_errors = all(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for y_hat ref_model.experiment_outputs.keys(). No need to call the unused values here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Ready for design review

Development

Successfully merging this pull request may close these issues.

6 participants