Low-Rank BLR¶
The scalable middle ground: precision parameterised as
\(\Lambda = \operatorname{diag}(D) + UU^\top\) with \(U \in \mathbb{R}^{d \times r}\),
giving \(O(dr)\) storage and \(O(dr^2 + r^3)\) solves through the Woodbury
identity. Structured solves are dispatched via
gaussx LowRankUpdate operators
(requires the optional gaussx extra).
Transforms¶
blr_low_rank_for_loss(learning_rate: float = 0.01, rank: int = 10, prior_precision: float = 0.0001, prior_mean: jnp.ndarray | None = None, hessian_estimator: str | Callable = 'ggn', damping: float = 1e-06, solver: Solver | None = None) -> optax.GradientTransformation
¶
Low-rank BLR accepting standard loss gradients.
Wraps blr_low_rank: negates incoming
gradients (\(g_{\text{loglik}} = -g_{\text{loss}}\)) and, for callable
Hessian estimators, negates the returned matrix so the inner BLR
transform receives log-likelihood Hessians.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
learning_rate
|
float
|
Step size rho in (0, 1]. |
0.01
|
rank
|
int
|
Target rank r of the low-rank factor U. |
10
|
prior_precision
|
float
|
Scalar diagonal prior precision. |
0.0001
|
prior_mean
|
ndarray | None
|
Prior mean vector (d,), or None for zeros. |
None
|
hessian_estimator
|
str | Callable
|
|
'ggn'
|
damping
|
float
|
Additive damping on the diagonal. |
1e-06
|
solver
|
Solver | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
GradientTransformation
|
An |
Source code in src/optax_bayes/_src/wrappers.py
blr_low_rank(learning_rate: float = 0.01, rank: int = 10, prior_precision: float = 0.0001, prior_mean: jnp.ndarray | None = None, hessian_estimator: str | Callable = 'ggn', damping: float = 1e-06, solver: Solver | None = None) -> optax.GradientTransformation
¶
Low-rank Gaussian BLR as an optax transform.
Parameterises the precision as
\(\Lambda = \operatorname{diag}(D) + U U^\top\) with \(D \in
\mathbb{R}^d\) and \(U \in \mathbb{R}^{d \times r}\), giving
\(O(dr)\) storage and \(O(dr^2 + r^3)\) solves via the Woodbury
identity through gaussx structured operators (requires the
optional gaussx extra).
The update is SLANG's (Mishkin et al., 2018). With the curvature in
factor form \(-H_t = G_t G_t^\top\) (\(G_t = g_t\) for "ggn"), the
target precision \((1-\rho)\Lambda_t + \rho(\Lambda_0 - H_t)\) is
\(\operatorname{diag}((1-\rho) D_t + \rho D_0) + \tilde U \tilde U^\top\)
with \(\tilde U = [\sqrt{1-\rho}\, U_t,\ \sqrt{\rho}\, G_t]\). A thin
SVD keeps the top \(r\) directions of \(\tilde U\), and the diagonal of
the discarded part is added to \(D\):
so the diagonal of the precision is updated exactly, and the whole
precision is exact when \(r \ge d\). A step costs \(O(d (r + k)^2)\) for
a rank-\(k\) factor: \(O(d r^2)\) for "ggn". The mean takes the
mean-form Gaussian BLR step
which matches the natural-mean recursion of blr_full_rank whenever
the precision is exact and stays stable when it is truncated. The
state initialises its mean at the params passed to init;
prior_mean and prior_precision anchor every update.
This API expects log-likelihood gradients. For standard loss
minimisation, use
blr_low_rank_for_loss instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
learning_rate
|
float
|
Step size rho in (0, 1]. |
0.01
|
rank
|
int
|
Target rank r of the low-rank factor U. |
10
|
prior_precision
|
float
|
Scalar diagonal prior precision D_0 = s0 * I. |
0.0001
|
prior_mean
|
ndarray | None
|
Prior mean vector (d,), or None for zeros. |
None
|
hessian_estimator
|
str | Callable
|
|
'ggn'
|
damping
|
float
|
Additive damping epsilon on the diagonal after each
update, as in |
1e-06
|
solver
|
Solver | None
|
A |
None
|
Returns:
| Type | Description |
|---|---|
GradientTransformation
|
An |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the optional |
Source code in src/optax_bayes/_src/low_rank.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
Posterior extraction & sampling¶
get_posterior_low_rank(state: BLRLowRankState, solver: Solver | None = None) -> tuple[jnp.ndarray, jnp.ndarray]
¶
Extract the approximate posterior from low-rank BLR state.
Returns the mean and covariance of
\(q(\theta) = \mathcal{N}(\Lambda^{-1}\eta,\ \Lambda^{-1})\) with
\(\Lambda = \operatorname{diag}(D) + U U^\top\), using gaussx
structured operators for the mean solve and gaussx.inv for the
covariance (Woodbury-dispatched; requires the optional gaussx
extra).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
BLRLowRankState
|
A |
required |
solver
|
Solver | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Tuple |
ndarray
|
covariance is (d, d). |
Source code in src/optax_bayes/_src/posterior.py
sample_posterior_low_rank(state: BLRLowRankState, key: jax.Array) -> jnp.ndarray
¶
Draw one reparameterised sample from the low-rank posterior.
Samples \(\theta \sim \mathcal{N}(m, \Lambda^{-1})\) where \(\Lambda = \operatorname{diag}(D) + U U^\top\), using a two-step Gaussian trick that never forms the dense covariance:
- Draw \(z \sim \mathcal{N}(0, \Lambda)\) cheaply via \(z = \sqrt{D} \odot \epsilon_1 + U \epsilon_2\).
- Solve \(\Lambda y = z\) via Woodbury; then \(y \sim \mathcal{N}(0, \Lambda^{-1})\).
Cost: \(O(dr + r^3)\) memory, \(O(dr^2 + r^3)\) time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
BLRLowRankState
|
A |
required |
key
|
Array
|
PRNG key. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Sampled parameter vector, shape (d,). |
Source code in src/optax_bayes/_src/sampling.py
State¶
BLRLowRankState
¶
Bases: NamedTuple
Low-rank natural-parameter state: \(\Lambda = \operatorname{diag}(D) + U U^\top\).
Attributes:
| Name | Type | Description |
|---|---|---|
diag_precision |
Array
|
Diagonal precision \(D\), shape |
low_rank_factor |
Array
|
Low-rank factor \(U\), shape |
nat_mean |
Array
|
Natural mean \(\eta = \Lambda m\), shape |
count |
Array
|
Scalar step counter. |