Skip to main content

Dense-Armor — Robot-AI Online Shielding & Learning

tests codecov pypi DOI license python vision robot control backend nan docs

Robot-AI Online Shielding & Learning

A library for online learning on robot, vision, and AI streams, one sample at a time, with streaming statistics and protection, drift and anomaly detection, and safe robot commands.

📖 Full documentation, API reference, quick guide →


Who is this for

Python developers working on systems where data arrives one sample at a time and the model has to learn or stay stable while it runs: robot control loops, sensor pipelines, agent runtimes, any streaming workload. If you train on a fixed dataset and then deploy, this library is probably not what you need.

Use cases

The primitives are domain-agnostic: anything that ingests data one sample at a time and has to react when the stream changes. It has been measured on a robot arm (CASPER on a UR3e), on stock and crypto prices, card transactions, network flows and a telemarketing log (the finance pages), and on synthetic streams with known drift; the layers above and below the model are the same shape everywhere.

domain what Dense-Armor brings
Robot control loops bounded commands (rate limits, CBF), drift and anomaly on joint streams, calibrated intervals
Deployed ML models input drift detection, runtime shielding of NaN and spikes, no retraining required
Antivirus / security event stream statistics, behavioural drift, anomaly scoring one event at a time
Fraud detection per-transaction scoring, drift on the user profile, streaming statistics
Search / ranking monitoring layer around the ranker: drift on user behaviour, streaming metrics
Live monitoring Prometheus-style metrics with drift detection, sketches, quantiles in constant memory
IoT / sensor fusion the same shape as a robot joint: noisy multichannel input, drift, anomalies, shields

What it expects from you

No specific model. Any estimator that follows the same contract: learn_one(x, y) updates the model from one sample, predict_one(x) returns a prediction, transform_one(x) returns a transform or a residual, score_one(x) returns an anomaly score (high = anomalous), update(x) advances a drift detector. Inputs and outputs are dicts of numpy-compatible scalars or arrays. Runs on CPU or GPU through JAX. A shield can wrap any callable from tensor to tensor.

What changes when you use it

  • The model keeps learning even when the stream has NaN, spikes, or missing samples — they are cleaned before the model sees them, and every correction reports how far it moved.
  • Concept drift is caught by an explicit detector instead of silently degrading accuracy.
  • Anomalies come back as a score, one sample at a time.
  • Robot commands are bounded (rate limits, control barrier functions) before they reach the actuator.
  • Predictions can carry a calibrated uncertainty interval.

In this library, shielding means cleaning the data a model sees (NaN, spikes, anomalous samples) and bounding the commands a robot receives, around any online learner that follows the learn_one / score_one contract. It is not the formal shield of safe reinforcement learning.

What it does

Dense-Armor is a Python library for online learning. Every estimator learns one sample at a time, at control-loop speed, on JAX: nothing is retrained in batch, nothing revisits the past. The same learn_one / predict_one / transform_one contract runs on a table, a time series, a robot joint stream, a video frame, a token stream, and a shield can sit in front of any of them.


Quickstart

As a quick example, we'll train an online Gaussian naive Bayes classifier to classify a drift stream with 5 features and one sudden concept change. Here's a look at the first observation in the dataset.

>>> from dense_armor.utility.datasets import DriftStream

>>> dataset = DriftStream(n_samples=2000, n_features=5, n_drifts=1, kind="sudden", seed=0)

>>> for x, y in dataset.stream():
...     print(x.to_dict())
...     print(y)
...     break
{'x0': 0.00889176732883129, 'x1': 0.7559062648510446, 'x2': -2.788269695138754, 'x3': 0.0168051027297742, 'x4': 1.9630566360240487}
0

Now let's run the model on the dataset in a streaming fashion. We sequentially interleave predictions and model updates. Meanwhile, we update a performance metric to see how well the model is doing.

>>> from dense_armor.utility.learn.online_classifiers import OnlineGaussianNB
>>> from dense_armor.utility.metrics import Accuracy

>>> model = OnlineGaussianNB()

>>> metric = Accuracy()

>>> for x, y in dataset.stream():
...     y_pred = model.predict_one(x)
...     if y_pred is not None:
...         metric.update(y, y_pred)
...     model.learn_one(x, y)

>>> metric
Accuracy(n=1999, value=0.9989994997498749)

Of course, this is just a contrived example. Check the getting started section of the documentation for a more thorough tutorial.


On a robot

A joint torque stream from SyntheticArm (real Panda URDF, real rigid-body dynamics) carries a 1e6 spike at sample 50. A rate-limited follower caps the applied jump at max_vel per step, so a downstream controller never sees the spike:

from pathlib import Path
import numpy as np
from dense_armor.utility.datasets import SyntheticArm
from dense_armor.utility.control.rate_limiter import rate_limited_follower

ds = SyntheticArm(
    Path("test/fixtures/urdf/panda.urdf"),
    period_s=1.0, rate_hz=50.0, n_cycles=2,
    fault_at_s=None, fault=None, seed=0,
)
tau = np.array([float(sig["tau_1"]) for sig, _ in ds.stream()])
tau[50] = 1e6

