Skip to content

fit.priors

The joint prior of the parameters of a fit and the priors as distributions.

A parameter of a fit has the prior of FitParameter.prior, truncated at its bounds, or else the uniform prior over its bounds. The priors are independent unless the problem has a prior_correlation, a Covariance.correlation of parameters which have a normal or a log-normal prior: the priors of these parameters are one Gaussian copula with this correlation of their normal scores (Nelsen 2006), i.e. the multivariate normal of their values (normal) and of the logarithms of their values (log-normal), restricted to their bounds. It is the dependence of the uncertainty analyses as well, see sbmlsim.uncertainty.Covariance.

A fit of ObjectiveType.POSTERIOR minimizes the negative log posterior as a sum of squares, JointPrior.residuals:

  • an independent prior has the residual sqrt(c - 2 log p) with the offset c of _independent_term, so half its square minus c / 2 is the negative log density of the prior truncated at the bounds;
  • the correlated priors are whitened (Tarantola 2005): with the normal scores z = (v - mu) / sigma of their values v (the logarithm of a log-normal one) and the Cholesky factor L of their correlation R = L L', the residuals w = L⁻¹ z have the half sum of squares z' R⁻¹ z / 2, the quadratic form of the multivariate normal; a log-normal prior has the residual sqrt(c + 2 ln(x)) of the density of the logarithm in the value, 1 / x. The density of correlated priors is normalized as the multivariate normal without the bounds, so the cost is the negative log posterior up to a constant of the problem, which neither the estimate, its profiles nor its Laplace approximation depend on.

prior_distributions and prior_model give the priors of a problem as the distributions of the designs of sbmlsim.simulation.sampling and as the UncertaintyModel of a propagation: a prior truncated at the bounds of its parameter, the uniform distribution over the bounds for a parameter without one, and the correlation of the problem. The marginals of correlated priors are truncated each at its bounds, which equals the joint prior of the fit where the bounds leave the priors untouched.

Nelsen RB (2006). An Introduction to Copulas, 2nd ed. Springer. Tarantola A (2005). Inverse Problem Theory and Methods for Model Parameter Estimation. SIAM.

JointPrior

JointPrior(parameters, correlation=None)

The prior of the parameters of a problem, see the module.

Create the prior of the parameters.

Parameters:

Name Type Description Default
parameters Sequence[FitParameter]

the parameters of the problem.

required
correlation Covariance | None

the correlation of the normal scores of some of their priors, see the module.

None

Raises:

Type Description
ValueError

for a correlation the priors do not take, see _correlated_term.

residuals

residuals(x)

Get the residuals of the prior, see the module.

Parameters:

Name Type Description Default
x ndarray

values of the parameters on the linear scale.

required

Returns:

Type Description
ndarray

The residuals, NaN where the prior is not defined, e.g. outside

float

the bounds of a truncated prior, and the offset, so that half the

tuple[ndarray, float]

sum of squares minus the offset is the negative log density.

log_density

log_density(x)

Get the log density of the prior.

Parameters:

Name Type Description Default
x ndarray

values of the parameters on the linear scale.

required

Returns:

Type Description
float

The log density, -inf outside the bounds of a prior; the

float

correlated priors are normalized without their bounds, see the

float

module.

check_prior_correlation

check_prior_correlation(parameters, correlation)

Check that the priors of the parameters take a correlation.

Parameters:

Name Type Description Default
parameters Sequence[FitParameter]

the parameters of a problem.

required
correlation Covariance | None

the correlation of their priors, nothing to check without.

required

Raises:

Type Description
ValueError

see _correlated_term.

prior_distributions

prior_distributions(problem, targets=None)

Get the priors of the parameters of a problem as distributions of their targets.

Parameters:

Name Type Description Default
problem OptimizationProblem

the problem, initialized, so the units of its parameters are the units of pint of its models, see OptimizationProblem.parameter_units.

required
targets Mapping[str, str] | None

pid -> the target of the model, overrides FitParameter.target_id.

None

Returns:

Type Description
dict[str, Distribution]

target -> its prior truncated at the bounds of its parameter, or the

dict[str, Distribution]

uniform distribution over the bounds for a parameter without a prior,

dict[str, Distribution]

in the unit of the parameter.

Raises:

Type Description
ValueError

for a parameter without a prior whose bounds are not finite, a prior without a distribution of the sampler, or two parameters of one target (the versions of a parameter).

prior_model

prior_model(problem, targets=None, **kwargs)

Get the priors of the parameters of a problem as the uncertainty of a propagation.

Parameters:

Name Type Description Default
problem OptimizationProblem

the problem, initialized, see prior_distributions.

required
targets Mapping[str, str] | None

pid -> the target of the model, overrides FitParameter.target_id.

None
kwargs Any

the other fields of the UncertaintyModel, e.g. inputs; a covariance is added to the correlation of the priors.

{}

Returns:

Type Description
UncertaintyModel

The model with the priors of prior_distributions and the correlation

UncertaintyModel

of the priors of the problem, by the targets.