Skip to main content

core.WeightPosterior

core.WeightPosterior()

A fitted weight-space Gaussian \(\mathcal{N}(\mu, \Sigma)\) over the parameters in mean.

A posterior whose covariance products batch can also define cov_many and cov_sqrt_many and so satisfy HasCovMany. For the exact output covariance, outputs (and the predictives built on it) then passes each chunk of vectors to them in one call instead of vmapping cov_mv and cov_sqrt_mv. This is the fast path for many outputs.

Attributes

Name Description
caps The model’s capabilities, which outputs and sample_outputs check.
layout The block layout of the parameters.
likelihood The likelihood of the fit.
mean The mean \(\mu\), a parameter mapping.
model The model the posterior was fitted for.
variance The diagonal of \(\Sigma\).

Methods

Name Description
cov_mv The product \(\Sigma v\).
cov_sqrt_mv The product \(L v\) with a square root of the covariance, \(L L^\top = \Sigma\).
precision The precision \(\Sigma^{-1}\).
sample n_samples draws from \(\mathcal{N}(\mu, \Sigma)\).
sample_centered n_samples draws from \(\mathcal{N}(0, \Sigma)\).

cov_mv

core.WeightPosterior.cov_mv(v, /)

The product \(\Sigma v\).

Parameters

Name Type Description Default
v Params Parameter mapping with the mean’s keys and shapes. required

Returns

Name Type Description
Params \(\Sigma v\), a parameter mapping.

Raises

Name Type Description
StructureError Implementations may raise it when the precision is not positive definite or v doesn’t fit the operator’s structure.

cov_sqrt_mv

core.WeightPosterior.cov_sqrt_mv(v, /)

The product \(L v\) with a square root of the covariance, \(L L^\top = \Sigma\).

Parameters

Name Type Description Default
v Params Parameter mapping with the mean’s keys and shapes. required

Returns

Name Type Description
Params \(L v\), a parameter mapping.

Raises

Name Type Description
StructureError Implementations may raise it when the precision is not positive definite or v doesn’t fit the operator’s structure.

precision

core.WeightPosterior.precision()

The precision \(\Sigma^{-1}\).

Returns

Name Type Description
Operator[Any] A precision operator.

sample

core.WeightPosterior.sample(n_samples, /, *, generator=None)

n_samples draws from \(\mathcal{N}(\mu, \Sigma)\).

Parameters

Name Type Description Default
n_samples int Number of draws. required
generator torch.Generator | None The generator to draw with, on any device: the draws move to the mean’s. None means torch’s global RNG. None

Returns

Name Type Description
Params A parameter mapping with a leading axis of n_samples on every leaf.

Raises

Name Type Description
StructureError Implementations may raise it when the precision is not positive definite.

sample_centered

core.WeightPosterior.sample_centered(n_samples, /, *, generator=None)

n_samples draws from \(\mathcal{N}(0, \Sigma)\).

Parameters

Name Type Description Default
n_samples int Number of draws. required
generator torch.Generator | None The generator to draw with, on any device: the draws move to the mean’s. None means torch’s global RNG. None

Returns

Name Type Description
Params A parameter mapping with a leading axis of n_samples on every leaf, in at least float32 (stat_dtype).

Raises

Name Type Description
StructureError Implementations may raise it when the precision is not positive definite.