← Projects · Research

ddma: data-driven models and abstractions

Safe controllers learned from data. An open-source library that turns logged sensor data into a model with guaranteed error bounds, for monotone systems and for any system with bounded derivatives, then into a safety filter that keeps any controller, including a learned one, inside its limits. Python and MATLAB on one C++ core.

Safety filter · Data-driven control · Online learning · C++ · Python · MATLAB

Code on GitHub →Stack: C++17 · OpenMP · Python · NumPy · SciPy / HiGHS · pybind11 · MATLAB / MEX · Octave · pytest · GitHub Actions · matplotlib

10⁸measurements processed in one run
0.3 sto learn a model from 10 million measurements
0safety violations in every closed-loop test
490+automated tests, Python and MATLAB checked against each other

The guaranteed band of an unknown monotone function tightening as samples arrive

An unknown increasing function, measured with bounded noise: the band ddma computes tightens as data arrives and always contains the true outputs.

What it does

You have a machine whose dynamics you only partly know, plenty of logged data, and hard limits it must never cross. ddma gives you a controller that is proven to respect those limits, built from the data alone:

  1. Logged dataMeasured transitions (state, input → next state), noisy and unevenly spread.
  2. Model with error boundsThe tightest set of possible behaviours consistent with the data. The real system is guaranteed to be inside it.
  3. Safe operating regionThe largest set of states from which the limits can always be kept, whatever the disturbance does.
  4. Safety filterWraps any controller (PID, MPC, an RL policy). It passes commands through and corrects only those that would lead out of the safe region.

The safe region can also be computed without any grid, straight from the measurements: a few hundred to a thousand transitions are often enough (see Safe operating envelopes straight from data).

No neural network or model class is fitted. You only state one property of the unknown dynamics:

  • Monotone: more input or a larger state gives a larger next state. That holds for many vehicle, thermal, traffic and process-control systems.
  • Bounded derivatives: each output changes at most so fast with each variable. That holds for almost any physical system (a pendulum, a robot arm), and the bounds can also be estimated from data. Five model types trade tightness against speed, from a fast default to a tightest variant with certified linear programs.

The model can also be refined while the system runs: new measurements update only the nearby part of the model, and the safe operating region is updated without starting over; it can only grow.

And if a stated property turns out to be wrong, ddma notices. Before learning, it checks every pair of logged measurements against the stated properties and points to corrupted readings. While the system runs, it checks each new measurement against the model and against all earlier ones, in well under a millisecond. Every alarm is a proof, not a heuristic. It also says which property is wrong and by how much, and responds: an alarm, a relearned model with wider bounds, or a switch to a backup controller when the change is too large.

Get it

ddma is open source (MIT) and comes as ready-to-install packages for Linux, Windows and macOS:

pip install ddma

For MATLAB (R2023b or newer), download the toolbox file (.mltbx) from the releases page and open it in MATLAB.

Documentation and tutorials: seven step-by-step tutorials, each in Python and MATLAB, from a first model to the safety filter and the assumption monitor, plus the full API reference.

Demo: a cruise-control safety filter learned from data

A following car must keep a 10–50 m gap to a leader that speeds up and slows down at will. The car’s own speed dynamics (drag, actuator) are not given to the method, only logged data. A naive cruise controller that ignores the leader is wrapped in the learned safety filter.

Without the filter the car crashes after 11.5 s. With it, the gap never drops below 11 m over 200 s. The whole pipeline, from 200,000 measurements to a working filter, runs in under 0.2 s.

Closed loop with and without the safety filter

More data gives a larger certified operating region:

Measurements Certified safe region Learn model Build abstraction Compute safe set
2,000 26.7 % 0.002 s 0.05 s 0.07 s
20,000 37.1 % 0.008 s 0.04 s 0.05 s
200,000 38.1 % 0.08 s 0.04 s 0.06 s

Certified safe region against amount of data

Demo: when the stated properties break

The same cruise-control filter, but at t = 75 s the world changes. The 200,000 logged measurements first pass the check of all 2·10¹⁰ pairs in a few seconds.

  • The leader slows to 11 m/s, below the 13 m/s the model assumed. The monitor flags it in the same step and finds that only the leader’s speed range can explain it. The change is small, so the bound is widened and the filter relearned: 3 steps outside the limits instead of 54.
  • A trailer is hitched (30 % of the acceleration, twice the drag). The monitor flags it in the same step. Explaining it would need three times the assumed noise, beyond the allowed limit, so the car switches to a backup controller: 0 steps outside the limits instead of 6.

Assumptions broken mid-run: alarm and response

Demo: an inverted pendulum, which is not monotone

