Skip to main content

Nimbus BCI: Bayesian classifiers for brain-computer interfaces

Project description

nimbus-bci

Bayesian BCI classifiers with sklearn compatibility, streaming inference, and rich diagnostics.

PyPI Python License

Features

  • Three Bayesian classifiers: LDA, QDA, and Softmax (Polya-Gamma)
  • Structural Time Series classifier (NimbusSTS): Latent-state dynamics with EKF-style updates (experimental)
  • sklearn-compatible API: Works with pipelines, cross-validation, and GridSearchCV
  • Streaming inference: Real-time chunk-by-chunk processing
  • Rich diagnostics: Entropy, Mahalanobis distance, calibration metrics (ECE/MCE)
  • Online learning: Update models with new data without retraining
  • BCI-specific utilities: ITR calculation, temporal aggregation, quality assessment
  • MNE-Python integration: Convert between MNE Epochs and Nimbus data formats

Installation

pip install nimbus-bci

To use the optional JAX-based softmax model:

pip install nimbus-bci[softmax]

From source:

git clone https://github.com/nimbusbci/nimbuspysdk.git
cd nimbuspysdk
pip install -e ".[all]"

Quick Start

sklearn-Compatible API (Recommended)

from nimbus_bci import NimbusLDA, NimbusQDA, NimbusSoftmax, NimbusSTS
import numpy as np

# Create and fit classifier
clf = NimbusLDA()
clf.fit(X_train, y_train)

# Predict
predictions = clf.predict(X_test)
probabilities = clf.predict_proba(X_test)

# Online learning
clf.partial_fit(X_new, y_new)

Works with sklearn Pipelines

from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import cross_val_score, GridSearchCV

# Simple pipeline
pipe = make_pipeline(StandardScaler(), NimbusLDA())
pipe.fit(X_train, y_train)

# Cross-validation
scores = cross_val_score(NimbusLDA(), X, y, cv=5)
print(f"Accuracy: {scores.mean():.2%} (+/- {scores.std():.2%})")

# Hyperparameter tuning
param_grid = {'mu_scale': [1.0, 3.0, 5.0], 'class_prior_alpha': [0.5, 1.0]}
grid = GridSearchCV(NimbusLDA(), param_grid, cv=5)
grid.fit(X, y)
print(f"Best params: {grid.best_params_}")

Streaming Inference (Real-Time BCI)

from nimbus_bci import NimbusLDA, StreamingSession
from nimbus_bci.data import BCIMetadata

# Setup
metadata = BCIMetadata(
    sampling_rate=250.0,
    paradigm="motor_imagery",
    feature_type="csp",
    n_features=16,
    n_classes=4,
    chunk_size=125,  # 500ms chunks
    temporal_aggregation="logvar",
)

# Train model
clf = NimbusLDA()
clf.fit(X_train, y_train)

# Create streaming session
session = StreamingSession(clf.model_, metadata)

# Process chunks in real-time
for chunk in eeg_stream:
    result = session.process_chunk(chunk)
    print(f"Chunk prediction: {result.prediction} ({result.confidence:.2%})")

# Finalize trial with aggregation
final = session.finalize_trial(method="weighted_vote")
print(f"Final: class {final.prediction} (entropy: {final.entropy:.2f} bits)")

For NimbusSTS specifically (stateful latent dynamics), use StreamingSessionSTS so the latent state can be propagated and updated with delayed feedback:

from nimbus_bci import NimbusSTS
from nimbus_bci.inference import StreamingSessionSTS
from nimbus_bci.data import BCIMetadata

metadata = BCIMetadata(
    sampling_rate=250.0,
    paradigm="motor_imagery",
    feature_type="csp",
    n_features=16,
    n_classes=2,
    chunk_size=125,
    temporal_aggregation="mean",
)

clf = NimbusSTS().fit(X_train, y_train)
session = StreamingSessionSTS(clf, metadata)

