Skip to content

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, 2 cost / (n - k), nan without degrees of freedom, 1 for a likelihood.

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, inf of a smallest one which is not positive.

covariance ndarray

sigma2 times the pseudo-inverse of the information.

standard_errors ndarray

the standard error of every parameter, nan of a variance which is not positive (zero allowed of an identifiable information).

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 ParameterScaleType. It is the scale of the settings of the fit, i.e. of the parameters without a scale of their own.

scales list[ParameterScaleType]

the space of every parameter, in the order of the matrix. Without them every parameter has the scale scale.

matrix ndarray

the Fisher information J' J of the residuals of the data.

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; 0 for a jacobian which took no difference, i.e. the sensitivities of the engine.

jacobian_of str

where the jacobian of the matrix comes from, CENTRAL_DIFFERENCES or SENSITIVITIES.

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, None for the unit of the model; empty for an information which does not know them.

targets list[str]

the target of the model every parameter is written to, in the order of the matrix (FitParameter.target_id); empty for an information which does not know them, then the pids are the targets.

objective ObjectiveType

what the fit minimized; a fit of the likelihood has the noise in its residuals, see scaled.

inverse ndarray | None

the pseudo-inverse of matrix, None to compute it. It is stored with the information and read back, so a record gives the standard errors it was written with: a record of a release before sbmlsim-core computed them took the SVD of LAPACK, which depends on the kernels of the CPU, so the same matrix gave standard errors which differ in their last digits on another machine and a model whose factory writes them into its SBML did not rebuild byte for byte (#523). sbmlsim-core computes them with the same bits on every machine, see decomposition. A record written before they were stored has none and computes them, and a matrix which is changed after the information was created drops them.

spectrum ndarray | None

the eigenvalues of matrix, largest first, None to compute them; stored with the information for the same reason, so the rank of a record is the rank on every machine.

k property

k

Get the number of parameters.

parameter_scales property

parameter_scales

Get the space of every parameter, in the order of the matrix.

scaled property

scaled

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

sigma2

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

eigenvalues

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

condition_number

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

rank

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

is_identifiable

Check whether the data constrains every direction locally.

covariance property

covariance

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

standard_errors

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

correlation

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

statistics

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

has_mixed_scales

Check whether the parameters are searched in more than one space.

relative_errors property

relative_errors

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

summary_df

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.

to_scale

to_scale(values)

Transform one value per parameter into the space of the optimizer.

from_scale

from_scale(values)

Transform one value per parameter into the units of the model.

confidence_intervals

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

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

from_dict(d)

Create from a dictionary, the inverse of to_dict.

Parameters:

Name Type Description Default
d Mapping[str, Any]

dictionary of to_dict, e.g. read from the fisher.json of a fit record.

required

Returns:

Type Description
FisherInformation

The Fisher information with the arrays restored.

to_dict

to_dict()

Convert to a dictionary of JSON serializable values.

default_step

default_step(relative_tolerance)

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, 1e-2 for the default tolerance 1e-6.

decomposition

decomposition(matrix)

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 J' J, square, finite and symmetric.

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

evaluator(problem, settings, n_cores=1)

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, None for the evaluation in this process.

jacobian

jacobian(problem, x, step=DEFAULT_STEP, evaluate=None)

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 evaluator; the evaluation in this process by default.

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, default_step of the relative tolerance of the settings by default; a step which is given asks for the differences, so the jacobian of such a call comes from the engine only with engine_jacobian=True.

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 evaluator; one evaluates them in this process, which is 2 k simulations of the experiments one after another. It is the threads of the batch of a jacobian of the engine.

1
engine_jacobian bool | None

whether the jacobian is the forward sensitivities of the engine: None takes them where the engine has them, True requires them and names what keeps the problem from them, False takes the central differences in python.

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 engine_jacobian is required and the engine cannot compute the jacobian of the problem.

data_residuals

data_residuals(problem, x)

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 problem.residuals, the

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.