Uncertainties#

Parameter uncertainty estimation from Hessian-based covariance.

everwillow.uncertainty.correlation_matrix(nll_fn, params, observation, *, fixed=None)[source]#

Compute the correlation matrix (normalized covariance).

The covariance matrix is normalized so that diagonal entries are 1.0:

ρ_ij = Cov_ij / √(Cov_ii · Cov_jj)

Parameters:
  • nll_fn (Callable[[PyTree[~V], PyTree], float]) – Negative log-likelihood function taking (params, observation).

  • params (State[V]) – Full parameter state at which to evaluate.

  • observation (PyTree) – Observed data passed to nll_fn.

  • fixed (State[V | EllipsisType] | None) – Parameters to exclude from correlation computation.

Returns:

2D JAX array with diagonal = 1.0, off-diagonal in [-1, 1].

Return type:

Array

everwillow.uncertainty.covariance_matrix(nll_fn, params, observation, *, fixed=None)[source]#

Compute the covariance matrix (inverse Hessian) at given parameters.

The Fisher information matrix is obtained by inverting the Hessian:

Cov(θ) = H⁻¹ where H_ij = ∂²NLL/∂θ_i∂θ_j

This is the Laplace approximation to the posterior covariance.

Parameters:
  • nll_fn (Callable[[PyTree[~V], PyTree], float]) – Negative log-likelihood function taking (params, observation).

  • params (State[V]) – Full parameter state (typically fitted values).

  • observation (PyTree) – Observed data passed to nll_fn.

  • fixed (State[V | EllipsisType] | None) – Parameters to exclude from covariance computation.

Returns:

2D JAX array of shape (n_free, n_free).

Return type:

Float[Array, ‘nparams nparams’]

everwillow.uncertainty.hessian_matrix(nll_fn, params, observation, *, fixed=None)[source]#

Compute the Hessian matrix of the NLL at given parameters.

The Hessian H_ij = ∂²NLL/∂θ_i∂θ_j is computed only for free (non-fixed) parameters using JAX automatic differentiation.

Parameters:
  • nll_fn (Callable[[PyTree[~V], PyTree], float]) – Negative log-likelihood function taking (params, observation).

  • params (State[V]) – Full parameter state at which to evaluate the Hessian.

  • observation (PyTree) – Observed data passed to nll_fn.

  • fixed (State[V | EllipsisType] | None) – Parameters to treat as constants (excluded from Hessian).

Returns:

2D JAX array of shape (n_free, n_free).

Return type:

Float[Array, ‘n_free n_free’]

everwillow.uncertainty.uncertainties(nll_fn, params, observation, *, fixed=None)[source]#

Extract parameter uncertainties as sqrt(diag(covariance)).

The uncertainties are the square roots of the diagonal of the covariance matrix (inverse Fisher information), following the Cramér-Rao bound: σ_i = √(Cov_ii) = √((H⁻¹)_ii)

Parameters:
  • nll_fn (Callable[[PyTree[~V], PyTree], float]) – Negative log-likelihood function taking (params, observation).

  • params (State[V]) – Full parameter state (typically fitted values).

  • observation (PyTree) – Observed data passed to nll_fn.

  • fixed (State[V | EllipsisType] | None) – Parameters to exclude from uncertainty computation.

Returns:

State containing uncertainty values for free parameters only.

Return type:

State[V]