result = session.process_chunk(chunk)  # propagates state by default
session.provide_feedback(label=0)      # when label arrives later

Batch Inference with Diagnostics

from nimbus_bci import predict_batch
from nimbus_bci.data import BCIData, BCIMetadata

# Create BCI data container
metadata = BCIMetadata(
    sampling_rate=250.0,
    paradigm="motor_imagery",
    feature_type="csp",
    n_features=16,
    n_classes=4,
)
data = BCIData(features, metadata, labels)

# Run batch inference with full diagnostics
result = predict_batch(model, data)

print(f"Mean entropy: {result.mean_entropy:.2f} bits")
print(f"Balance: {result.balance:.2%}")
print(f"ECE: {result.calibration.ece:.3f}")
print(f"Latency: {result.latency_ms:.1f}ms")

MNE-Python Integration

import mne
from nimbus_bci import NimbusLDA
from nimbus_bci.compat import from_mne_epochs, extract_csp_features

# Load and preprocess with MNE
raw = mne.io.read_raw_gdf("motor_imagery.gdf")
events = mne.find_events(raw)
epochs = mne.Epochs(raw, events, tmin=0, tmax=4, baseline=None, preload=True)
epochs.filter(8, 30)  # Mu + Beta bands

# Extract CSP features
csp_features, csp = extract_csp_features(epochs, n_components=8)

# Train Nimbus classifier
clf = NimbusLDA()
clf.fit(csp_features, epochs.events[:, 2])

Available Classifiers

Classifier Description Best For
NimbusLDA Bayesian LDA with shared covariance Fast, when classes have similar shapes
NimbusQDA Bayesian QDA with class-specific covariances Complex class distributions
NimbusSoftmax Bayesian logistic regression (Polya-Gamma VI) Non-Gaussian decision boundaries
NimbusSTS Structural time series classifier (latent state + EKF-style inference) Non-stationary settings, drifting class boundaries (experimental)

Choosing the Right Classifier

Quick Decision Guide