safe = rate_limited_follower(tau, max_vel=2.0, max_accel=1.0)
print(round(float(np.max(np.abs(tau))), 1), round(float(np.max(np.abs(safe))), 1))
1000000.0 272.2

RigidBodyModel loads dynamics from the same URDF (.xacro and <mimic> joints included), quintic_trajectory generates a minimum-jerk path, and cbf_safety_filter enforces a spatial barrier around an obstacle.


Install

pip install dense-armor                 # core: numpy + jax
pip install "dense-armor[vision]"       # + OpenCV frame readers
pip install "dense-armor[ros]"          # + rosbag readers
pip install "dense-armor[audio,data]"   # + WAV, HDF5, NetCDF
pip install "dense-armor[mcp]"          # + MCP server for LLM agents
pip install "dense-armor[quantum]"      # + Dense-Evolution (NISQ simulator)

Works on Python 3.10+. JAX is the backend for every estimator.


Features

Dense-Armor provides online implementations of the following families of algorithms:

  • Linear models, with a wide array of optimizers
  • Decision trees, online forests (adaptive random forest, aggregated Mondrian forests, online extra trees) and rule sets (adaptive model rules)
  • Naive Bayes, nearest neighbours, multiclass and multi-output wrappers, conjugate distributions
  • Clustering
  • Anomaly detection (including the local outlier factor)
  • Drift detection
  • Time series (AR, VAR, Kalman, adaptive Kalman, cycle residual)
  • Online classifiers
  • Online dynamics
  • Calibration and metric learning
  • Imbalanced learning
  • Vision (frame features, patches, vocabulary, online reduction)
  • Robot control (rate limits, control barrier functions, trajectories, kinematic tracking)
  • Robot dynamics (URDF, passivity + CBF controllers)
  • Shielding (1D series cleanup, input/output shield, per-point routing)
  • Finance pipelines: nine pipelines for markets, fraud, intrusion and credit scoring, each page opening with the question it answers

Dense-Armor also provides other online utilities:

  • Feature extraction and selection
  • Online statistics and sketches
  • Metrics for streams and robots
  • Preprocessing
  • Streams (CSV, arrays, rosbag, frame folders, merge by time, shuffle)
  • Built-in datasets
  • Progressive model validation
  • Model pipelines
  • LLM bridge (embeddings as features, estimators as JSON tools)
  • Checks (check_estimator, p99 budget, memory growth, clone, pickle, state dict, roc_auc)
  • Core engine (DynamicAICodegen JIT compiler, ImageChunker, UniversalMemoryGuard, AdaptiveSignalStabilizer, AIHardwareProfiler, StochasticAdversarialNoise)

Check out the API for a comprehensive overview.


Should I be using Dense-Armor?

The answer is probably no. Most of the time, batch learning does the job just fine. An online approach fits when:

  • you want a model that learns from new data without revisiting past data
  • you want a model that is robust to concept drift
  • the production context is event-based, not batch-based, and you want the code to look like it
  • you want the model to be protected from corrupted input, NaN, spikes, or slow drift without retraining it
  • you work with a real robot and need command-side safety in the same library that learns the model

Some specifics:

  • It focuses on clarity and user experience, more than on raw speed.
  • It runs on JAX, so the same code runs on CPU, GPU or TPU.
  • It plays nicely with the rest of Python's ecosystem: numpy in, numpy out.


Contributing

Contributions are welcome. The library is built to be extended one estimator at a time, following the same interface (learn_one / predict_one / transform_one) and the same checks (dense_armor.checks).


Citation

@software{pennacchio_dense_armor,
  author    = {Pennacchio, Salvatore},
  title     = {Dense-Armor: Robot-AI Online Shielding \\& Learning},
  year      = 2026,
  publisher = {Zenodo},
  doi       = {10.5281/zenodo.23340608}
}

License

Business Source License 1.1 — free non-commercial use, converts to Apache 2.0 on 2029-06-01. See LICENSE.md.

© 2026 Salvatore Pennacchio <jtatopenn@libero.it>

Twin project of Dense-Evolution (NISQ quantum circuit simulator).

Metadata

Release files for dense-armor 1.1.28

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dense-armor 1.1.28
File Size Uploaded
dense_armor-1.1.28.tar.gz 379.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dense-armor 1.1.28
File Interpreter ABI Platform
dense_armor-1.1.28-py3-none-any.whl Python 3 none any Details

Total release size: 854.5 kB

Release files / dense_armor-1.1.28.tar.gz

Download URL dense_armor-1.1.28.tar.gz
Size 379.1 kB
Tags Source
SHA-256 checksum
How to use checksums
eca5454c57d0ef24b0e6c9e6fe709ed74ad10d2526115908839477393b4e736f
BLAKE2b-256 checksum
How to use checksums
dc9981b4b8458d6ae2ec1552ce226556f2f32d606b46ff34853fa61acdf3b042
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / dense_armor-1.1.28-py3-none-any.whl

Download URL dense_armor-1.1.28-py3-none-any.whl
Size 475.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
afcf0aa92832162051286d747e332858805f9c5065837382dc08c40ae670edb4
BLAKE2b-256 checksum
How to use checksums
1587df2e4c07be3121aa7e92dd0a0a06c530c6ea55e03470b54886d9deea5a61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page