predict
predict(posterior, inputs, method=None, *, select=None, generator=None)Predictive distribution over targets, observation noise included.
probs = lk.predict(post, x).probs
probs = lk.predict(post, x, method=lk.Linearized(link=lk.Probit())).probslk.predict_outputs gives the Gaussian over the model outputs alone.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| posterior | P | The posterior, weight-space or function-space. | required |
| inputs | Inputs | The inputs. A mapping that is not a pytree node (a tokenizer’s BatchEncoding) becomes a dict, so select and the method see the same inputs. |
required |
| method | Predictive[P] | None | The predictive method. None means lk.Linearized(), resolved against the posterior (and the event size of the selected outputs) when it runs. A method accepts some posteriors only: WeightSamples needs a weight-space one. |
None |
| select | Callable[[Outputs, Inputs], Outputs] | None | select(f, inputs) picks the outputs to predict, e.g. lambda f, x: f[:, -1] for the last position of a sequence model. The posterior’s model is replaced by the selected one before the method runs, so Linearized linearizes the selected outputs only. None keeps all outputs. |
None |
| generator | torch.Generator | None | The generator of a sampled method (WeightSamples, sampled outputs or an MC link). None means torch’s global RNG, so torch.manual_seed makes the prediction repeatable. |
None |
Returns
| Name | Type | Description |
|---|---|---|
| Distribution | The distribution over targets, from the method. |
Raises
| Name | Type | Description |
|---|---|---|
| TypeError | method is not a predictive method (a link such as lk.Probit(), which goes inside lk.Linearized(link=...)), or it takes another kind of posterior. |
|
| CapabilityError | The method, or its link, doesn’t support the likelihood (one with no distribution, say) or the model lacks what the method needs. | |
| ValueError | The method refuses its settings or its numbers (Probit with negative logit variances, say). |
|
| RuntimeError | A parameter changed in place since the fit (check_versions). |
|
| StructureError | The method refuses the outputs, or the posterior’s covariance products fail. | |
| NotImplementedError | The model does not return a single tensor. |