Skip to content

Extended Parmest Capability for weighted SSE objective #3535

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

Open
wants to merge 83 commits into
base: main
Choose a base branch
from

Conversation

slilonfe5
Copy link
Contributor

@slilonfe5 slilonfe5 commented Mar 24, 2025

Fixes # .

Summary/Motivation:

Currently, the Parmest SSE objective does not support measurements in different units. This work adds new capabilities to Parmest, including weighted SSE to handle measurements in different units, and more robust covariance matrix calculation methods for more accurate uncertainty quantification. This work also enables the calculation of the covariance matrix using a user-supplied measurement error standard deviation.

Changes proposed in this PR:

  • Added a weighted SSE objective
  • Added two covariance matrix calculation methods for both the SSE and weighted SSE objectives
  • Enabled calculation of the covariance matrix using a user-supplied measurement error standard deviation
  • Added a separate function for the covariance matrix estimation

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
Copy link
Contributor Author

@adowling2 @djlaky

@adowling2
Copy link
Member

@slilonfe5 Here is some quick feedback

compute_jacobian function

  • Make this a private method by adding _ to the function name
  • Add as an argument to the function relative_perturbation
  • In the document string, explain this is using forward (?) finite difference
  • Add as an argument the solver object. You can make the default Ipopt.

Feedback on the compute_FIM method:

  • Add relative_tolerance and solver as arguments
  • Also add a check that error_list must be the same length as y_hat_list
  • Add a debugging step for the linear algebra error, compute the condition number of the Jacobian matrix and print it out
  • Why would you ever get a linear algebra error for just matrix multiplication? Is this check even needed?

@slilonfe5
Copy link
Contributor Author

slilonfe5 commented Apr 19, 2025

@adowling2 @djlaky I also updated the calculation for the normal SSE such that we can use the user-supplied measurement error if defined; otherwise, we calculate the measurement error as usual.

Copy link
Member

@adowling2 adowling2 left a comment

Choose a reason for hiding this comment

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

Nice progress. I think it is time to start writing tests for the new capabilities.

@adowling2
Copy link
Member

@slilonfe5 Once you have the tests ready, tag us for feedback. Also, I think you can skip adding this to the depreciated class.

Copy link
Member

@adowling2 adowling2 left a comment

Choose a reason for hiding this comment

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

Here is more feedback as you work on getting this ready for the Pyomo team to review.

@slilonfe5
Copy link
Contributor Author

@adowling2 @djlaky I have created a separate method (cov_est) for computing the covariance matrix, supporting three calculation methods (jacobian, kaug, and reduced_hessian). I implemented these covariance calculation methods for both the SSE and SSE_weighted objectives. Lastly, as you suggested, I did not add the new capability to the deprecated interface.

I tested these with three examples (2 steady state and 1 dynamic), and all work well. I'm yet to write the test file for these.

@slilonfe5
Copy link
Contributor Author

@blnicho @mrmundt @jsiirola @adowling2 @djlaky I have implemented Miranda's final review on this PR. I think this can be moved to Reviewer Approved in the August 2025 Release dashboard.

@slilonfe5
Copy link
Contributor Author

@mrmundt @blnicho Just a kind reminder that this PR is waiting for Reviewer Approval. Thanks

@slilonfe5
Copy link
Contributor Author

@blnicho Just a kind reminder that I'm waiting for your pending comments (the ones you mentioned during Tuesday's meeting). Thanks

Copy link
Member

@blnicho blnicho left a comment

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/suggestions. I'm still going through a couple of the files but I have some more substantial questions that I'll message you separately about.

Copy link
Member

@blnicho blnicho left a comment

Choose a reason for hiding this comment

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

@slilonfe5 here are a few more review comments. I'm still going through parmest.py

Comment on lines +206 to +224
else:
self.assertAlmostEqual(
cov.iloc[asymptote_index, asymptote_index], 36.935351, places=2
) # 6.22864 from paper
self.assertAlmostEqual(
cov.iloc[asymptote_index, rate_constant_index],
-2.551392,
places=2,
) # -0.4322 from paper
self.assertAlmostEqual(
cov.iloc[rate_constant_index, asymptote_index],
-2.551392,
places=2,
) # -0.4322 from paper
self.assertAlmostEqual(
cov.iloc[rate_constant_index, rate_constant_index],
0.243428,
places=2,
) # 0.04124 from paper
Copy link
Member

Choose a reason for hiding this comment

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

I think you only end up in this else-statement when cov_method="reduced_hessian". Why don't these covariance values match the expected values from the paper or the values calculated using the other methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are using the true sse to compute the covariance matrix. Previously, we calculated the covariance by assuming that the obj_val is the sse, which is not true.

Copy link
Member

Choose a reason for hiding this comment

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

So the three calculation methods aren't approximating the same sse and covariance?

@blnicho blnicho moved this to Todo in Pyomo 6.9.4 Release Aug 12, 2025
@blnicho blnicho moved this from Todo to Review In Progress in Pyomo 6.9.4 Release Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Ready for final review
Status: Review In Progress
Development

Successfully merging this pull request may close these issues.

6 participants