objectives.brier
objectives.brier(data, /, predictive=None, *, generator=None)Brier score: the squared error between predictive probabilities and targets, per example.
With \(N\) the examples over all batches,
\[ \frac{1}{N} \sum_{n=1}^{N} \sum_{j} (p_{nj} - t_{nj})^2, \]
where \(j\) runs over classes (against one-hot class indices \(t\)) for a Categorical predictive, or over outputs for a Bernoulli one, and over positions. A two-class Categorical therefore gives twice the Brier score of the matching single-output Bernoulli. Every position counts: a likelihood’s mask is not applied.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| data | Data | Iterable[Any] | Data with targets, in any form lk.laplace takes: a list or DataLoader of (inputs, targets) pairs, or a Data source. It is read once, into a list. Targets are class indices shaped like the probabilities without the class axis (Categorical), or values in \([0, 1]\) shaped like the probabilities (Bernoulli). |
required |
| predictive | Predictive[Posterior] | None | The predictive method. None means Linearized(), resolved against the posterior. |
None |
| generator | torch.Generator | None | Seeds the draws of a sampled predictive (lk.Linearized(n_samples=64), say). One seed is drawn when the objective is built, and every call reuses it, so the objective is a function of the posterior alone, as lk.Minimize needs. None draws the seed from torch’s global RNG. |
None |
Returns
| Name | Type | Description |
|---|---|---|
| Objective[Posterior] | The objective, a function of a posterior to a 0-dim tensor. When called, it raises CapabilityError for a predictive distribution other than a Categorical or a Bernoulli (under any Independent wrappers), StructureError for targets of another shape, and ValueError for a batch without targets, non-integer or out-of-range class indices, or Bernoulli targets outside \([0, 1]\). |