This repository contains the implementation of a framework for designing neural network controllers that guarantee closed-loop stability by design, promote probabilistic safety using risk-aware training, and provide distribution-free finite-sample safety certificates through conformal prediction. The approach combines the Performance Boosting (PB) framework with CVaR-based training and conformal verification to enable safe deployment of learning-based controllers for nonlinear systems.
- Stability-preserving neural network architecture: Uses Internal Model Control (IMC) parameterization to guarantee closed-loop ℓₚ-stability for any controller parameters, eliminating the need for stability constraints during optimization.
- Risk-aware CVaR training: Replaces intractable chance constraints with a smooth Conditional Value-at-Risk (CVaR) surrogate that promotes safe behavior for worst-case disturbances.
- Distribution-free conformal verification: Provides two-sided finite-sample probabilistic bounds on safety certificates using the DKWM inequality, with no assumptions on the underlying disturbance distribution.
- Iterative design feedback: Leverages conformal bounds to guide controller redesign, distinguishing between poor design and insufficient data collection.
-
Clone the repository:
git clone https://github.com/DecodEPFL/Conformal_PB.git cd Conformal_PB -
Create a virtual environment (Python 3.8+):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install torch numpy matplotlib jupyter
The main reproducibility notebook is main.ipynb, which contains:
- CVaR-Lagrangian training phase
- ERM-RBF baseline comparison with hyperparameter search
- Conformal verification and safety certification
- Pareto frontier visualization
- Trajectory plots and analysis
To run:
jupyter notebook main.ipynbThe notebook will train models, generate figures in a figures/ directory, and save trained checkpoints.
conformal_pb/
├── main.ipynb # Main reproducibility notebook with full pipeline
├── ren.py # REN (Recurrent Equilibrium Networks) controller implementation
├── robot.py # Robot dynamics and PD base controller
├── dataset.py # Data generation utilities
├── losses_and_wrappers.py # Loss functions and CVaR/Lagrangian wrappers
├── training_function.py # Training loop and optimization
├── performance_boosting.py # Performance Boosting closed-loop architecture
├── plot_functions.py # Visualization utilities for trajectories
├── *_checkpoints/ # Pre-trained model checkpoints
└── README.md # This file
ren.py: Implements the contractive REN, a stable-by-design neural network that parameterizes the controller in the IMC framework.robot.py: Defines the nonlinear robot dynamics (point-mass with drag) and base PD controller.losses_and_wrappers.py: ContainsPBLoss(tracking + collision avoidance),ERMWrapper,CVaRLossWrapper, andLagrangianCVaRLossWrapperfor different training objectives.training_function.py: Implements the min-max optimization loop for the Lagrangian-CVaR formulation.performance_boosting.py: Implements the IMC-based closed-loop system combining the stable controller with the plant.
We consider a sampling time
We sample the initial position of the robot from a Gaussian Mixture Model (GMM) with means
The environment contains two elliptical obstacles: the first is centered at
The tracking cost is parameterized with weight matrices
We trained a contractive REN (Revay et al., 2023) with internal linear and nonlinear state dimensions set to 4, and initialized its parameters from a zero-mean Gaussian with standard deviation 0.5. Training was conducted for 3000 episodes with independent batches of 200 trajectories.
We optimized the primal parameters
Let us define the empirical safety constraint violation
For the dual ascent step, we used a base dual learning rate
Thus,
The approach demonstrates that risk-aware CVaR-based training effectively promotes conformal safety verification. On the robot obstacle avoidance task:
- Safety vs. Performance Tradeoff: Our method achieves 1% collision frequency with mean tracking cost of 1.05, while the baseline suffers a 16% collision frequency at equivalent cost.
- Conformal Certification: The learned controller satisfies the 95% safety requirement with 95% confidence, verified on independent calibration data.
- Finite-Sample Confidence: Conformal bounds account for finite-sample uncertainty and guide iterative redesign decisions.
See main.ipynb for detailed results, Pareto curves, and trajectory visualizations.
Authors: Laura Meroi, Sabri El Amrani, Danilo Saccani, Dario Piga, Giancarlo Ferrari-Trecate
Affiliations:
- Institute of Mechanical Engineering, EPFL, Switzerland
- Dalle Molle Institute for Artificial Intelligence (IDSIA), SUPSI, Switzerland
This work was supported as part of NCCR Automation, a National Centre of Competence in Research, funded by the Swiss National Science Foundation (grant number 51NF40 225155) and the NECON project (grant number 200021219431).