> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nimbusbci.com/llms.txt
> Use this file to discover all available pages before exploring further.

# NimbusProbit (Python)

> NimbusProbit for Python: a Bayesian probit head read by expectation propagation, with honest confidence on a few trials over features that outnumber them.

**Python**: `NimbusProbit` (since nimbus-bci 0.10.0) | **Julia**: [`NimbusProbit`](https://docs.nimbusbci.com/models/nimbusprobit), a different model with the same name\

**Mathematical model**: Bayesian probit regression, one problem per class against the rest

`NimbusProbit` is a linear classifier built for one regime: a few calibration trials over features that outnumber them many times over — a frozen trunk's embeddings. Its point is not accuracy. Its point is that the probabilities it reports follow the evidence: with few trials the posterior is diffuse, and the head says so.

> [!NOTE]
>
> **Python Personalizer head:** `Personalizer.for_features(classes, head="probit")`, or `Personalizer(encoder=enc, head="probit")`. On this head `fit_calibrated` fits the risk gate — a certificate replaces the fixed gate. See [Trust & calibration](https://docs.nimbusbci.com/personalizer/trust-and-calibration.md).

## Quick Start

```python theme={null}
from nimbus_bci import NimbusProbit

clf = NimbusProbit()                 # tau2=1.0, bias_var=100.0
clf.fit(Z_train, y_train)           # (n_trials, n_features): embeddings or features
probabilities = clf.predict_proba(Z_test)
labels = clf.predict(Z_test)
clf.partial_fit(Z_new, y_new)       # recomputes the posterior on every labelled trial
```

> [!TIP]
>
> Fit this head on features the encoder has not been fitted on. In-sample features of a supervised encoder are optimistic, and the probabilities come out overconfident.

## When to Use NimbusProbit

* A frozen trunk emits embeddings, and the subject has a few dozen labelled trials.
* You gate commands on the head's confidence and need that confidence to mean something.
* You want to read the posterior — for `predict_proba`, for active learning, for a calibrated gate — rather than the most likely weights.

## When Not to Use It

* **If accuracy is the only thing you want, and your features are covariance or bandpower features:** a plain `LogisticRegression` on the same features is as accurate. Use that.
* **If updates must be fast at scale:** `partial_fit` is a refit on all the labelled trials. It costs about 50 ms at 100 trials, 0.3 s at 200 and 0.8 s at 300 — tens to a few hundred trials, not thousands.
* **If you need per-trial weights or forgetting:** both raise `ValueError` on this head; every labelled trial counts in full.
* **If the session is drifting:** `NimbusSTS` models latent state; this head does not.

## Model Architecture

```text theme={null}
p(y = +1 | x) = Phi(w . x + c)
w ~ N(0, tau2 I)          tau2 = 1.0
c ~ N(0, bias_var)        bias_var = 100.0  (nearly flat)
```

With more than two classes, one such problem per class against the rest. The posterior of every problem is approximated by expectation propagation, on the trials — so the feature count can exceed the trial count. Reading the posterior, rather than plugging in its mode, is what keeps the probabilities honest.

A plain `LogisticRegression(C=1)` is this model's mode under a logit link and the same prior — which is exactly what the measured comparison below uses.

## Hyperparameters

| Parameter | Default | Meaning |
| - | - | - |
| `tau2` | `1.0` | Prior variance of every weight. The unit prior is the one measured |
| `bias_var` | `100.0` | Prior variance of the intercept |
| `max_passes` | `200` | Most expectation-propagation passes over the trials per fit |
| `tol` | `1e-7` | Expectation propagation stops when no site moved by more than this |
| `training_sfreq` | `None` | Sampling rate of the training data; persisted for the cross-session check |

## Training Requirements

* Feature rows shaped `(n_trials, n_features)`: embeddings, CSP, Riemann or bandpower features — not raw EEG.
* Labels as class labels; the head stores `classes_`, `n_classes_` and `n_features_in_`.
* The fitted `model_` holds the labelled trials — features and class indices — so the artifact grows with them, as `NimbusSoftmax`'s does.

## What Was Measured

One preregistered cell, read once (Zhou2016, 4 subjects; BNCI2015-001 session B, 12 subjects; 4–20 trials per class):

* **As accurate** as its own point estimate and as a plain `LogisticRegression(C=1)`, and above `NimbusLDA(kappa0="cv")` in accuracy.
* **Better calibrated than both:** log-loss lower by 0.096 \[0.066, 0.126] on Zhou2016 and 0.064 \[0.036, 0.087] on BNCI2015-001, at every size.
* **The gain lives on frozen-trunk embeddings.** On covariance features the logistic regression is as good or better.

Read through the Personalizer — its saved artifacts, its model file, its online update, in the pure-Python and in the compiled build — the head decides as the measured arm does on every test trial of that cell's 1,200 draws.

This is a calibration claim, not a decoding one.

## Model Selection Context

| Head | Use it for |
| - | - |
| `NimbusLDA` | The default; fast; motor imagery |
| `NimbusProbit` | Honest confidence on few trials over many features |
| [`NimbusSoftmax`](https://docs.nimbusbci.com/models/rxpolya) | Non-Gaussian static boundaries (optional JAX) |
| [`NimbusFusion`](https://docs.nimbusbci.com/models/nimbusfusion) | The classic SSVEP decision as a head |

## Next Read

> [card] [Trust & calibration](https://docs.nimbusbci.com/personalizer/trust-and-calibration.md)
>
> Why a certificate, not a fixed gate, decides on this head.

> [card] [Encoder contract](https://docs.nimbusbci.com/personalizer/encoder-contract.md)
>
> Wrap a frozen trunk so its embeddings reach the head.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.