> ## 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.

# Research surfaces: transforms and PEFT

> Opt-in research surfaces of the Personalizer: embedding-space transforms (whiten, CORAL, RPA, affine) and BaLoRA / LoRA trunk arms behind nimbus-bci[train].

Everything on this page is an **opt-in research surface**. No certified accuracy claims. The production default remains a frozen trunk + Bayesian head (`for_deployment`) with no transform; what is certified is on [Trust & calibration](https://docs.nimbusbci.com/personalizer/trust-and-calibration.md) and [Evidence](https://docs.nimbusbci.com/personalizer/evidence.md).

## Embedding transforms

The Personalizer can apply an **embedding-space transform** on `Z` before the head. Use this when calibration and stream embeddings shift, without retraining the trunk.

| Family | Names | When |
| - | - | - |
| **Cal-fitted (unsupervised)** | `standardize`, `whiten`, `euclidean_alignment` | Fit at `fit()` from calibration embeddings |
| **Two-distribution / supervised** | `coral`, `rpa`, `affine` | Need a stream (or second) slice after fit — **offline / research**, not deployment defaults |

```python theme={null}
from nimbus_bci import Personalizer, wrap

enc = wrap(model.encode, model_id="partner", embedding_dim=64)

# Cal-fitted — common research path
p = Personalizer.for_research(enc, ["left", "right"], transform="whiten")
p.fit(X_cal, y_cal)

# Two-distribution maps — after fit, pass a shifted stream slice
p2 = Personalizer.for_research(enc, ["left", "right"], transform="coral")
p2.fit(X_cal, y_cal)
p2.fit_coral(X_stream)           # two-distribution CORAL (Sun & Saenko 2016)
# p2.fit_rpa(X_stream, trim_windows=...)
# p2.fit_affine(X_stream, y_stream)  # supervised L2 ridge toward identity
```

Or pass a stream at fit time when supported: `fit(..., X_stream=...)`. EMA-damped label-free CORAL refits use `ema_beta=` on supported paths.

| Transform | Intent |
| - | - |
| `standardize` | Per-dimension mean/std from calibration |
| `whiten` | Decorrelate + unit variance from calibration |
| `euclidean_alignment` | EA-style recentering in embedding space |
| `coral` | Align second-order statistics to a target distribution |
| `rpa` | Re-centering with optional `trim_windows=` robustness |
| `affine` | Supervised affine map; ridge toward identity |

Public types: `StandardizeTransform`, `WhitenTransform`, `CoralTransform`, `RpaTransform`, `EuclideanAlignment` (also importable from `nimbus_bci`).

> [!WARNING]
>
> Prefer **no transform** (or cal-fitted only) for deployment. Treat `coral` / `rpa` / `affine` as research / offline alignment — they are not the product default.

## Trunk adaptation (BaLoRA and PEFT arms)

Install:

```bash theme={null}
pip install nimbus-bci[train]   # torch >= 2.14
```

Bayesian LoRA on the trunk with composed trunk+head BALD sampling:

```python theme={null}
from nimbus_bci import Personalizer, Recipe, MCSamplingConfig

# Auto-wraps a raw torch trunk (rank=4 default)
p = Personalizer.for_balora(torch_model, ["left", "right"], rank=4)
p.fit(X_cal, y_cal)
# Escalate trunk adaptation when your protocol calls for it:
# p.adapt_trunk(...)  # see API / AdaptArm registry

# Or Recipe.BALORA_COMPOSED / MCSamplingConfig.balora() presets:
# MCSamplingConfig.balora(n_trunk=8, n_head=32)
# MCSamplingConfig.balora_fast() / .balora_standard()
```

`mc_samples=(n_trunk, n_head)` marginalises over the BaLoRA alpha-posterior and the Bayesian head.

| Tool | Role |
| - | - |
| `wrap_lora` | LoRA on Linear + Conv2d |
| FiLM rung | Feature-wise linear modulation arm |
| `AdaptArm` registry | Named arms with measured cost estimates |
| `Personalizer.for_lora(...)` | Convenience factory when the trunk already has / needs LoRA |

```python theme={null}
from nimbus_bci.middleware.adapters.lora import wrap_lora
from nimbus_bci import Personalizer, available_arms

enc = wrap_lora(torch_model, ...)
p = Personalizer.for_research(enc, ["left", "right"])
print(available_arms())  # cost estimates for trainer arms
```

Trainer arms accept hyperparameter overrides. Prefer measuring cost on your hardware before comparing to head-only `partial_fit`.

## Other research-only mechanisms

| API | Role | Notes |
| - | - | - |
| `adapt_pseudo` | Gated self-training on an unlabeled stream | Hardened in 0.8: entropy ceiling ($0.60 \log_2 K$), epistemic ($0.45$), `max_pseudo_updates=200` cap |
| `fit_tent` | Entropy minimization over trunk norm affine params | Unsupervised normalization adaptation |
| `T3APrototypeChannel` | Optimization-free recalibration on verified labels | Prototype recalibration |
| `adapt_errp` | Soft-negative conjugate update from an external ErrP probability | Soft-label error updates |
| `fit_population` | Warm-start from pooled LOSO posteriors + prior-predictive gate | Population initialization |

> [!WARNING]
>
> **`adapt_pseudo` fails closed.** It enforces an entropy ceiling ($0.60 \cdot \log_2 K$ bits) and a normalized epistemic floor ($0.45$), plus a cumulative session cap of 200 accepted updates. Models without Monte Carlo sampling lack epistemic scores and **fail closed** by raising `AdaptationRefusedError`. Enable `mc=MCSamplingConfig.head_only(...)` or pass `epistemic=1.0` if running unguided experiments.

## Next read

> [card] [Online Safety Layer](https://docs.nimbusbci.com/personalizer/safety.md)
>
> Govern online adaptation with budgets and monitors.

> [card] [Paradigms & profiles](https://docs.nimbusbci.com/personalizer/paradigms.md)
>
> MI / P300 recipes and day-2 profiles.

> [card] [Changelog](https://docs.nimbusbci.com/python-sdk/changelog.md)
>
> The 0.8 hardening of `adapt_pseudo`, and the 0.6 preset renames.

> [card] [API Reference](https://docs.nimbusbci.com/python-sdk/api-reference.md)
>
> Personalizer methods and configs.


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