kipe.sensitivity module

Sensitivity analysis: kipe sensitivity.

The Fisher information \(\bs{M}\) of a study’s measurements says how much they tell about the estimated parameters, and which combinations of the parameters they barely determine. It is evaluated at the nominal parameters, i.e., the truth of a twin experiment, and in \(\bs{\theta}\) of the parameters section, the space the filter estimates in.

Two forward runs per parameter, at \(\bs{\theta}_\mathrm{true} \pm h_\theta\) along it, give the noise-weighted sensitivities of the predicted data at each measurement time \(t^k\) by centered differences. \(h_\theta\) is the step in \(\theta\) of sensitivity.step, a relative change of the parameter, or a fraction of its prior standard deviation for additive parameters (theta_step()):

\[\bs{\tilde{J}}^k = \bs{W}^{-1/2} \frac{\partial \mathcal{H}\big(\bs{\chi}^k(\bs{\theta})\big)}{\partial \bs{\theta}} \bigg|_{\bs{\theta} = \bs{\theta}_\mathrm{true}}, \qquad \bs{M} = \sum_{k=1}^{N_T} \big(\bs{\tilde{J}}^k\big)^T \bs{\tilde{J}}^k,\]

with \(\bs{W}\) the noise covariance of the measurements’ noise.stddev, which estimation assumes too, and the stacked \(\bs{\tilde{J}}\) of all times and measurements. The runs themselves are noise-free.

  • \(\bs{M}^{-1}\) is the Cramér-Rao bound of the covariance of an estimate from the data alone. The filter’s \(\bs{P}_\theta\) also contains the prior: compare it with the Bayesian Cramér-Rao bound \((\bs{M} + (\bs{P}^0_\theta)^{-1})^{-1}\), which includes the prior. For observations linear in \(\bs{\theta}\), the filter’s \(\bs{P}_\theta\) after each pass equals it: with additive and multiplicative, observations linear in the parameters are also linear in \(\bs{\theta}\); with log, they are not. It is close to \(\bs{M}^{-1}\) only where the data dominate the prior (see below).

  • \(\bs{\theta}\) is the filter’s: the study’s parameterization, anchored at the prior means, with \(\bs{\theta}_\mathrm{true}\) the nominal parameters in it. So \(\bs{M}\) and the filter’s \(\bs{P}_\theta\) compare directly, in every outer iteration, and the Bayesian bound uses the filter’s prior \(\bs{P}^0_\theta\), the same in every pass.

  • The singular values \(s_1 \geq \dots \geq s_p\) of \(\bs{\tilde{J}}\) and its right singular vectors, the columns of \(\bs{V}\) in \(\bs{\tilde{J}} = \bs{U} \operatorname{diag}(\bs{s}) \bs{V}^T\), are also the eigendecomposition of the Fisher information, \(\bs{M} = \bs{V} \operatorname{diag}(\bs{s})^2 \bs{V}^T\). Each vector is a combination of the parameters, determined well by the data for a large \(s_i\), poorly for a small one. The condition number \(\kappa = s_1 / s_p\) summarizes this with the ratio of the best to the worst determined combination. The SVD of \(\bs{\tilde{J}}\) is better conditioned than the eigendecomposition of \(\bs{M}\), whose condition number is \(\kappa^2\): the small eigenvalues of \(\bs{M}\) lose accuracy first, so kipe decomposes \(\bs{\tilde{J}}\). For additive parameters, the decomposition depends on their units.

The runs are independent: run() computes one of them, e.g., as a task of a job array, assemble() combines them, and read_sensitivity() reads the result back, e.g., for kipe plot-sensitivity (kipe.plot.plot_sensitivity()). Output, in <output.path>/sensitivity/:

  • runs/<i>/: the predicted data of run \(i\), one file per measurement in the format of the data files, with the run’s log and provenance;

  • sensitivity.npz: the sensitivities, the Fisher information per measurement and in total (the information of several measurements adds up), the singular values and right singular vectors of the noise-weighted sensitivities (corresponding to the square-roots of eigenvalues and to the eigenvectors of the Fisher information, respectively), the Cramér-Rao covariance, standard deviations and correlations, and the Bayesian Cramér-Rao covariance and standard deviations.

