# core.WeightPosterior

``` python
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](#laplacekit.core.WeightPosterior.caps) | The model’s capabilities, which `outputs` and `sample_outputs` check. |
| [layout](#laplacekit.core.WeightPosterior.layout) | The block layout of the parameters. |
| [likelihood](#laplacekit.core.WeightPosterior.likelihood) | The likelihood of the fit. |
| [mean](#laplacekit.core.WeightPosterior.mean) | The mean $\mu$, a parameter mapping. |
| [model](#laplacekit.core.WeightPosterior.model) | The model the posterior was fitted for. |
| [variance](#laplacekit.core.WeightPosterior.variance) | The diagonal of $\Sigma$. |

## Methods

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

### cov_mv

``` python
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

``` python
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

``` python
core.WeightPosterior.precision()
```

The precision $\Sigma^{-1}$.

#### Returns

| Name | Type            | Description           |
|------|-----------------|-----------------------|
|      | Operator\[Any\] | A precision operator. |

### sample

``` python
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

``` python
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. |