Keeping a pendulum upright with limited torque: its dynamics turn around at 90°, so the monotone methods don’t apply. Only bounds on the derivatives are given; the model is learned from 10⁶ logged transitions on a 101 × 101 grid.

Every one of the five models gives a controller with 0 violations in 100 closed-loop runs on the true pendulum. The tighter models certify a larger operating region:

Certified safe region of the inverted pendulum, learned from data

Model Learn model Certified safe region
Two matrices (default) 0.2 s 16.1 %
Growth cones (can be updated online) 0.2 s 17.6 %
Growth cones + linear programs (tightest) 26 s 17.8 %

Building the abstraction and computing the safe region take about 0.1 s for each model.

Demo: a learning agent that never crashes, even while it learns

Reinforcement-learning agents learn by trial and error, which on real hardware means crashes. ddma’s safety filter sits between any agent and the system: a safe action passes unchanged, an unsafe one is replaced by the nearest safe action. It works with any agent and any library (Gymnasium in Python; the Reinforcement Learning Toolbox’s environment interface in MATLAB).

On the cruise-control task (drive close to 22 m/s behind a leader whose speed changes; a crash or a lost leader ends the episode), a standard PPO agent crashed or lost the leader 266–319 times while it learned. Inside the filter, learned from logged data without the vehicle model, it had 0 violations in training and evaluation, and ended with a slightly higher return.

Constraint violations during training, with and without the safety filter

Algorithms and performance

The original research code was correct but slow: tens of minutes on the larger benchmarks. I rebuilt the core algorithms for speed and memory:

  • Learning the model in near-linear time. Each measurement is located in its grid cell (binary search, or direct indexing on uniform grids), then a single running min/max sweep per axis propagates the bounds across the grid. Cost: O(|K| log|Q| + |Q|) for |K| measurements and |Q| cells, against O(|K|·|Q|·|P|) in the earlier method. It runs in one fused pass in C++, with no temporary arrays.
  • Exact bounds for non-monotone systems in two sweeps. For the growth-cone models, the tightest bound at every grid vertex is computed exactly with one forward and one backward running min/max per axis, instead of an iterative fixed point; the per-cell refinement uses the same idea, so its cost does not depend on the grid’s size along an axis. Both run in the C++ core: about 0.3 s for 10 million measurements. The linear-programming variants solve all cells as one sparse LP and keep the bound certified by duality, so solver tolerances can never make the model unsound.
  • Online updates. New data refine the model by intersection, without revisiting old data. A single new measurement tightens a growth-cone model on the whole grid in about 0.1 ms (or only a window of cells around it); the abstraction and the safe region are then updated for the changed states only, with the same result as a full recomputation. Available in Python and MATLAB. My safe learning-based MPC package, compatible-mpc, uses these models while the robot drives.
  • Faster safe-set computation. Safety and reach-avoid fixed points run in the shared C++ core: each state keeps a pointer to its first input not yet ruled out, so every state–input pair is examined at most once. Successor checks use n-dimensional summed-area tables. On a 27-million-pair problem this cut synthesis from 49 s to 5 s.
  • Lazy abstractions. Transitions can be computed on demand instead of stored: states outside the safe region are never expanded, and memory stays proportional to the number of states. On a 3-room cooling example only 4.6 % of the transitions are evaluated.

Scaling of model learning with the number of measurements

Benchmark Original code ddma
Cruise control, model + 27 M-pair abstraction + safe set 1,264 s 12 s
Lorenz system, 10⁸ samples, 104 M cells 929 s 296 s
Learning from 10⁶ samples, 100 × 100 grid — 0.02 s (C++), 0.15 s (NumPy)

