AA228V/CS238V
Validation of Safety-Critical Systems
Lecture 05/06: Falsification Through Optimization
Sydney Katz (smkatz@stanford.edu)
https://gandalf.lakera.ai/do-not-tell-and-block
Falsification = Systematically Finding Failures
Falsification = Systematically Finding Failures
Why find failures?
To inform future design decisions.
Enhance system sensors
Change agent’s policy
Revise system requirements
Adapt training of human operators
Recognize as limitations
Abandon the project
On a happy note…
A Baseline Approach
Direct Sampling
Direct Sampling
Perception noise 0.10
Depth 41
Number of rollouts 50
Direct Samplingmay perform poorly for systems with rare failure events.
Direct Samplingmay perform poorly for systems with rare failure events.
Direct Samplingmay perform poorly for systems with rare failure events.
Geometric distribution:
Direct Samplingmay perform poorly for systems with rare failure events.
Geometric distribution:
The expected value of this distribution is
In other words, it should require
simulations on average to find a single
failure event.
Direct Samplingmay perform poorly for systems with rare failure events.
In other words, it should require
simulations on average to find a single
failure event.
For systems with rare failure events, is really low.
e.g. imagine an aircraft collision avoidance system with
We would need an average of billion simulations to observe a single failure!
🤔
We are going to need a better way.
Plan for Today
1
Direct Sampling
2
Disturbances
3
Fuzzing
4
Optimization
This is what I would start with for Project 1!
Plan for Today
1
Direct Sampling
2
Disturbances
3
Fuzzing
4
Optimization
This (and/or what we learn Thursday) is what I would do to
improve my leaderboard score.
🤔
Direct Samplingmay perform poorly for systems with rare failure events.
We can instead systematically search for failures by taking control of the sources of randomness in a system using
Disturbances
To incorporate disturbances into a system, we need to rewrite its agent, environment, and sensor models:
,  ,  and .
To incorporate disturbances into a system, we need to rewrite its agent, environment, and sensor models:
,  ,  and .
To incorporate disturbances into a system, we need to rewrite its agent, environment, and sensor models:
,  ,  and .
To incorporate disturbances into a system, we need to rewrite its agent, environment, and sensor models:
,  ,  and .
rewrite
deterministic
function
disturbance
distribution
disturbance
rewrite
Example
Recall the inverted pendulum observation model:
We can rewrite with disturbances as follows:
In this case, the disturbance represents the “observation noise” added to the true state.
The observation noise is sampled from a disturbance distribution centered at zero (no
noise) with covariance .
Note: the model with disturbances still represents the same process. We have just
separated out the stochastic components so that we can control them!
Sensor
rewrite
Agent
rewrite
Environment
rewrite
Sensor
rewrite
Agent
rewrite
Environment
rewrite
Disturbance
Disturbance distribution
“disturbution”
Sensor
rewrite
Agent
rewrite
Environment
rewrite
*Note: no because the
agent is
deterministic!
*Note: no because the
environment is
deterministic!
Disturbance
Disturbance distribution
Disturbance
Disturbance distribution
Disturbance
Disturbance distribution
Disturbance
Disturbance distribution
Disturbance
Disturbance distribution
Disturbance
Disturbance distribution
Disturbance
Disturbance distribution
Disturbance
Disturbance distribution
deterministic for the pendulum!
Disturbance
Disturbance distribution
deterministic for the pendulum!
Disturbance
Disturbance distribution
deterministic for the pendulum!
deterministic for the pendulum!
Disturbance
Disturbance distribution
deterministic for the pendulum!
deterministic for the pendulum!
Disturbance
Disturbance distribution
deterministic for the pendulum!
deterministic for the pendulum!
record everything
that happened
Disturbance
Disturbance distribution
We can use the idea of disturbances to explicitly define the distribution over trajectories for a system.
We can use the idea of disturbances to explicitly define the distribution over trajectories for a system.
There are two sources of randomness in a trajectory rollout:
1
the initial state
2
the disturbance applied at each time step
We can use the idea of disturbances to explicitly define the distribution over trajectories for a system.
There are two sources of randomness in a trajectory rollout:
1
the initial state
2
the disturbance applied at each time step
We can use the idea of disturbances to explicitly define the distribution over trajectories for a system.
There are two sources of randomness in a trajectory rollout:
1
the initial state
2
the disturbance applied at each time step
Trajectory Distribution
We can use the idea of disturbances to explicitly define the distribution over trajectories for a system.
There are two sources of randomness in a trajectory rollout:
1
the initial state
2
the disturbance applied at each time step
Trajectory Distribution
We can use the idea of disturbances to explicitly define the distribution over trajectories for a system.
There are two sources of randomness in a trajectory rollout:
1
the initial state
2
the disturbance applied at each time step
Trajectory Distribution
We can use the idea of disturbances to explicitly define the distribution over trajectories for a system.
There are two sources of randomness in a trajectory rollout:
1
the initial state
2
the disturbance applied at each time step
Trajectory Distribution
We can use the idea of disturbances to explicitly define the distribution over trajectories for a system.
There are two sources of randomness in a trajectory rollout:
1
the initial state
2
the disturbance applied at each time step
Trajectory Distribution
Sampling a Trajectory Distribution: Rollout
We can use the idea of disturbances to explicitly define the distribution over trajectories for a system.
There are two sources of randomness in a trajectory rollout:
Trajectory Distribution
Sampling a Trajectory Distribution: Rollout
🤔
Wait.. didn’t we already see a different algorithm for rollout in the intro lecture?
Sampling a Trajectory Distribution: Rollout
Rollout from Introduction Lecture
This version of rollout is
implicitly sampling from the
nominal trajectory distribution
for the system.
Thenominal trajectory distributionrepresents the distribution over trajectories that we expect to observe in the real world.
Thenominal trajectory distributionrepresents the distribution over trajectories that we expect to observe in the real world.
Note:
  • Every agent has a nominal implemented
  • Every environment has a nominal and implemented
  • Every sensor has a nominal implemented
