Skip to content

Commit 590c5c9

Browse files
committed
Implemented Miranda's final review on parmest.py, test_parmest.py, and covariance.rst
1 parent bdd93a5 commit 590c5c9

File tree

3 files changed

+34
-38
lines changed

3 files changed

+34
-38
lines changed

doc/OnlineDocs/explanation/analysis/parmest/covariance.rst

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,60 @@ methods which have been implemented in parmest.
99

1010
1. Reduced Hessian Method
1111

12-
When the objective function is "SSE":
12+
When the objective function is the sum of squared errors (SSE) between the
13+
observed and predicted values of the measured variables, the covariance matrix is:
1314

1415
.. math::
1516
V_{\boldsymbol{\theta}} = 2 \sigma^2 \left(\frac{\partial^2 \text{SSE}}
1617
{\partial \boldsymbol{\theta} \partial \boldsymbol{\theta}}\right)^{-1}_{\boldsymbol{\theta}
1718
= \boldsymbol{\theta}^*}
1819
19-
When the objective function is "SSE_weighted":
20+
When the objective function is the weighted SSE (WSSE), the covariance matrix is:
2021

2122
.. math::
22-
V_{\boldsymbol{\theta}} = 2 \sigma^2 \left(\frac{\partial^2 \text{WSSE}}
23+
V_{\boldsymbol{\theta}} = \left(\frac{\partial^2 \text{WSSE}}
2324
{\partial \boldsymbol{\theta} \partial \boldsymbol{\theta}}\right)^{-1}_{\boldsymbol{\theta}
2425
= \boldsymbol{\theta}^*}
2526
26-
Where SSE is the sum of squared errors between the observed (data) and predicted
27-
values of the measured variables, WSSE is the weighted SSE,
28-
:math:`\boldsymbol{\theta}` are the unknown parameters, :math:`\boldsymbol{\theta^*}`
29-
are the estimate of the unknown parameters, and :math:`\sigma^2` is the variance of
30-
the measurement error. When the standard deviation of the measurement error is not
31-
supplied by the user, parmest approximates the variance of the measurement error as
27+
Where :math:`V_{\boldsymbol{\theta}}` is the covariance matrix of the estimated
28+
parameters, :math:`\boldsymbol{\theta}` are the unknown parameters,
29+
:math:`\boldsymbol{\theta^*}` are the estimate of the unknown parameters, and
30+
:math:`\sigma^2` is the variance of the measurement error. When the standard
31+
deviation of the measurement error is not supplied by the user, parmest
32+
approximates the variance of the measurement error as
3233
:math:`\sigma^2 = \frac{1}{n-l} \sum e_i^2` where :math:`n` is the number of data
33-
points, :math:`l` is the number of fitted parameters, and :math:`e_i` is the residual
34-
for experiment :math:`i`.
34+
points, :math:`l` is the number of fitted parameters, and :math:`e_i` is the
35+
residual for experiment :math:`i`.
3536

3637
2. Finite Difference Method
3738

39+
In this method, the covariance matrix, :math:`V_{\boldsymbol{\theta}}`, is
40+
calculated by applying the Gauss-Newton approximation to the Hessian,
41+
:math:`\frac{\partial^2 \text{SSE}}{\partial \boldsymbol{\theta} \partial \boldsymbol{\theta}}`
42+
or
43+
:math:`\frac{\partial^2 \text{WSSE}}{\partial \boldsymbol{\theta} \partial \boldsymbol{\theta}}`,
44+
leading to:
45+
3846
.. math::
39-
V_{\boldsymbol{\theta}} = \left( \sum_{r = 1}^n \mathbf{G}_{r}^{\mathrm{T}} \mathbf{W}
40-
\mathbf{G}_{r} \right)^{-1}
47+
V_{\boldsymbol{\theta}} = \left(\sum_{i = 1}^n \mathbf{G}_{i}^{\mathrm{T}} \mathbf{W}
48+
\mathbf{G}_{i} \right)^{-1}
4149
4250
This method uses central finite difference to compute the Jacobian matrix,
43-
:math:`\mathbf{G}_{r}`, which is the sensitivity of the measured variables with
44-
respect to the parameters, :math:`\boldsymbol{\theta}`. :math:`\mathbf{W}` is a diagonal
45-
matrix containing the inverse of the variance of the measurement errors,
46-
:math:`\sigma^2`.
51+
:math:`\mathbf{G}_{i}`, for experiment :math:`i`, which is the sensitivity of
52+
the measured variables with respect to the parameters, :math:`\boldsymbol{\theta}`.
53+
:math:`\mathbf{W}` is a diagonal matrix containing the inverse of the variance
54+
of the measurement errors, :math:`\sigma^2`.
4755

4856
3. Automatic Differentiation Method
4957

58+
Similar to the finite difference method, the covariance matrix is calculated as:
59+
5060
.. math::
51-
V_{\boldsymbol{\theta}} = \left( \sum_{r = 1}^n \mathbf{G}_{\text{kaug},\, r}^{\mathrm{T}}
52-
\mathbf{W} \mathbf{G}_{\text{kaug},\, r} \right)^{-1}
61+
V_{\boldsymbol{\theta}} = \left( \sum_{i = 1}^n \mathbf{G}_{\text{kaug},\, i}^{\mathrm{T}}
62+
\mathbf{W} \mathbf{G}_{\text{kaug},\, i} \right)^{-1}
5363
54-
This method uses the model optimality (KKT) condition to compute the Jacobian matrix,
55-
:math:`\mathbf{G}_{\text{kaug},\, r}`.
64+
However, this method uses the model optimality (KKT) condition to compute the
65+
Jacobian matrix, :math:`\mathbf{G}_{\text{kaug},\, i}`, for experiment :math:`i`.
5666

5767
In parmest, the covariance matrix can be calculated after defining the
5868
:class:`~pyomo.contrib.parmest.parmest.Estimator` object and estimating the unknown

pyomo/contrib/parmest/parmest.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import re
4242
import importlib as im
4343
import logging
44-
import warnings
4544
import types
4645
import json
4746
from collections.abc import Callable
@@ -1056,13 +1055,6 @@ def _Q_opt(
10561055
solver.options[key] = self.solver_options[key]
10571056

10581057
solve_result = solver.solve(self.ef_instance, tee=self.tee)
1059-
1060-
# The import error will be raised when we attempt to use
1061-
# inv_reduced_hessian_barrier below.
1062-
#
1063-
# elif not asl_available:
1064-
# raise ImportError("parmest requires ASL to calculate the "
1065-
# "covariance matrix with solver 'ipopt'")
10661058
elif kwargs and all(arg.value in kwargs for arg in UnsupportedArgsLib):
10671059
deprecation_warning(
10681060
"You're using a deprecated call to the `theta_est()` function "
@@ -1086,13 +1078,6 @@ def _Q_opt(
10861078
solver.options[key] = self.solver_options[key]
10871079

10881080
solve_result = solver.solve(self.ef_instance, tee=self.tee)
1089-
1090-
# The import error will be raised when we attempt to use
1091-
# inv_reduced_hessian_barrier below.
1092-
#
1093-
# elif not asl_available:
1094-
# raise ImportError("parmest requires ASL to calculate the "
1095-
# "covariance matrix with solver 'ipopt'")
10961081
else:
10971082
# parmest makes the fitted parameters stage 1 variables
10981083
ind_vars = []

pyomo/contrib/parmest/tests/test_parmest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737

3838

3939
# Test class for the built-in "SSE" and "SSE_weighted" objective functions
40-
# validated the results using the Rooney-Biegler paper example
41-
# Rooney-Biegler paper example is the case when the measurement error is None
40+
# validated the results using the Rooney-Biegler paper example linked below
41+
# https://doi.org/10.1002/aic.690470811
42+
# The Rooney-Biegler paper example is the case when the measurement error is None
4243
# we considered another case when the user supplies the value of the measurement error
4344
@unittest.skipIf(
4445
not parmest.parmest_available,

0 commit comments

Comments
 (0)