Engineering

  • One core, two languages, same results. A header-only C++ kernel serves Python (pybind11) and MATLAB/Octave (MEX). Every feature exists in both languages, from the models to the lazy synthesis and the online updates, and every MATLAB function is tested against a Python reference in CI; a feature counts as done only when both languages have it. Without a compiler, pure NumPy / MATLAB fallbacks give the same results.
  • Multithreaded learning and abstraction, same result on any number of threads. Learning the model and building the abstraction both use all cores (OpenMP). The learning kernels are cache-aware: data are grouped by block of the grid so writes stay in the processor cache, and because they only keep minima and maxima, which do not depend on the order of the writes, the result is bit-identical whatever the thread count. The abstraction kernel handles each state–input pair on its own, reading the learned bounds through small offset tables and finding successor cells in constant time, with exactly the arithmetic of the reference code: about half a second for 27 million pairs on one core. The tests check bit-identical results on Linux, macOS and Windows. Without OpenMP the same code runs on one thread.
  • A check of the assumptions that stays fast with millions of measurements. Each new measurement is compared with every stored one, exactly, yet only about a thousand comparisons are actually computed: the stored data are grouped in cells, and a cheap bound per cell rules out whole cells that cannot conflict. The bound uses the same floating-point operations as the exact check, so skipping a cell never changes the result. With 2 million stored measurements a check takes under a millisecond; points that fail are set aside so they cause no follow-up alarms.
  • Tests that check the guarantees, not just the outputs. On thousands of random systems: the true system always lies inside the learned model (soundness); the bounds cannot be tightened (minimality); the fast algorithms equal brute-force versions; C++, NumPy and MATLAB agree bit for bit; and the new code reproduces the original MATLAB research code exactly.
  • Closed-loop validation. Every controller is simulated on the true plant: 200 random starts × 300–500 steps with random disturbances. 0 violations.
  • CI and releases on GitHub Actions: the Python tests, and the MATLAB tests in Octave and in MATLAB R2023b. Every release builds pre-compiled packages for Linux, macOS and Windows and six Python versions, runs the whole test suite on each, and publishes them to PyPI and as a MATLAB toolbox. A documentation site whose tutorials are re-run on every change, CITATION.cff, and reproducible scripts for every figure.

Next

The gridless envelopes inside the safety filters, and richer specifications (reach-while-stay, recurrence).


For researchers: the method and the papers

ddma implements the minimal simulating maps of the TAC paper Data-Driven Models of Monotone Systems (with A. Girard and L. Fribourg) and the symbolic abstractions built on them (L4DC 2021, ADHS 2021). For a monotone map with bounded disturbance, the set-valued map built from the data is sound (it contains every monotone system consistent with the data) and minimal (no tighter sound map exists). On a rectangular partition, the per-cell upper and lower staircases give a finite abstraction for safety and reach-avoid synthesis. The package also covers sign patterns, derivative and disturbance bounds from data with scenario-approach guarantees, and assume-guarantee contracts.

For systems that are not monotone but have bounded derivatives, BoundedDerivativeModel(method=...) implements the five approaches of my PhD thesis (Chapter 3): two sign matrices ("two_matrix"), all sign matrices ("all_matrix"), growth cones ("growth"), and both with a linear-programming final step ("lin_mono", "lin_growth"). All are sound, plug into the same abstraction and synthesis, and the growth-cone models support local updates (update_local, refresh, and an exact incremental safe-set update); in MATLAB the same models and updates are ddma.bd_fit, ddma.bd_update, ddma.bd_update_local. GrowthMap offers the growth-cone model for a single function on its own.

Staircase bounds of the growth-cone model with the LP step, 10⁷ samples

Upper and lower staircase bounds around the true map

The experiments of the three papers and of the thesis chapter are re-run from scripts in the repository. Selected results:

Experiment Paper ddma
TAC, conservatism µ, 10⁶ → 10⁷ samples 2.7 → 2.47 2.703 → 2.470
TAC, Lorenz controlled invariant set, full size 929 s 296 s, 80 % of the cells
L4DC, exact abstraction + invariant set 923 s + 341 s 6.9 s + 5.1 s
Thesis Ch. 3, five bounded-derivative models LP variants (3, 5) tightest, 5 best same ranking at every data size: 5 < 3 < 4 ≈ 2 < 1

Maximal controlled invariant set of the Lorenz system, 10⁸ samples

Controllable set of the cruise-control contract, TAC Fig. 11

Conservatism of the five bounded-derivative models against data and grid size

The reproduction report in the repository also documents two open points found along the way: the disturbance level used for ADHS Fig. 3, and the disturbance weighting in the Lorenz scenario LP.

Methods: A. Makdesi, A. Girard, L. Fribourg. Implementation: Anas Makdesi.

Related papers

  1. IEEE CCTA

    Rectangular Partitioning Optimization for Data-Driven Abstractions of Monotone Systems

    Anas Makdesi, Majid Zamani · IEEE Conference on Control Technology and Applications, 2026

  2. IEEE TAC

    Data-Driven Models of Monotone Systems

    Anas Makdesi, Antoine Girard, Laurent Fribourg · IEEE Transactions on Automatic Control, 2024

  3. L4DC

    Data-Driven Abstraction of Monotone Systems

    Anas Makdesi, Antoine Girard, Laurent Fribourg · Learning for Dynamics and Control, 2021 · Oral presentation

  4. IFAC ADHS

    Efficient Data-Driven Abstraction of Monotone Systems with Disturbances

    Anas Makdesi, Antoine Girard, Laurent Fribourg · IFAC Conference on Analysis and Design of Hybrid Systems, 2021