class kipe.sensitivity.Sensitivity(names: list[str], theta: NDArray_f64, stddev_theta: NDArray_f64, jacobians: dict[str, NDArray_f64], fims: dict[str, NDArray_f64], fim: NDArray_f64, singular_values: NDArray_f64, right_singular_vectors: NDArray_f64, condition_number: float, covariance: NDArray_f64, posterior_covariance: NDArray_f64)[source]

Bases: object

The result of a sensitivity analysis, in \(\theta\).

names: list[str]

Names of the estimated parameters.

theta: NDArray_f64

\(\bs{\theta}_\mathrm{true}\), which maps to the nominal parameters.

stddev_theta: NDArray_f64

Prior standard deviations \(\sigma_\theta\), of the parameters section.

jacobians: dict[str, NDArray_f64]

Sensitivities \(\partial \mathcal{H} / \partial \bs{\theta}\) of each measurement, not weighted with the noise: one row per entry of its data, the entries of all its times one after another; one column per parameter.

fims: dict[str, NDArray_f64]

Fisher information of each measurement.

fim: NDArray_f64

the sum of theirs.

Type:

Fisher information of all measurements

singular_values: NDArray_f64

Singular values of the noise-weighted sensitivities \(\bs{\tilde{J}}\) in descending order, corresponding to the square roots of the eigenvalues of the Fisher information.

right_singular_vectors: NDArray_f64

Right singular vectors of the noise-weighted sensitivities \(\bs{\tilde{J}}\), column-wise, in the order of the singular values. They correspond to eigenvectors of the Fisher information.

condition_number: float

Condition number \(\kappa = s_1 / s_p\) of the noise-weighted sensitivities of all times and measurements, from their singular values.

covariance: NDArray_f64

Cramér-Rao bound of the covariance of \(\theta\), the inverse Fisher information; infinite where it is singular.

posterior_covariance: NDArray_f64

Bayesian Cramér-Rao bound, with the prior: \((\bs{M} + (\bs{P}^0_\theta)^{-1})^{-1}\), to compare with the filter’s \(\bs{P}_\theta\).

property stddev: NDArray_f64

Cramér-Rao standard deviations of \(\theta\).

property posterior_stddev: NDArray_f64

Standard deviations of \(\theta\) of the Bayesian Cramér-Rao bound.

property correlation: NDArray_f64

Cramér-Rao correlations.

kipe.sensitivity.run_count(study: StudyOptions) → int[source]

Return the number of forward runs of the sensitivity analysis: two per parameter.

Parameters:

study – the study options, with parameters

Returns:

the number of runs

kipe.sensitivity.run_directory(study: StudyOptions, index: int) → Path[source]

Return the output directory of a run, e.g., <output.path>/sensitivity/runs/03.

Parameters:
  • study – the study options

  • index – number of the run, from 0

Returns:

the directory, numbered with as many digits as the largest number

Raises:

StudyFileError – if the study has no such run

kipe.sensitivity.run(study: StudyOptions, index: int, comm: mpi4py.MPI.Comm = mpi4py.MPI.COMM_WORLD) → None[source]

Compute one forward run of the sensitivity analysis, and write its predicted data.

Run \(i\) perturbs parameter \(i // 2\), by \(+h_\theta\) for even \(i\), by \(-h_\theta\) for odd \(i\), the step in \(\theta\) of sensitivity.step (theta_step()).

Parameters:
  • study – the study options

  • index – number of the run, from 0

  • comm – communicator over which the model state is distributed

Raises:

StudyFileError – if the study lacks what the sensitivity analysis needs, or has no such run

kipe.sensitivity.assemble(study: StudyOptions, comm: mpi4py.MPI.Comm = mpi4py.MPI.COMM_WORLD) → Sensitivity[source]

Combine the runs of the sensitivity analysis; write and log the result.

Every rank reads the runs; rank 0 writes sensitivity.npz.

Parameters:
  • study – the study options

  • comm – communicator of the run

Returns:

the result

Raises:

StudyFileError – if a run is missing or unfinished, or was computed with other parameters than the study’s

kipe.sensitivity.read_sensitivity(path: str | Path) → Sensitivity[source]

Read the result of a sensitivity analysis from its sensitivity.npz.

Parameters:

path – path to the file, <output.path>/sensitivity/sensitivity.npz

Returns:

the result