Is your data stationary (distributions don't change over time)?

  • Yes → Use static models (LDA/GMM/Softmax)
  • No → Use NimbusSTS for temporal adaptation

For stationary data:

  • Classes have similar covariance?NimbusLDA (fastest)
  • Classes have different shapes?NimbusQDA
  • Non-Gaussian boundaries?NimbusSoftmax

For non-stationary data:

  • Gradual drift (fatigue, electrode shift)?NimbusSTS
  • Multi-day sessions with state transfer?NimbusSTS
  • Delayed feedback paradigms?NimbusSTS

Detailed Comparison

Scenario Recommended Model Why?
Stable offline datasets NimbusLDA Fastest, closed-form solution
P300 spelling (stable) NimbusLDA or NimbusQDA Event-related, stationary
SSVEP NimbusLDA Highly stationary frequency response
Motor Imagery (short sessions) NimbusLDA or NimbusQDA Stationary within session
Motor Imagery (long sessions, fatigue) NimbusSTS Tracks drift due to fatigue
Multi-day experiments NimbusSTS State transfer across sessions
Electrode repositioning NimbusSTS Adapts to impedance changes
Closed-loop with delayed feedback NimbusSTS Explicit state propagation
Asynchronous BCI (idle vs active) NimbusSTS Models engagement state
Neurofeedback training NimbusSTS Tracks learning-induced changes

NimbusSTS Example (Temporal Adaptation)

from nimbus_bci import NimbusSTS

# Train on calibration data
clf = NimbusSTS(transition_cov=0.05, num_steps=50)
clf.fit(X_calibration, y_calibration)

# Online session with delayed feedback
for x_trial, y_feedback in online_trials:
    # 1. Propagate state forward (no label needed)
    clf.propagate_state()
    
    # 2. Make prediction
    prediction = clf.predict(x_trial)
    
    # ... user performs action, feedback arrives later ...
    
    # 3. Update with true label
    clf.partial_fit(x_trial, y_feedback)

# Multi-day state transfer
z_day1, P_day1 = clf.get_latent_state()

# Day 2: Initialize with Day 1 state (increased uncertainty)
clf_day2 = NimbusSTS()
clf_day2.fit(X_day2_calib, y_day2_calib)
clf_day2.set_latent_state(z_day1 * 0.5, P_day1 * 2.0)

Label Conventions (Important)

Nimbus supports common EEG/BCI labeling patterns:

  • BCIData labels: can be any non-negative integer codes (e.g., MNE event IDs like 769/770), as long as the number of unique labels does not exceed BCIMetadata.n_classes.
  • sklearn estimators (NimbusLDA, NimbusQDA, NimbusSoftmax, NimbusSTS):
    • fit() learns classes_ from your provided labels.
    • predict() returns labels in the original label space (elements of classes_).
  • Model-snapshot inference (NimbusModel + predict_batch / StreamingSession):
    • predictions are returned in the model’s label_base convention (label_base is stored in model.params).
    • use nimbus_bci.data.labels_to_zero_indexed(...) for metrics/aggregation that require 0-indexed labels.

NimbusSTS Sequence Semantics (Important)

NimbusSTS has a latent state. For correctness and sklearn compatibility:

  • NimbusSTS.predict_proba(X) treats rows as conditionally independent by default.
  • For time-ordered evaluation, propagate explicitly:
    • call clf.propagate_state() between trials/chunks, or
    • use the functional API nimbus_sts_predict_proba(model, X, evolve_state=True) when X rows are ordered in time.

Metrics & Diagnostics

from nimbus_bci import (
    compute_entropy,            # Prediction uncertainty
    compute_calibration_metrics,  # ECE, MCE
    calculate_itr,              # Information Transfer Rate
    assess_trial_quality,       # Quality checks
)

# Entropy (uncertainty)
entropy = compute_entropy(posterior)  # bits

# Calibration
calib = compute_calibration_metrics(predictions, confidences, labels)
print(f"ECE: {calib.ece:.3f}, MCE: {calib.mce:.3f}")

# ITR
itr = calculate_itr(accuracy=0.85, n_classes=4, trial_duration=4.0)
print(f"ITR: {itr:.1f} bits/min")

Normalization

Critical for cross-session BCI performance:

from nimbus_bci import estimate_normalization_params, apply_normalization

# Estimate from training data
params = estimate_normalization_params(X_train, method="zscore")

# Apply to all data
X_train_norm = apply_normalization(X_train, params)
X_test_norm = apply_normalization(X_test, params)  # Same params!

Project Structure

nimbus_bci/
├── models/              # Classifiers
│   ├── nimbus_lda/     # LDA (shared covariance)
│   ├── nimbus_qda/     # QDA (class-specific covariances)
│   └── nimbus_softmax/ # Softmax (Polya-Gamma)
├── data/               # Data contracts (BCIData, BCIMetadata)
├── inference/          # Batch and streaming inference
├── metrics/            # Diagnostics, calibration, ITR
├── utils/              # Normalization, aggregation
└── compat/             # sklearn/MNE compatibility

Functional API (Backward Compatible)

The original functional API is still available:

from nimbus_bci import (
    nimbus_lda_fit, nimbus_lda_predict, nimbus_lda_update,
    nimbus_qda_fit, nimbus_qda_predict,
    nimbus_softmax_fit, nimbus_softmax_predict,
    nimbus_save, nimbus_load,
)

# Fit model
model = nimbus_lda_fit(X, y, n_classes=4, label_base=0, ...)

# Predict
probs = nimbus_lda_predict_proba(model, X_test)

# Update (online learning)
model = nimbus_lda_update(model, X_new, y_new)

# Save/load
nimbus_save(model, "model.npz")
model = nimbus_load("model.npz")

Testing

pip install -e ".[dev]"
pytest -v

Requirements

  • Python ≥ 3.10
  • NumPy ≥ 1.26
  • JAX ≥ 0.4.25
  • NumPyro ≥ 0.14.0
  • scikit-learn ≥ 1.4

Optional:

  • MNE ≥ 1.6 (for EEG integration)
  • matplotlib ≥ 3.8 (for visualization)

License

This software is proprietary and requires a valid license for use.

License Tiers

Tier Use Case
Evaluation 30-day free trial for R&D
Academic University research (free)
Startup Companies < $1M revenue
Commercial Full production rights
Enterprise Unlimited deployments + SLA
OEM/Embedded Medical devices, FDA support

Request Access

To obtain a license:

  1. Email hello@nimbusbci.com with your use case
  2. Receive API key and license agreement
  3. Install and start building

Website: https://nimbusbci.com


© 2024-2025 Nimbus BCI Inc. — The AI Engine for Brain-Computer Interfaces

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nimbus_bci-0.3.0.tar.gz (95.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

nimbus_bci-0.3.0-cp312-cp312-win_amd64.whl (442.7 kB view details)

Uploaded CPython 3.12Windows x86-64

nimbus_bci-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

nimbus_bci-0.3.0-cp312-cp312-macosx_11_0_arm64.whl (492.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

nimbus_bci-0.3.0-cp312-cp312-macosx_10_9_x86_64.whl (506.4 kB view details)

Uploaded CPython 3.12macOS 10.9+ x86-64

nimbus_bci-0.3.0-cp311-cp311-win_amd64.whl (465.6 kB view details)

Uploaded CPython 3.11Windows x86-64

nimbus_bci-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

nimbus_bci-0.3.0-cp311-cp311-macosx_11_0_arm64.whl (501.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

nimbus_bci-0.3.0-cp311-cp311-macosx_10_9_x86_64.whl (537.0 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

nimbus_bci-0.3.0-cp310-cp310-win_amd64.whl (464.9 kB view details)

Uploaded CPython 3.10Windows x86-64

nimbus_bci-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

nimbus_bci-0.3.0-cp310-cp310-macosx_11_0_arm64.whl (506.9 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

nimbus_bci-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl (545.0 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

Details for the file nimbus_bci-0.3.0.tar.gz.

File metadata

  • Download URL: nimbus_bci-0.3.0.tar.gz
  • Upload date:
  • Size: 95.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nimbus_bci-0.3.0.tar.gz
Algorithm Hash digest
SHA256 69329e7e27687e5d8d9c92772095081b9f76d35012d8bc5efb2b8724a4b44d61
MD5 35d21f4ac9c85069aef2cd1c34b1fed3
BLAKE2b-256 aff55736b1300154fb81da74c3c2d3f6b460c5c71f50bba059af427abb6897ad

See more details on using hashes here.

File details

Details for the file nimbus_bci-0.3.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: nimbus_bci-0.3.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 442.7 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nimbus_bci-0.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8b2c61b37cf876b959cbd36b6c4ccc595e024e4e96b593f13d9e7379cd6020df
MD5 04cdae8ed01539855c78c05e698eb04b
BLAKE2b-256 5df632fc63c3c49267763e6b297149e73604a98895d4920c86ab15e8b14807fa

See more details on using hashes here.

File details

Details for the file nimbus_bci-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nimbus_bci-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6492c6257ae35cd6075265467dd9890544a0876ef8d0bd87fe3ebff2d9801043
MD5 8604b110c55ffecc959c5ea5f3ff262f
BLAKE2b-256 920618717f6d0e92de2dcd447f58f1000a016d1c47c9210850a2cdd21936bc54

See more details on using hashes here.

File details

Details for the file nimbus_bci-0.3.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nimbus_bci-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7d83a580d740e3c50b6902440261b1c6398fcdff21caedafcfba30d032d8dffa
MD5 6bfbb773da36537835401c8a83edd16f
BLAKE2b-256 75317f018ce322f9df02267e4b277eb51511992edfe7d31a3be31757b8a1cd0f

See more details on using hashes here.

File details

Details for the file nimbus_bci-0.3.0-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for nimbus_bci-0.3.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 21bb2817278384d2c6a0d133d59a2db361ff0916d238088674f6d7087a5377a2
MD5 3b51d55c2665e207079cb396fa49630d
BLAKE2b-256 787d33a538ce311696ca9545850aa30d70cbc90bd4e987ab032cfd34da6fbbc9

See more details on using hashes here.

File details

Details for the file nimbus_bci-0.3.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: nimbus_bci-0.3.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 465.6 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nimbus_bci-0.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3383b0e54d76aac6b4cd20d2da92c3c244c96a3eee33c4895f88e430ca191ab3
MD5 e0ff49f28d2bd2314d20d97bf0b4fea1
BLAKE2b-256 67cb43e5597b3963fc1da06fe28d0e8b7e0da65294b20a654f592eb65ae3fe18

See more details on using hashes here.

File details

Details for the file nimbus_bci-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nimbus_bci-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5e5627bc4ea5f0673bb94c61e7698df2fff12c9e8a9d04ed3b3c69312385f6c9
MD5 34ac282e2c44415c1ce63c3e86394218
BLAKE2b-256 4fb43ca0b0434fe3b7afb2f0dd600c9031222ebd4a3a055235c0886b8b69de4e

See more details on using hashes here.

File details

Details for the file nimbus_bci-0.3.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nimbus_bci-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e64fbd740f7a77b73b883fb280831ec051f5e0cca11e34d7a3fcb9476995b0f3
MD5 fd7212494d9c43a794d51e09ec8e92b6
BLAKE2b-256 4174e85687073faad1ab238f0b6c3578cf2f2864a11f11a2b3a86c119319aa07

See more details on using hashes here.

File details

Details for the file nimbus_bci-0.3.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for nimbus_bci-0.3.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5c5f7b609919051513be60a5e825f3a4d2b2a577bf071d9e5db6612cfa4b74b3
MD5 bb1c5ec2e0445da51c339a4e0272d3b8
BLAKE2b-256 2e567a77b53dd99370953ce85eaf4c988e34a363778fdf3036b921776f4ce63b

See more details on using hashes here.

File details

Details for the file nimbus_bci-0.3.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: nimbus_bci-0.3.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 464.9 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nimbus_bci-0.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 aac4d7826a449123dff1f5493926de9a7b51366741d26285b41d86f142be3fca
MD5 793a29863a33518f57ba81859aa001ed
BLAKE2b-256 11eadd9d11fe3afcb36fea42d54454bd885987e5c2d0c1c0f5efa1565401de7f

See more details on using hashes here.

File details

Details for the file nimbus_bci-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nimbus_bci-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0a46613372f89c8f777128447370e43deb663cb00cb67ed4e7bb3540a93275e5
MD5 28098562ff3e9eb7c04fae323fbd090e
BLAKE2b-256 520d61fb68a75f7b56f56a5c3482e0235eb109d5332aba39bb73f2adab0cefa2

See more details on using hashes here.

File details

Details for the file nimbus_bci-0.3.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nimbus_bci-0.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cd0c7cfe326b6a29f40ff5ab1e9e12d2dde298bdcef226870cfb3dbd0becea23
MD5 c824fd964c3878af2ac217df1e296348
BLAKE2b-256 bb1fc3635fd7ebec0386f006f1dc585af5846344a8c5f438e5839b05f193384e

See more details on using hashes here.

File details

Details for the file nimbus_bci-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for nimbus_bci-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2fefbca4eb863be957299ade2d89a82610de987a9b728188d6e7c1cc038b122a
MD5 46f78ff01b93328c25d93de376b74a1e
BLAKE2b-256 7887a0b341f8608add24be23a79f0e32926de5386056a603a0284310d9673ee1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page