fit.fisher¶
Fisher information of a parameter fit.
The profile likelihood of sbmlsim.fit.identifiability scans a parameter and
re-optimizes the others, which is exact and costs a simulation per point. The
Fisher information is the local alternative: the curvature of the cost at the
optimum, from which the standard errors, the correlations of the parameters and
the directions the data does not constrain follow, at the cost of one jacobian.
For a fit which minimizes cost = 0.5 * Σ r² with the weighted residuals r,
the Gauss-Newton approximation of the Hessian is J' J with the jacobian
J = ∂r/∂θ, which is the Fisher information matrix of the estimate. Its
inverse, scaled by the variance of the residuals, is the covariance of the
parameters:
FIM = J' J, cov = σ² (J' J)⁻¹, σ² = 2 cost / (n - k)
A fit of the likelihood (ObjectiveType.LIKELIHOOD or POSTERIOR) has the
scale of the noise in its residuals, so its covariance is (J' J)⁻¹ without
σ², and its intervals are the ones of the normal distribution. The
information is the one of the data: the residuals of the priors of a fit of
the posterior are no part of it, the Laplace approximation of the posterior,
sbmlsim.fit.posterior, adds the curvature of the priors.
The jacobian is the forward sensitivities of sbmlsim-core where the problem
is one the engine fits (sbmlsim.fit.fit_core, #556) and its conditions carry
them, and the central differences of the residuals in python otherwise, see
_jacobian_of; FisherInformation.jacobian_of says which of the two a matrix
came from.
The two analyses answer different questions and disagree where the cost is not a quadratic: the Fisher information is a local statement about the optimum, the profile likelihood follows the cost until it rises by the threshold. A parameter which the Fisher information calls determined and the profile likelihood calls non-identifiable is a parameter whose cost is flat away from the optimum, which is what the profile is for.
FisherStatistics
¶
Bases: TypedDict
The statistics of a Fisher information, see FisherInformation.statistics.
Attributes:
| Name | Type | Description |
|---|---|---|
sigma2 |
float
|
the variance of the residuals, |
spectrum |
ndarray
|
the eigenvalues, largest first. |
rank |
int
|
the number of eigenvalues above the rank tolerance times the largest one. |
condition |
float
|
the ratio of the largest to the smallest eigenvalue, |
covariance |
ndarray
|
|
standard_errors |
ndarray
|
the standard error of every parameter, |
correlation |
ndarray
|
the correlation of the parameters. |
FisherInformation
dataclass
¶
FisherInformation(
opid,
sid,
pids,
values,
scale,
matrix,
cost,
n,
alpha=0.95,
rank_tolerance=DEFAULT_RANK_TOLERANCE,
step=DEFAULT_STEP,
jacobian_of=CENTRAL_DIFFERENCES,
units=list(),
scales=list(),
targets=list(),
objective=LEAST_SQUARES,
inverse=None,
spectrum=None,
)
The Fisher information of a parameter set on a problem.
Its statistics, see statistics, follow from the decomposition of the
matrix, its eigenvalues and its pseudo-inverse, which a record stores and
sbmlsim-core computes for a matrix without one (decomposition).
Attributes:
| Name | Type | Description |
|---|---|---|
opid |
str
|
id of the optimization problem. |
sid |
str
|
id of the parameter set. |
pids |
list[str]
|
parameters, in the order of the matrix. |
values |
ndarray
|
values of the parameters, in the units of the model. |
scale |
ParameterScaleType
|
space the matrix is expressed in, i.e. the space the optimizer
searches, see |
scales |
list[ParameterScaleType]
|
the space of every parameter, in the order of the matrix.
Without them every parameter has the scale |
matrix |
ndarray
|
the Fisher information |
cost |
float
|
cost of the data at the parameter set, the weighted least squares or the negative log-likelihood, without the priors. |
n |
int
|
number of data points of the fit. |
alpha |
float
|
confidence level of the intervals. |
rank_tolerance |
float
|
eigenvalues below this fraction of the largest one are a direction the data does not constrain. |
step |
float
|
relative step of the finite differences of the jacobian the
matrix was computed with, see |
jacobian_of |
str
|
where the jacobian of the matrix comes from,
|
units |
list[str | None]
|
the unit of every parameter in the order of the matrix, a unit
of pint with the unit ids of the model resolved, |
targets |
list[str]
|
the target of the model every parameter is written to, in the
order of the matrix ( |
objective |
ObjectiveType
|
what the fit minimized; a fit of the likelihood has the
noise in its residuals, see |
inverse |
ndarray | None
|
the pseudo-inverse of |
spectrum |
ndarray | None
|
the eigenvalues of |
parameter_scales
property
¶
Get the space of every parameter, in the order of the matrix.
scaled
property
¶
Check whether the covariance is scaled by the variance of the residuals.
The residuals of a fit of least squares are weighted by weights whose scale is arbitrary, so the variance of the residuals is estimated from them; the residuals of a likelihood are in units of the noise.
sigma2
property
¶
Get the variance of the residuals, 2 cost / (n - k).
A fit with as many parameters as data points has no degrees of freedom
left and no variance to estimate, which is nan. A fit of the
likelihood has residuals in units of the noise, the variance 1, see
scaled. It follows from the cost and the counts alone, without the
decomposition of the matrix, so the posterior reads it of a matrix
which does not decompose (sbmlsim.fit.posterior); it is the
sigma2 of statistics, to the bit.
eigenvalues
property
¶
Get the eigenvalues of the Fisher information, largest first.
The matrix is symmetric and positive semi-definite, so the eigenvalues are real and not negative up to rounding. A small eigenvalue is a direction in parameter space the data does not constrain.
condition_number
property
¶
Get the ratio of the largest to the smallest eigenvalue.
A large condition number is a problem which is sloppy: the data
determines some combinations of the parameters much better than
others. It is inf of a smallest eigenvalue which is not positive.
rank
property
¶
Get the number of directions the data constrains.
The number of eigenvalues above the rank tolerance times the largest one, 0 of a largest one which is not positive.
is_identifiable
property
¶
Check whether the data constrains every direction locally.
covariance
property
¶
Get the covariance of the parameters in the scaled space.
cov = σ² (J' J)⁻¹, with the pseudo-inverse for a matrix which is rank
deficient, i.e. for a problem which is locally not identifiable. The
covariance of such a problem is not a covariance, its entries of the
unconstrained directions are arbitrary; is_identifiable says whether
it can be read. The warning about it is logged once per information and
rank tolerance.
standard_errors
property
¶
Get the standard error of every parameter in the scaled space.
nan of a variance which is not positive; a perfect identifiable fit
has the variance zero, a zero on the diagonal of a deficient
pseudo-inverse may be unconstrained.
correlation
property
¶
Get the correlation of the parameters.
Two parameters which are correlated to ±1 are the pair the data only
determines together, i.e. the fit can trade one against the other.
statistics
property
¶
Get the statistics of the information.
They follow from its decomposition, the stored one of a record or the
one of sbmlsim-core, see decomposition, by one call of
fisher_statistics_of_decomposition of sbmlsim-core, so a record
gives the numbers it was written with.
has_mixed_scales
property
¶
Check whether the parameters are searched in more than one space.
relative_errors
property
¶
Get the standard error of every parameter relative to its value.
The coefficient of variation of the parameter in the units of the
model, to first order: se / |value| for a parameter searched on the
linear scale, the standard error of ln(p) for one searched as a
natural logarithm and ln(10) times the standard error of log10(p)
for a decadic logarithm. It does not depend on the unit of the
parameter (the error of a logarithm divided by the logarithm of the
value did, and was near infinite for a value near 1).
summary_df
property
¶
Get the parameters with their errors and intervals as a table.
The table has the column scale with the space of every parameter
when the parameters are searched in different spaces, see
has_mixed_scales.
confidence_intervals
¶
Get the confidence interval of every parameter.
The interval is θ ± t · SE in the space the optimizer searches, with
the quantile of the t distribution of n - k degrees of freedom (of
the normal distribution for a fit of the likelihood, see scaled),
and is transformed back into the units of the model, every parameter with
its own scale. On a logarithmic scale the interval is therefore not
symmetric around the value.
Returns:
| Type | Description |
|---|---|
ndarray
|
The lower and the upper bound in the units of the model, |
ndarray
|
for a fit of least squares without degrees of freedom; the |
tuple[ndarray, ndarray]
|
interval of a direction the data does not constrain is unbounded |
tuple[ndarray, ndarray]
|
on a logarithmic scale. |
from_dict
classmethod
¶
Create from a dictionary, the inverse of to_dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Mapping[str, Any]
|
dictionary of |
required |
Returns:
| Type | Description |
|---|---|
FisherInformation
|
The Fisher information with the arrays restored. |
default_step
¶
Get the relative step of the central differences of the jacobian.
A simulation is exact only to the relative tolerance of its integrator, so the residuals have a noise of about that size. The error of a central difference is the noise divided by the step plus the truncation error, which grows with the square of the step; the cube root of the noise balances them. A step at the machine epsilon divides the noise of the integrator by a tiny step and the jacobian is noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
relative_tolerance
|
float
|
relative tolerance of the integrator of the fit. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The step, relative to the parameters in the space the optimizer |
float
|
searches, |
decomposition
¶
Get the eigenvalues and the pseudo-inverse of a Fisher information.
One eigendecomposition of sbmlsim_core.stats (the cyclic Jacobi method,
fisher_decomposition) gives the eigenvalues and the pseudo-inverse of
numpy (the eigenvalues cut at 1e-15 of the largest one), with the same
bits on every machine. They are the decomposition a record stores, and
every statistic of FisherInformation follows from them, the ones of a
record which stores them as well, see FisherInformation.statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
ndarray
|
the Fisher information |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
The eigenvalues, largest first, and the pseudo-inverse. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a matrix which is not a square, finite and symmetric matrix of at least one parameter. |
evaluator
¶
Get what evaluates the residuals of the points of a jacobian.
The points of the central differences are independent of each other.
sbmlsim-core evaluates them as one batch on threads of its own in this
process (OptimizationProblem.evaluate_residuals_many); any other engine
on a pool of workers, the pool of a fit with the problem initialized in
every worker (sbmlsim.fit.runner.JacobianPool, what the jacobian of
least squares uses). The values are the values of this process bitwise,
see JacobianPool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
OptimizationProblem
|
initialized optimization problem. |
required |
settings
|
FitSettings
|
the settings the problem was initialized with, which the workers initialize it with. |
required |
n_cores
|
int
|
the number of workers, one for the evaluation in this process. |
1
|
Yields:
| Type | Description |
|---|---|
Generator[Evaluate | None]
|
What evaluates the points, |
jacobian
¶
Get the jacobian of the weighted residuals by central differences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
OptimizationProblem
|
initialized optimization problem. |
required |
x
|
ndarray
|
parameters in the space the optimizer searches. |
required |
step
|
float
|
relative step of the differences. |
DEFAULT_STEP
|
evaluate
|
Evaluate | None
|
what evaluates the points of the differences, see
|
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The jacobian with one row per residual and one column per parameter. |
fisher_information
¶
fisher_information(
problem,
settings,
parameter_set,
alpha=0.95,
step=None,
rank_tolerance=DEFAULT_RANK_TOLERANCE,
n_cores=1,
engine_jacobian=None,
)
Calculate the Fisher information of a parameter set on a problem.
The jacobian is the forward sensitivities of sbmlsim-core where the
problem and its conditions carry them, and the central differences of the
residuals in python otherwise, see _jacobian_of.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
OptimizationProblem
|
optimization problem, initialized with the settings. |
required |
settings
|
FitSettings
|
settings the parameters were fitted with. |
required |
parameter_set
|
ParameterSet
|
parameters to evaluate the information at, i.e. the result of a fit. |
required |
alpha
|
float
|
confidence level of the intervals. |
0.95
|
step
|
float | None
|
relative step of the finite differences of the jacobian,
|
None
|
rank_tolerance
|
float
|
eigenvalues below this fraction of the largest one are a direction the data does not constrain. |
DEFAULT_RANK_TOLERANCE
|
n_cores
|
int
|
the workers which evaluate the points of the jacobian, the
two points of every parameter, see |
1
|
engine_jacobian
|
bool | None
|
whether the jacobian is the forward sensitivities of
the engine: |
None
|
Returns:
| Type | Description |
|---|---|
FisherInformation
|
The Fisher information with the errors, the correlations and the |
FisherInformation
|
directions the data does not constrain. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
data_residuals
¶
Get the residuals of the data at parameters, without the ones of the priors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
OptimizationProblem
|
initialized optimization problem. |
required |
x
|
ndarray
|
parameters in the space the optimizer searches. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ndarray
|
The residuals of the data, the first ones of |
|
float
|
cost of the data (half their sum of squares minus the offset of a |
|
int
|
likelihood, i.e. the negative log-likelihood) and the number of data |
|
points |
tuple[ndarray, float, int]
|
a residual per point for least squares, two (of the data and |
tuple[ndarray, float, int]
|
of the scale of its noise) for a likelihood. |