The nominal models come from data/expert knowledge from
the real world (see chapter 2!).
Pendulum example: the nominal trajectory distribution
DeterministicDeterministic
🤔
Wait.. didn’t we already see a different algorithm for rollout in the intro lecture?
Sampling a Trajectory Distribution: Rollout
Rollout from Introduction Lecture
This version of rollout is
implicitly sampling from the
nominal trajectory distribution
for the system.
Plan for Today
1
Direct Sampling
2
Disturbances
3
Fuzzing
4
Optimization
This is what I would start with for Project 1!
Fuzzing
Input a different (not nominal) trajectory distribution into this
function — one that is more likely to cause failures.
e.g. for the inverted pendulum, we could use a disturbance distribution with
higher perception noise than the nominal distribution
Fuzzing
Nominal perception noise
Fuzzing noise 0.10
Rollouts 50
Another happy note…
Plan for Today
1
Direct Sampling
2
Disturbances
3
Fuzzing
4
Optimization
This (and/or what we learn next week) is what I would do to
improve my leaderboard score.
Optimization
Our goal is to systematically search over initial states and sequences of disturbances to find failure trajectories.
Optimization
Our goal is to systematically search over initial states and sequences of disturbances to find failure trajectories.
Optimization
Our goal is to systematically search over initial states and sequences of disturbances to find failure trajectories.
Optimization
Our goal is to systematically search over initial states and sequences of disturbances to find failure trajectories.
minimize
subject to
objective function that represents
“closeness to failure”
Optimization
Our goal is to systematically search over initial states and sequences of disturbances to find failure trajectories.
minimize
subject to
objective function that represents
“closeness to failure”
Optimization
Our goal is to systematically search over initial states and sequences of disturbances to find failure trajectories.
objective function that represents
“closeness to failure”
🤔
What metric from chapter 3 reminds you of “closeness to failure”?
Robustness!
(or if our optimization algorithm needs gradients, smooth robustness)
Optimization
Our goal is to systematically search over initial states and sequences of disturbances to find failure trajectories.
objective function that represents
“closeness to failure”
🤔
What metric from chapter 3 reminds you of “closeness to failure”?
Robustness!
(or if our optimization algorithm needs gradients, smooth robustness)
🤔
What might be a problem with the robustness objective?
We might get very unlikely trajectories…
Optimization
Our goal is to systematically search over initial states and sequences of disturbances to find failure trajectories.
🤔
What might be a problem with the robustness objective?
We might get very unlikely trajectories…
incorporate likelihood
into the objective
incorporate likelihood
into the objective
How do we evaluate the likelihood of a trajectory?
The likelihood of the trajectory is the likelihood of the initial state and all disturbances in the trajectory occurring.
incorporate likelihood
into the objective
How do we evaluate the likelihood of a trajectory?
The likelihood of the trajectory is the likelihood of the initial state and all disturbances in the trajectory occurring.
incorporate likelihood
into the objective
How do we evaluate the likelihood of a trajectory?
The likelihood of the trajectory is the likelihood of the initial state and all disturbances in the trajectory occurring.
incorporate likelihood
into the objective
How do we evaluate the likelihood of a trajectory?
The likelihood of the trajectory is the likelihood of the initial state and all disturbances in the trajectory occurring.
incorporate likelihood
into the objective
How do we evaluate the likelihood of a trajectory?
The likelihood of the trajectory is the likelihood of the initial state and all disturbances in the trajectory occurring.
incorporate likelihood
into the objective
How do we evaluate the likelihood of a trajectory?
The likelihood of the trajectory is the likelihood of the initial state and all disturbances in the trajectory occurring.
incorporate likelihood
into the objective
How do we evaluate the likelihood of a trajectory?
The likelihood of the trajectory is the likelihood of the initial state and all disturbances in the trajectory occurring.
incorporate likelihood
into the objective
How do we evaluate the likelihood of a trajectory?
The likelihood of the trajectory is the likelihood of the initial state and all disturbances in the trajectory occurring.
incorporate likelihood
into the objective
New Objective:
1
The trajectory is a failure.
“Make the failure trajectory more likely”
2
The trajectory is not a failure.
“Move the trajectory closer to a failure”
incorporate likelihood
into the objective
Previous Objective:
New Objective:
incorporate likelihood
into the objective
Previous Objective:
New Objective:
Iteration 1
Iteration 5
Iteration 8
Converged
incorporate likelihood
into the objective
Some Notes on This Objective
We must ensure that failures never have a
higher objective value than successes.
No problem! for successes
and is always less than .
…but is often really small causing
numerical stability issues
…so we want to use log-likelihood instead, but
this breaks the first requirement because log
likelihood can be less than !
…so sometimes a different objective works
better in practice (see next slide)
incorporate likelihood
into the objective
robustness
*tends to be more numerically stable
incorporate likelihood
into the objective
log likelihood
*tends to be more numerically stable
incorporate likelihood
into the objective
weighting
parameter
*tends to be more numerically stable
Then we optimize!
Then we optimize!
Then we optimize!
Objective Function
Optimizer
Then we optimize!
Objective Function
Optimizer
1
2
3
Then we optimize!
Objective Function
Optimizer
1
2
3
Optimization
Algorithm
Objective
Parameters
Optimum
Optimization
Algorithm
Objective
Parameters
Optimum
Local Descent Methods
Population Methods
Optimization
Algorithm
Objective
Parameters
Optimum
Local Descent Methods
Population Methods
Optimization
Algorithm
Objective
Parameters
Optimum
Local Descent Methods
Population Methods
first-order and
second-order
e.g. gradient descent,
ADAM, LBFGS
!
gradients
required!
zero-order
(direct methods)
e.g. Hooke-Jeeves,
Nelder-Mead
work for black-
box systems!
Optimization
Algorithm
Objective
Parameters
Optimum
Local Descent Methods
Optimization
Algorithm
Objective
Parameters
Optimum
Local Descent Methods
Population Methods
first-order and
second-order
e.g. gradient descent,
ADAM, LBFGS
!
gradients
required!
zero-order
(direct methods)
e.g. Hooke-Jeeves,
Nelder-Mead
work for black-
box systems!
Optimization
Algorithm
Objective
Parameters
Optimum
Population Methods
Optimization
Algorithm
Objective
Parameters
Optimum
Local Descent Methods
Population Methods
first-order and
second-order
e.g. gradient descent,
ADAM, LBFGS
!
gradients
required!
zero-order
(direct methods)
e.g. Hooke-Jeeves,
Nelder-Mead
work for black-
box systems!
Then we optimize!
Objective Function
Optimizer
1
2
3
Optimization
Algorithm
Objective
Parameters
Optimum
Take AA222/CS361 for more details!!!
Plan for Today
1
Direct Sampling
2
Disturbances
3
Fuzzing
4
Optimization
This is what I would start with for Project 1!
This (and/or what we learn Thursday) is what I would do to
improve my leaderboard score.