Skip to main content

testing.check_prior

testing.check_prior(prior, params)

Check a prior against the core contracts.

  • It satisfies PriorWithCovariance (log_prob, location, add_precision_to, cov_mv), and log_prob(params) is a tensor with one finite element.
  • For a TunablePrior, tunable() returns positive tensors that are leaves of the prior itself (not copies), alone or in a mapping.
  • add_precision_to keeps the operator type, block by block for a BlockDiag. It is tried on Diag, BlockDiag[Diag], LowRankPlusDiag, and for at most DENSE_MAX_PARAMS parameters on KronEigenbasis per block, Dense, BlockDiag[Dense] and Joint[Dense]. Refusing one with StructureError or CapabilityError is allowed; refusing all is not. Types compare exactly, so returning a subclass of the operator’s type fails.
  • cov_mv is the inverse of the prior’s precision: \(\mathrm{cov\_mv}(v) = P^{-1} v\) for a random \(v\), where \(P\) is read off by adding the prior to each zero operator it accepts: Diag, BlockDiag[Diag], and for at most DENSE_MAX_PARAMS parameters Dense, BlockDiag[Dense] and Joint[Dense]. Refusing all fails.

Every equality holds up to RTOL. Errors that the prior raises, other than a refusal by add_precision_to, propagate.

Parameters

Name Type Description Default
prior PriorWithCovariance The prior. required
params Params Float64 parameter mapping. Blocks follow Layout.by_module(params). required

Raises

Name Type Description
AssertionError A law above fails. The message names the law and prior.
ValueError params are not float64, or the prior accepts a single-block zero operator (Diag, Dense) and the params are not grouped by module.