|
|
lucid
0.0.1
Lifting-based Uncertain Control Invariant Dynamics
|
Monte Carlo simulation for estimating the safety probability of a system. More...
#include <MontecarloSimulation.h>
Public Member Functions | |
| MontecarloSimulation ()=default | |
| Construct a new MontecarloSimulation object. | |
| std::pair< double, double > | safety_probability (const Set &X_bounds, const Set &X_init, const Set &X_unsafe, const std::function< Vector(ConstVectorRef)> &system_dynamics, std::size_t time_horizon, double confidence_level=0.9, Dimension num_samples=1000) const |
| Compute the safety probability with a confidence interval using Monte Carlo simulation. | |
Monte Carlo simulation for estimating the safety probability of a system.
The safety probability is estimated by sampling initial states from the initial set and simulating the system dynamics for a given time horizon. The safety probability is then computed as the fraction of samples that do not enter the unsafe set during the simulation. The method also provides a confidence interval for the estimated safety probability using the Chebychev inequality.
|
nodiscard |
Compute the safety probability with a confidence interval using Monte Carlo simulation.
The method samples initial states from the initial set \( \texttip{\mathcal{X}}{Initial set}_0 \), simulates the system dynamics up to the given time_horizon and computes the fraction of samples whose trajectories do not enter the unsafe set \( \texttip{\mathcal{X}}{Usafe set}_u \). Note that a trajectory leaving the bounds of the state space is immediately considered safe. The confidence interval is computed using the Chebychev inequality. Let \( X \) be a random variable drawn from a Bernoulli distribution with probability \( p \), i.e., \( X \sim \text{Bernoulli}(p) \). It follows that the expected value of \( X \) is \( \mathbb{E}[X] = p \). \( X \) indicates whether a trajectory starting within the initial set remains safe (1) or enters the unsafe set (0) within the time horizon. Sampling num_samples trajectories independently distributed, we can create a confidence interval around the true safety probability with the formula
\[P(|\hat{X} - \mathbb{E}[X]| \geq \varepsilon) \leq \frac{1}{4 n \varepsilon^2} \le (1 - \alpha) , \]
where \( \hat{X} = \frac{1}{n} \sum_{i=1}^{n} X_i \) is the sample mean, \( n \) is the number of samples, \( \varepsilon \) is the error, and \( \alpha \) is the confidence level. Hence, having fixed \( \alpha \) and \( n \), we can obtain the error bound
\[\varepsilon = \sqrt{\frac{1}{4 n (1 - \alpha)}} , \]
so that the interval \( [\hat{X} - \varepsilon, \hat{X} + \varepsilon] \) contains the true safety probability with confidence level \( \alpha \).
confidence_level must be in the range \( [0, 1) \). num_samples must be greater than 0. X_bounds, X_init, and X_unsafe must have the same dimension. time_horizon must be greater than 0. | X_bounds | set representing the bounds of the state space |
| X_init | set representing the initial states |
| X_unsafe | set representing the unsafe states |
| system_dynamics | function representing the system dynamics |
| time_horizon | number of time steps to simulate |
| confidence_level | confidence level for the safety probability interval |
| num_samples | number of samples to use for the Monte Carlo simulation |