Linearized
Linearized(link=None, strategy=None, n_samples=None, chunk_size=None)Linearize the model at the mean, push the weight-space posterior to outputs, apply a link.
For a weight-space posterior \(\mathcal{N}(\mu, \Sigma)\), the model is linearized at its mean,
\[f(x; \theta) \approx f(x; \mu) + J(x) (\theta - \mu),\]
with \(J(x)\) the Jacobian of the outputs with respect to the parameters at \(\mu\). The outputs at \(x\) are then Gaussian, \(\mathcal{N}\big(f(x; \mu), J(x) \Sigma J(x)^\top\big)\) (see outputs), and the link turns them into a distribution over targets.
None fields are chosen by resolve from the posterior’s capabilities and likelihood.
On a function-space posterior the link is applied to posterior.at(inputs), which is already the Gaussian over the outputs; strategy, n_samples and chunk_size must stay unset.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| link | LinkApprox | None | Turns the output Gaussian into the predictive. None takes it from the likelihood: for a Categorical or Bernoulli, Probit on the exact covariance and MC over all the draws of a SampleCov; for a Gaussian, Exact; otherwise the likelihood’s default_link (HasDefaultLink). |
None |
| strategy | Strategy | None | How the Jacobian products run, "forward-mode" (JVPs) or "reverse-mode" (VJPs), as in torch.autograd.functional.jacobian. None picks: for exact outputs, the cheaper path that fits; for sampled outputs, reverse mode (a VJP of a VJP) when the probe found it works, else forward mode. The VJP of a VJP keeps the batch’s forward and backward graph until the last draw; strategy="forward-mode" runs the forward per draw instead. |
None |
| n_samples | int | Literal['exact'] | None | "exact" for the exact output covariance. An int (at least 2, and at least an MC link’s n_samples) gives a SampleCov of that many draws; see lk.predict_outputs. None is exact when the exact path fits its budget, else 64 draws, or the MC link’s n_samples if larger. |
None |
| chunk_size | int | None | Output entries (reverse mode) or parameter directions (forward mode) per Jacobian chunk of the exact covariance. None means 256. |
None |
Attributes
| Name | Description |
|---|---|
| requires | What the pushforward needs, by strategy and n_samples. |
Methods
| Name | Description |
|---|---|
| resolve | Fill the None fields from the posterior’s capabilities and likelihood. |
resolve
Linearized.resolve(posterior, /)Fill the None fields from the posterior’s capabilities and likelihood.
The event size is the probe’s (caps.event_size). A function-space posterior gives its output Gaussian through at, so only link is resolved, as for exact outputs.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| posterior | Posterior | A weight-space or function-space posterior. | required |
Returns
| Name | Type | Description |
|---|---|---|
| Linearized | A copy with link, strategy and n_samples resolved and chunk_size as given. For a function-space posterior, a copy with link resolved and n_samples="exact". |
Raises
| Name | Type | Description |
|---|---|---|
| TypeError | posterior is neither a weight-space nor a function-space posterior. |
|
| CapabilityError | The likelihood has no distribution (lk.predict_outputs still gives the Gaussian over \(f\)), or it needs a default link and has none (it is not a Categorical or a Gaussian and has no HasDefaultLink). For a weight-space posterior, also: the likelihood is a Categorical and the probed outputs have one entry per input (one class, or none), or the model lacks what requires asks for. |
|
| ValueError | For a function-space posterior, an explicit strategy, n_samples or chunk_size. For a weight-space posterior, an int n_samples below 2, a chunk_size below 1, or an int n_samples (given, or the default number of draws) below the n_samples of the MC link, given or from the likelihood’s default link. |