# priors.LowRankSum

``` python
priors.LowRankSum(summed, base, mean, rank=static())
```

A chain of `LowRankGGN` posteriors as the prior of a `LowRankGGN` fit, cut to a fixed rank.

The prior is $\mathcal{N}(\mu, (\Lambda_0 + S)^{-1})$, with $\Lambda_0$ the precision of `base` and $S$ the summed curvature. Build it with `LowRankSum.of(post)`. Each step sums the scaled low-rank curvatures and keeps the top $r$ eigenpairs of the sum:

$$S_t = \operatorname{trunc}_r(S_{t-1} + c_t C_t),$$

with $C_t$ the curvature of fit $t$ and $c_t$ its scale times the likelihood’s curvature factor. Approximate: the eigenpairs below the top $r$ are dropped, so the prior has less precision (more variance) in those directions. A plain `LowRankGGN` posterior as the prior is exact, but its width grows by the curvature’s rank with every fit.

The chain is held flat, as in `KronSum`.

Both curvatures must be a `Joint` of `LowRankPlusDiag` over the same blocks; others raise `StructureError`, for `post` in `of`, for the new fit when its precision is formed (in `lk.laplace`, before the data pass). Not tuned by default and not pushable to function space.

## Parameters

| Name | Type | Description | Default |
|----|----|----|----|
| summed | Joint\[LowRankPlusDiag\] | $S$, the truncated sum of every earlier fit’s scaled curvature (zero diagonal). | *required* |
| base | Prior | The first prior in the chain that is not a `LowRankSum`, added once, after the sum. | *required* |
| mean | Params | The last posterior’s mean $\mu$. | *required* |
| rank | int | The rank $r$ kept, at least 1. | `static()` |

## Raises

| Name | Type           | Description                                     |
|------|----------------|-------------------------------------------------|
|      | StructureError | `summed` is not a `Joint` of `LowRankPlusDiag`. |
|      | ValueError     | `rank < 1`.                                     |

## Methods

| Name | Description |
|----|----|
| [add_precision_to](#laplacekit.priors.LowRankSum.add_precision_to) | $\operatorname{trunc}_r(S + \text{op})$ plus the precision $\Lambda_0$ of `base`. |
| [location](#laplacekit.priors.LowRankSum.location) | The last posterior’s mean. |
| [log_prob](#laplacekit.priors.LowRankSum.log_prob) | $\log \mathcal{N}(\theta; \mu, (\Lambda_0 + S)^{-1})$, in the dtype of $S$. |
| [of](#laplacekit.priors.LowRankSum.of) | The prior for the fit after `post`: its scaled curvature added to the chain. |

### add_precision_to

``` python
priors.LowRankSum.add_precision_to(op, /)
```

$\operatorname{trunc}_r(S + \text{op})$ plus the precision $\Lambda_0$ of `base`.

#### Parameters

| Name | Type | Description           | Default    |
|------|------|-----------------------|------------|
| op   | Op   | A precision operator. | *required* |

#### Returns

| Name | Type | Description                                            |
|------|------|--------------------------------------------------------|
|      | Op   | An operator of the same type, $\text{op} + \Lambda_0$. |

#### Raises

| Name | Type | Description |
|----|----|----|
|  | StructureError | `op` is not a `Joint` of `LowRankPlusDiag`, its blocks or size differ from those of $S$, or `base` can’t add its precision. |

### location

``` python
priors.LowRankSum.location(like, /)
```

The last posterior’s mean.

#### Parameters

| Name | Type | Description | Default |
|----|----|----|----|
| like | Params | Parameter mapping whose names, shapes, dtypes and devices the mean must have. | *required* |

#### Returns

| Name | Type   | Description                    |
|------|--------|--------------------------------|
|      | Params | The mean, a parameter mapping. |

### log_prob

``` python
priors.LowRankSum.log_prob(params, /)
```

$\log \mathcal{N}(\theta; \mu, (\Lambda_0 + S)^{-1})$, in the dtype of $S$.

#### Parameters

| Name | Type | Description | Default |
|----|----|----|----|
| params | Params | Parameter mapping with the posterior’s keys and shapes. | *required* |

#### Returns

| Name | Type   | Description                       |
|------|--------|-----------------------------------|
|      | Tensor | A 0-dim tensor, $\log q(\theta)$. |

### of

``` python
priors.LowRankSum.of(post, /, rank=None)
```

The prior for the fit after `post`: its scaled curvature added to the chain.

With $C$ the curvature of `post` and $c$ its scale times the likelihood’s curvature factor, the new $S$ is $\operatorname{trunc}_r(S + cC)$ when the prior of `post` is a `LowRankSum` with summed curvature $S$, and $\operatorname{trunc}_r(cC)$ otherwise.

#### Parameters

| Name | Type | Description | Default |
|----|----|----|----|
| post | LaplacePosterior\[Any, Any\] | A `LowRankGGN` posterior. | *required* |
| rank | int \| None | The rank $r$ kept, at least 1. `None` keeps the rank of the prior of `post` when that is a `LowRankSum`, and the width of the curvature of `post` otherwise. | `None` |

#### Returns

| Name | Type | Description |
|----|----|----|
|  | Self | The `LowRankSum`, with `post.mean` as its mean. Its `base` is the prior of `post`, or that prior’s `base` when it is a `LowRankSum`. |

#### Raises

| Name | Type | Description |
|----|----|----|
|  | StructureError | The curvature of `post` is not a `Joint` of `LowRankPlusDiag` (the message points a KFAC posterior to `KronSum.of`), or its blocks or size differ from the chain’s. |
|  | ValueError | `rank < 1`. |
