core.LowRankPlusDiag
core.LowRankPlusDiag(factor, evals, diag)A diagonal plus a low-rank term, \(P = D + U \operatorname{diag}(s) U^\top\).
Here \(D = \operatorname{diag}(d)\). Products and the diagonal work for any \(d\); solve, inverse_diagonal, logdet and cov_sqrt_mv need \(d > 0\), which a prior gives. They use the Woodbury identity on a thin QR of the scaled factor and a second QR of a \(2r \times r\) matrix, so each costs \(O(n r^2)\); the dense matrix is never formed. With \(B = D^{-1/2} U \operatorname{diag}(s)^{1/2}\), the precision is \(P = D^{1/2} (I + B B^\top) D^{1/2}\). The thin QR \(B = Q R\) and the thin QR \([R^\top; I] = Q_2 T\) give \(T^\top T = I + R R^\top\), so
\[P^{-1} = D^{-1/2} \big(I - Q (I - (T^\top T)^{-1}) Q^\top\big) D^{-1/2}, \qquad \log \det P = \sum_i \log d_i + 2 \sum_j \log |T_{jj}|.\]
Through those four, an evals entry that is exactly zero gets no gradient (its column is dropped), and gradients may be NaN when the scaled factor has exactly dependent columns (the derivative of QR). Repeated singular values are fine.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| factor | Tensor | \(U\), [n, r]. |
required |
| evals | Tensor | \(s\), [r], non-negative. |
required |
| diag | Tensor | \(d\), [n]; zeros for a bare curvature. |
required |
Raises
| Name | Type | Description |
|---|---|---|
| StructureError | factor is not 2-D, or evals or diag has the wrong shape for it. |
Methods
| Name | Description |
|---|---|
| add_diagonal | \(P + \operatorname{diag}(d')\): the argument \(d'\) added to \(d\). |
| add_isotropic | \(P + \lambda I\): \(\lambda\) added to \(d\). |
| add_same | The exact sum: the factors and evals concatenated, the diagonals summed. |
| cov_sqrt_mv | \(L v\) with \(L = D^{-1/2} (I - Q Q^\top + Q T^{-1} Q^\top)\). |
| diagonal | \(d + (U \odot U) s\). |
| inverse_diagonal | The diagonal of \(P^{-1}\) from the Woodbury factors, without forming \(P^{-1}\). |
| logdet | \(\sum_i \log d_i + 2 \sum_j \log \|T_{jj}\|\). |
| mv | \(D v + U \operatorname{diag}(s) U^\top v\). |
| scaled | \(s P\): \(s d\) and \(s\) times evals. |
| solve | \(P^{-1} v\) by the Woodbury identity, with two triangular solves in \(T\). |
| truncated | The same diag, with the low-rank part cut to its top rank eigenpairs. |
add_diagonal
core.LowRankPlusDiag.add_diagonal(d, /)\(P + \operatorname{diag}(d')\): the argument \(d'\) added to \(d\).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| d | Tensor | The diagonal \(d\), shaped like a vector of the operator. | required |
Returns
| Name | Type | Description |
|---|---|---|
| Self | An operator of the same type. |
add_isotropic
core.LowRankPlusDiag.add_isotropic(precision, /)\(P + \lambda I\): \(\lambda\) added to \(d\).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| precision | Tensor | The precision \(\lambda\), a 0-dim tensor. | required |
Returns
| Name | Type | Description |
|---|---|---|
| Self | An operator of the same type. |
add_same
core.LowRankPlusDiag.add_same(other, /)The exact sum: the factors and evals concatenated, the diagonals summed.
The width grows with each sum, as for a LowRankGGN posterior used as the prior of a LowRankGGN fit; lk.priors.LowRankSum truncates it back to a fixed rank instead.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| other | Operator[Tensor] | The operator \(P'\). | required |
Returns
| Name | Type | Description |
|---|---|---|
| Self | An operator of the same type. |
Raises
| Name | Type | Description |
|---|---|---|
| StructureError | other is not a LowRankPlusDiag, or its size \(n\) differs. |
cov_sqrt_mv
core.LowRankPlusDiag.cov_sqrt_mv(v, /)\(L v\) with \(L = D^{-1/2} (I - Q Q^\top + Q T^{-1} Q^\top)\).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| v | Tensor | A vector [..., P]. |
required |
Returns
| Name | Type | Description |
|---|---|---|
| Tensor | \(L v\), shaped like v. |
diagonal
core.LowRankPlusDiag.diagonal()\(d + (U \odot U) s\).
Returns
| Name | Type | Description |
|---|---|---|
| Tensor | A vector [P]. |
inverse_diagonal
core.LowRankPlusDiag.inverse_diagonal()The diagonal of \(P^{-1}\) from the Woodbury factors, without forming \(P^{-1}\).
Entry \(i\) is \(\big(1 - \lVert Q_{i,:} \rVert^2 + \lVert M_{i,:} \rVert^2\big) / d_i\), with \(M = Q T^{-1}\).
Returns
| Name | Type | Description |
|---|---|---|
| Tensor | A vector [P]. |
logdet
core.LowRankPlusDiag.logdet()\(\sum_i \log d_i + 2 \sum_j \log |T_{jj}|\).
Returns
| Name | Type | Description |
|---|---|---|
| Tensor | A 0-dim tensor. |
mv
core.LowRankPlusDiag.mv(v, /)\(D v + U \operatorname{diag}(s) U^\top v\).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| v | Tensor | A vector [..., P]. |
required |
Returns
| Name | Type | Description |
|---|---|---|
| Tensor | \(P v\), shaped like v. |
scaled
core.LowRankPlusDiag.scaled(s, /)\(s P\): \(s d\) and \(s\) times evals.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| s | Tensor | A 0-dim factor. | required |
Returns
| Name | Type | Description |
|---|---|---|
| Self | An operator of the same type. |
solve
core.LowRankPlusDiag.solve(v, /)\(P^{-1} v\) by the Woodbury identity, with two triangular solves in \(T\).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| v | Tensor | A vector [..., P]. |
required |
Returns
| Name | Type | Description |
|---|---|---|
| Tensor | \(P^{-1} v\), shaped like v. |
truncated
core.LowRankPlusDiag.truncated(rank, /)The same diag, with the low-rank part cut to its top rank eigenpairs.
The eigenpairs of \(U \operatorname{diag}(s) U^\top\) below the top rank are dropped, so their precision is lost. Below the width, the columns whose evals entry is zero are dropped first, and the top rank are taken from the rest. It costs a thin QR \(U \operatorname{diag}(s)^{1/2} = Q R\) and an \(r \times r\) eigh of \(R R^\top\).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| rank | int | The number of eigenpairs to keep, at least 1. | required |
Returns
| Name | Type | Description |
|---|---|---|
| Self | The operator unchanged (exact) when rank is at or above the width. Otherwise one with min(rank, nonzero, n) columns, with nonzero the count of nonzero evals and n the number of rows, so it can be narrower than rank. Its eigenvalues are clamped at zero. |
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | rank is below 1. |