AA228V/CS238V
Validation of Safety-Critical Systems
Lecture 09: Failure Distribution
Sydney Katz (smkatz@stanford.edu)
What is the failure distribution?
Trajectory Distribution
Trajectory Distribution
Failure Distribution
A Simple Example
A Simple Example
A Simple Example
A Simple Example
A Simple Example
gives us the shape
A Simple Example
gives us the normalizing
constant
normally, this normalizing
constant is very difficult if not
impossible to compute
We can compute this!
Unnormalized Probability Density
Unnormalized Probability Density
There are algorithms that allow us to
draw samples from an unnormalized
probability density! This way, we can
implicitly represent the failure
distribution using samples.
Unnormalized Probability Density
There are algorithms that allow us to
draw samples from an unnormalized
probability density! This way, we can
implicitly represent the failure
distribution using samples.
Plan for Today
1
Unnormalized Probability Density
2
Rejection Sampling
3
Markov Chain Monte Carlo
4
Tips to Scale Things Up
Rejection Sampling
Rejection Sampling
Dart Board Analogy
1
Throw darts uniformly at the board.
Sample a value uniformly between and
1
Throw darts uniformly at the board.
Sample a value uniformly between and
Sample a value uniformly between and
repeat for
each dart
1
Throw darts uniformly at the board.
Sample a value uniformly between and
Sample a value uniformly between and
repeat for
each dart
1
Throw darts uniformly at the board.
Sample a value uniformly between and
Sample a value uniformly between and
repeat for
each dart
2
Reject any darts that lie
above the blue density.
1
Throw darts uniformly at the board.
Sample a value uniformly between and
Sample a value uniformly between and
repeat for
each dart
2
Reject any darts that lie
above the blue density.
3
Move the remaining darts to
the bottom of the board.
1
Throw darts uniformly at the board.
Sample a value uniformly between and
Sample a value uniformly between and
repeat for
each dart
2
Reject any darts that lie
above the blue density.
3
Move the remaining darts to
the bottom of the board.
1
Throw darts uniformly at the board.
Sample a value uniformly between and
Sample a value uniformly between and
repeat for
each dart
2
Reject any darts that lie
above the blue density.
3
Move the remaining darts to
the bottom of the board.
1
Throw darts uniformly at the board.
Sample a value uniformly between and
Sample a value uniformly between and
repeat for
each dart
2
Reject any darts that lie
above the blue density.
3
Move the remaining darts to
the bottom of the board.
1
Throw darts uniformly at the board.
Sample a value uniformly between and
Sample a value uniformly between and
repeat for
each dart
2
Reject any darts that lie
above the blue density.
Reject if
3
Move the remaining darts to
the bottom of the board.
1
Throw darts uniformly at the board.
Sample a value uniformly between and
Sample a value uniformly between and
repeat for
each dart
2
Reject any darts that lie
above the blue density.
Reject if
3
Move the remaining darts to
the bottom of the board.
Just keep the value for each sample
1
Throw darts uniformly at the board.
Sample a value uniformly between and
Sample a value uniformly between and
repeat for
each dart
2
Reject any darts that lie
above the blue density.
Reject if
3
Move the remaining darts to
the bottom of the board.
Just keep the value for each sample
Look at all those gray darts (samples) we wasted!
1
Throw darts uniformly at the board.
Sample a value uniformly between and
Sample a value uniformly between and
repeat for
each dart
2
Reject any darts that lie
above the blue density.
Reject if
3
Move the remaining darts to
the bottom of the board.
Just keep the value for each sample
Look at all those gray darts (samples) we wasted!
What if we could make our dart board look like this instead?
1
Throw darts uniformly at the board.
Sample a value uniformly between and
Sample a value uniformly between and
repeat for
each dart
2
Reject any darts that lie
above the blue density.
Reject if
3
Move the remaining darts to
the bottom of the board.
Just keep the value for each sample
What if we could make our dart board look like this instead?
We just need to select to be a distribution we can sample from
and such that is always greater than .
Departing from the dart board analogy.
Departing from the dart board analogy.
But first, a random fact about darts:
Dart boards are designed to
reward accuracy and penalize
inaccuracy.
Rejection Sampling
1
Sample
is often referred to as a proposal distribution
2
Reject if 
Rejection Sampling
1
Sample
is often referred to as a proposal distribution
2
Reject if 
Rejection Sampling
1
Sample
is often referred to as a proposal distribution
2
Reject if 
Accept if
Note: we must select the proposal
distribution such that .
Rejection Sampling
Back to trying to sample from the failure distribution:
1
Sample
2
Accept if
where
Rejection Sampling
Back to trying to sample from the failure distribution:
1
Sample
2
Accept if
where
We can produce samples from the failure
distribution by sampling from the nominal
trajectory distribution and rejecting any samples
that are not failures!
What might be a problem with this method?
Hint: what theme seems to be coming up over and over again in this course?
It will be inefficient for systems with rare failure events!
One solution is to try to come up with a better proposal distribution.
Rejection Sampling
We can produce samples from the failure
distribution by sampling from the nominal
trajectory distribution and rejecting any samples
that are not failures!
It will be inefficient for systems with rare failure events!
One solution is to try to come up with a better proposal distribution.
Threshold
-1.0
Samples
200
Proposal mean
0.0
Scale
1.000
Rejection Sampling
Challenges
Selecting an appropriate proposal distribution .
Selecting an appropriate value for .
See example 6.1
Plan for Today
1
Unnormalized Probability Density
2
Rejection Sampling
3
Markov Chain Monte Carlo
4
Tips to Scale Things Up
Markov Chain Monte Carlo
Markov
Markov Chain Monte Carlo
Markov Chain Monte Carlo
Markov Chain Monte Carlo
Markov Chain Monte Carlo
So how do we create the chain?
Start with an initial sample .
At each iteration:
1
Sample
e.g.
2
Accept with probability
(otherwise keep )
kernel
Markov Chain Monte Carlo
So how do we create the chain?
Start with an initial sample .
At each iteration:
1
Sample
e.g.
2
Accept with probability
(otherwise keep )
Markov Chain Monte Carlo
So how do we create the chain?
Start with an initial sample .
At each iteration:
1
Sample
e.g.
2
Accept with probability
(otherwise keep )
Markov Chain Monte Carlo
So how do we create the chain?
Start with an initial sample .
At each iteration:
1
Sample
e.g.
2
Accept with probability
(otherwise keep )
Markov Chain Monte Carlo
So how do we create the chain?
Start with an initial sample .
At each iteration:
1
Sample
e.g.
2
Accept with probability
(otherwise keep )
Markov Chain Monte Carlo
So how do we create the chain?
Start with an initial sample .
At each iteration:
1
Sample
e.g.
2
Accept with probability
(otherwise keep )
Markov Chain Monte Carlo
So how do we create the chain?
Start with an initial sample .
At each iteration:
1
Sample
e.g.
2
Accept with probability
(otherwise keep )
And so on…
Markov Chain Monte Carlo
So how do we create the chain?
Start with an initial sample .
At each iteration:
1
Sample
e.g.
2
Accept with probability
(otherwise keep )
And so on…
This process is guaranteed to
converge to the target distribution in
the limit of infinite samples.
Markov Chain Monte Carlo
Some Intuition
Accept with probability
This process is guaranteed to
converge to the target distribution in
the limit of infinite samples.
The kernel is often chosen to be
symmetric such that
.
We want to sample from areas of high density more often than areas of low density.
Two cases:
1
is more likely under the target density than
Always accept!
2
is less likely under the target density than
Accept with probability proportional to how much less likely it is.
Markov Chain Monte Carlo
Some Intuition
🤔
Still scratching your head?
Markov Chain Monte Carlo
Some Intuition
🤔
Still scratching your head?
Samples
1
Initial sample
-2.0
Burn in
1
Markov Chain Monte Carlo
This all works (converges to the target distribution) in the limit of infinite samples.
Markov Chain Monte Carlo
This all works (converges to the target distribution) in the limit of infinite samples.
We don’t have time for that!
Markov Chain Monte Carlo
This all works (converges to the target distribution) in the limit of infinite samples.
We don’t have time for that!
So we need often use some extra tricks in practice to make it perform better for a finite number of samples.
1
Burn in period
2
Thinning (e.g. only keep every 5th sample)
Deals with the fact that samples at subsequent steps are correlated
3
Smoothing
Markov Chain Monte Carlo
Multiple Failure Modes
Failure if
Chain starts at
Samples
1
Markov Chain Monte Carlo
Smoothing
We may need to “help” the algorithm move between failure modes.
We can do this by “smoothing out” the failure distribution.
Markov Chain Monte Carlo
Smoothing
We may need to “help” the algorithm move between failure modes.
We can do this by “smoothing out” the failure distribution.
Define distance for each trajectory such that:
if is a failure
otherwise
e.g.
when is small
The smoothed distribution assigns
nonzero probability to successes with
higher probabilities for successes that
are closer to failure.
Markov Chain Monte Carlo
Define distance for each trajectory such that:
if is a failure
otherwise
e.g.
when is small
The smoothed distribution assigns
nonzero probability to successes with
higher probabilities for successes that
are closer to failure.
The parameter controls the amount of smoothing applied:
nominal trajectory
distribution
no smoothing
Markov Chain Monte Carlo
🤔But won’t we now have a bunch of samples that are not failures?
Yes, but we can just reject them, and we will be left with samples from the failure distribution!
Note: you can think of it as applying
rejection sampling with the smoothed distribution
as the proposal distribution.
Markov Chain Monte Carlo
Smoothing

0.05
Plan for Today
1
Unnormalized Probability Density
2
Rejection Sampling
3
Markov Chain Monte Carlo
4
Tips to Scale Things Up
Tips to Scale Things Up
It is possible to apply these methods to more than just a one-dimensional Gaussian distribution 😀.
Tips to Scale Things Up
It is possible to apply these methods to more than just a one-dimensional Gaussian distribution 😀.
See examples 6.2 and 6.4 to show how we can apply
MCMC and smoothing to the pendulum example.
Other methods that help:
1
Some MCMC methods use gradients of the likelihood to define the kernel, which can
lead to better performance (e.g. MALA in section 6.3.3, HMC, NUTS)
2
Probabilistic programming allows us to specify probabilistic models as computer
programs
in a way that allows inference to be performed automatically.
Advanced
topics
Tips to Scale Things Up
Inverted pendulum: MCMC with a smoothed failure distribution (, keep every 500th)
Smoothing
0.15
Tips to Scale Things Up
2
Probabilistic programming allows us to specify probabilistic models as computer
programs
in a way that allows inference to be performed automatically.
😲
Plan for Today
1
Unnormalized Probability Density
2
Rejection Sampling
3
Markov Chain Monte Carlo
4
Tips to Scale Things Up