Probabilistic Program Analysis and Concentration of...
Transcript of Probabilistic Program Analysis and Concentration of...
![Page 1: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/1.jpg)
Probabilistic Program Analysis and Concentration of Measure
Part I: Concentration of Measure
Sriram SankaranarayananUniversity of Colorado, Boulder
![Page 2: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/2.jpg)
Concentration of Measure: Experiment #1Heads àGain one dollar
Tails à Lose one dollar
Repeat 1000 times.
Best Case: + 1000 DollarsWorst Case: - 1000 Dollars.Average Case: 0 Dollars.
![Page 3: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/3.jpg)
Concentration of Measure: Experiment #2
Vehicle on a road.
![Page 4: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/4.jpg)
Systems Acting Under Disturbances
SystemExternal Disturbances
Output
Property
Yes
No
• “Classic” Formal Verification.• “Set-Valued” Robust Control.
• Stochastic Verification• Reliability• Stochastic Controls• Uncertainty Quantification
• Artificial Intelligence• Uncertainty Representations
![Page 5: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/5.jpg)
Topics Covered
• Quantitative Reasoning:• Prove bounds on probabilities of assertions.• Bounds on expectations/moments.
• Qualitative Reasoning:• Almost sure termination, recurrence, persistence, ..• Limit behavior.
y(t)
t
Probability(y(n) >= c)
Please ask questions during the talk!
![Page 6: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/6.jpg)
Papers
• Aleksandar Chakarov, Yuen-Lam (Vris) Voronin, and Sriram Sankaranarayanan, Deductive Proofs of Almost Sure Persistence and Recurrence Properties In TACAS 2016.• Olivier Bouissou, Eric Goubault, Sylvie Putot, Aleksandar Chakarov, and
Sriram Sankaranarayanan, Uncertainty Propagation using Probabilistic Affine Forms and Concentration of Measure Inequalities. In TACAS 2016.• Aleksandar Chakarov, and Sriram Sankaranarayanan, Probabilistic
Program Analysis using Martingales. In CAV 2013.• Sriram Sankaranarayanan, Aleksandar Chakarov, and Sumit
Gulwani, Static Analysis for Probabilistic Programs: Inferring Whole Program Properties from Finitely Many Paths In PLDI 2013.
Aleksandar Chakarov, PhD Thesis, University of Colorado, Boulder, August
2016.
![Page 7: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/7.jpg)
Co-Authors
Aleksandar ChakarovUniv. Colorado, Bouldernow at Phase Change
Olivier BouissouCEA, now at Mathworks
Eric GoubaultEcole Polytechnique
Sylvie PutotEcole Polytechnique
Yuen-Lam VoroninUniv. Colorado, Boulder
![Page 8: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/8.jpg)
Motivating Examples
![Page 9: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/9.jpg)
Example #1: Repetitive Robot
Sawyer Robotic Arm(rethink robotics)
Small errors at
each step.
Repeat this 100 times.
Probability of going out of bounds?
angles = [10, 60, 110, 160, 140, ...100, 60, 20, 10, 0]
x := TruncGaussian(0,0.05,-0.5,0.5) y := TruncGaussian(0, 0.1,-0.5,0.5)for reps in range(0,100):
for theta in angles: # Distance travelled variation d = Uniform(0.98,1.02) # Steering angle variation t = deg2rad(theta) * (1 + ...
TruncGaussian(0,0.01,-0.05,0.05)) # Move distance d with angle t x = x + d * cos(t) y = y + d * sin(t)
#Probability that we went too far?assert(x >= 272)
![Page 10: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/10.jpg)
Example #1: Continuedangles = [10, 60, 110, 160, 140, ...
100, 60, 20, 10, 0]x := TruncGaussian(0,0.05,-0.5,0.5) y := TruncGaussian(0, 0.1,-0.5,0.5)for reps in range(0,100):
for theta in angles: # Distance travelled variation d = Uniform(0.98,1.02) # Steering angle variation t = deg2rad(theta) * (1 + ...
TruncGaussian(0,0.01,-0.05,0.05)) # Move distance d with angle t x = x + d * cos(t) y = y + d * sin(t)
#Probability that we went too far?assert(x >= 272)
Scatter Plot (x,y) - 10^5 Simulations
![Page 11: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/11.jpg)
Example #2: UAV Keep Out Zone
Keep Out
Keep Out
x
y
![Page 12: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/12.jpg)
Example #2: UAV Keep Out Zone
theta := Uniform(-0.1, 0.1)y := Uniform(-0.1, 0.1)for j in range(0, n):
v := 4vw := 1 + random([-0.1, 0.1], 0, 0.01)thetaw := 0.6 + random([-0.1, 0.1], 0, 0.01)y := y + 0.1 * v * sin(theta) +
0.1 * vw * sin(thetaw)theta := 0.95 * theta – 0.03 * y
Probability( y >= 1.0)Probability(y <= -1.0)
![Page 13: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/13.jpg)
Anesthesia (Fentanyl) Infusion
InfusionRate
Time
Pump Error Patient
Drug Concentration
[McClain+Hug, Fentanyl Kinetics, Clinical Pharmacology & Therapeutics, 28(1):106–114, July 1980.]
x4 : [150, 300] ng/ml+
![Page 14: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/14.jpg)
Anesthesia Infusion (Continued)infusionTimings[7] = {20, 15, 15, 15, 15, 15, 45}; double infusionRates[7] = { 3, 3.2, 3.3, 3.4, 3.2, 3.1, 3.0}; Interval e0(-0.4, 0.4), e1(0.0), e2(0.006,0.0064); for i in range(0, 7):
currentInfusion= 20.0*infusionRates[i]; curTime = infusionTimings[i];
for j in range(0, 40 * infusionTimings[j]):e : = 1+ randomVariable(e0, e1, e2) u : = e * currentInfusionx1n : = 0.9012* x1 + 0.0304 * x2 + 0.0031 * x3
+ 2.676e-1 * ux2n := 0.0139* x1 + 0.9857 * x2 + 2e-3*u x3n := 0.0015 * x1 + 0.9985 * x3+ 2e-4*u x4n := 0.0838 * x1 + 0.0014 * x2 + 0.0001 *x3 +
0.9117 * x4 + 12e-3 * ux1 := x1n; x2 := x2n; x3 := x3; x4 := x4n
![Page 15: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/15.jpg)
Reasoning about Uncertainty
ProbabilisticProgram
RandomInputs
DemonicInputs
Output Property
Probability of Success?
Probability of Failure?
Estimating the probabilities vs. Proving bounds on probabilities.
Rare Event≤10-6 ?
![Page 16: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/16.jpg)
Agenda
• Probabilities and Programs.• Probabilistic Properties.
• Concentration of Measure Inequalities.• Finite executions, “straight line” programs.
• Martingales and more general programs.• Pre-expectation calculus.• Reasoning about termination.• Reasoning about temporal properties.
![Page 17: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/17.jpg)
Programming with Probabilities• Imperative programs with random number generation.
real x := Uniform(-1, 1)real y := Gaussian(2.5, 1.3)bool b := trueint i := 0for i in range(0, 100):
b := Bernoulli(0.5)if b:
x := x + 2 *y + Gaussian(0.5, 1.5)else:
x := 1 – 2.5 * x y := 2
assert( x >= y)
Random Number Generation
Function
![Page 18: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/18.jpg)
Demonic Nondeterminism
real x := Uniform(-1, 1)real y := Gaussian(2.5, 1.3)bool b int ifor i in range(0, 100):
b := Bernoulli(0.5)if b:
x := x + 2 *y + Gaussian(0.5, 1.5)else:
x := 1 – 2.5 * x – Choice(-1, 1)y := 2
assert( x >= y)
Demon chooses so as to maximize
probability of failure
• Ignore demonic nondeterminism.• Focus purely on random variables.
![Page 19: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/19.jpg)
Parametric Nondeterminism
real x := Uniform(-1, 1)real y := Gaussian(2.5, 1.3)bool b int ifor i in range(0, 100):
b := Bernoulli(0.5)if b:
x := x + 2 *y + Gaussian(0.5, 1.5)else:
x := 1 – 2.5 * x – RandomVariable([-1,1], [-0.1, 0.1], [0.001, 0.0015])y := 2
assert( x >= y)
![Page 20: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/20.jpg)
Probabilistic Program Semantics real x := Uniform(-1, 1)real y := Gaussian(2.5, 1.3)bool b := trueint i := 0for i in range(0, 100):
b := Bernoulli(0.5)if b:
x := x + 2 *y + Gaussian(0.5, 1.5)else:
x := 1 – 2.5 * x y := 2
assert( x >= y)
• Probabilistic Program = Markov Process.• State Variables (x, y, i, b)• Initial Distribution X0• State Update Rule:
Gaussian(0.5, 1.5)
Bernoulli(0.5)
![Page 21: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/21.jpg)
Concentration of Measure
![Page 22: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/22.jpg)
Concentration of Measure: Experiment #1
Heads àGain one dollar
Tails à Lose one dollar
Repeat 1000 times.
Best Case: + 1000 DollarsWorst Case: - 1000 Dollars.Average Case: 0 Dollars.
![Page 23: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/23.jpg)
Coin Tossi.i.d. random
variables
What is the distribution of Xn?
n, j both even or both odd.
![Page 24: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/24.jpg)
Coin Toss
What is the probability Xn >= 100?
Problem: Not easy to calculate.Solution: A bound on the probability is good enough.
![Page 25: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/25.jpg)
“Large Deviation” Inequalities
One-Sided Inequality Two-Sided Inequality
![Page 26: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/26.jpg)
Markov Inequality
• Let X be a non-negative random variable.
• Corollary (Chebyshev-Cantelli):
![Page 27: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/27.jpg)
Chernoff-Hoeffding Bounds
Theorem (Chernoff’ 52, Hoeffding’ 63):
![Page 28: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/28.jpg)
Coin Toss
What is the probability Xn >= 100?
![Page 29: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/29.jpg)
Coin Toss
• Probability bound (0.006) is conservative.• Actual value is 10x smaller ~ 5 x10-4
• What information about the coin tosses did we use?
Could we use higher moments to obtain better bounds?
![Page 30: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/30.jpg)
Bernstein Inequality
Extend Chernoff Inequalities with information about moments
![Page 31: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/31.jpg)
Quantitative Analysis
ProbabilisticProgram
Random Inputs
Output Quantity
y := Uniform(-0.01, 0.01)th := Uniform(-0.01, 0.01)
for i in range(0, n):y := y + 0.1 * thth := 0.8 * th + randomw()
Probability( y >= 1) <= ??
Lane Keeping Example
![Page 32: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/32.jpg)
Lane Keeping Exampley := Uniform(-0.01, 0.01)th := Uniform(-0.01, 0.01)
for i in range(0, 10):y := y + 0.1 * thth := 0.8 * th + randomw()
Probability( y >= 0.1) <= ??
![Page 33: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/33.jpg)
“Heterogeneous” Chernoff-HoeffdingBounds
![Page 34: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/34.jpg)
Lane Keeping Exampley := Uniform(-0.01, 0.01)th := Uniform(-0.01, 0.01)
for i in range(0, 10):y := y + 0.1 * thth := 0.8 * th + randomw()
Probability( y >= 0.1) <= ??
![Page 35: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/35.jpg)
Problem Setup
ProbabilisticProgram
Random Inputs (w0, w1, … , wm)
Output Quantity (y)
![Page 36: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/36.jpg)
Setup
x := InitialDistribution()
for i in range(0, n):w := RandomInputs()x := f(i, x, w)
assert(g(x) >= t)
Deterministic Control Flow
1. Chernoff-Hoeffding bounds ~ sums of random variables. Not general functions.2. Need to estimate expectations and possibly higher moments to apply.
![Page 37: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/37.jpg)
Setup
• Chernoff-Hoeffding bounds:• Sums of random variables. • Extensions to general functions.
• Solution 1: Affine arithmetic and concentration of measure (Bouissou et al. TACAS’16).
• Solution 2: Method of Bounded Differences.
x := InitialDistribution()
for i in range(0, n):w := RandomInputs()x := f(i, x, w)
assert(g(x) >= t)
![Page 38: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/38.jpg)
Affine Form Overview
• Affine Form: how program variables depend on the uncertainties.
y := Uniform(-0.01, 0.01)th := Uniform(-0.01, 0.01)
for i in range(0, 10):y := y + 0.1 * thth := 0.8 * th + randomw()
Probability( y >= 0.1) <= ??
![Page 39: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/39.jpg)
Affine Form Definition [Figueirido+Stolfi’04, Bouissou et al. ]
Noise Symbols
w1 w2
w4 w5
w3
Functional dependency graph
![Page 40: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/40.jpg)
Computing with Affine Forms
• Linear operations• Addition.• Multiplication with scalar.• Introduction of fresh random variables.
• Nonlinear Operations• Multiplication.• Division.• Sine, cosine, tan, log, exp,…
• Reasoning with affine forms.
![Page 41: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/41.jpg)
Multiplication of Affine Forms
Dependency Graph
![Page 42: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/42.jpg)
Nonlinear Operations
• We will restrict ourselves to smooth operations (continuous + differentiable)
• Let f be a Ck function
x : Affine Form x0: E(x)
Fresh noise symbol.
![Page 43: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/43.jpg)
Nonlinear Operation Example
w w1
![Page 44: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/44.jpg)
Lane Keeping Exampley := Uniform(-0.01, 0.01)th := Uniform(-0.01, 0.01)
for i in range(0, 10):y := y + 0.1 * thth := 0.8 * th + randomw()
Probability( y >= 0.1) <= ??
w1, … , w10 are all independent.
![Page 45: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/45.jpg)
Modified Lane Keepingy := Uniform(-0.01, 0.01)th := Uniform(-0.01, 0.01)
for i in range(0, 10):y := y + 0.1 * sin(th)th := randomw()
Probability( y >= 0.1) <= ??
y0 y2 y3 y4 y5 y6 y7
y20 y21Dependency Graph
![Page 46: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/46.jpg)
Modified Lane Keeping
y0
y2
y3y4
y5
y6
y7 y20 y21
Idea: 1. “Compress” connected component to a single noise symbol.2. Use Chernoff Hoeffding Bounds.
![Page 47: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/47.jpg)
Modified Lane Keepingy := Uniform(-0.01, 0.01)th := Uniform(-0.01, 0.01)
for i in range(0, 10):y := y + 0.1 * sin(th)th := randomw()
Probability( y >= 0.1) <= ??
![Page 48: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/48.jpg)
Example #1: Repetitive Robot
Sawyer Robotic Arm(rethink robotics)
Small errors at
each step.
Repeat this 100 times.
Probability of going out of bounds?
angles = [10, 60, 110, 160, 140, ...100, 60, 20, 10, 0]
x := TruncGaussian(0,0.05,-0.5,0.5) y := TruncGaussian(0, 0.1,-0.5,0.5)for reps in range(0,100):
for theta in angles: # Distance travelled variation d = Uniform(0.98,1.02) # Steering angle variation t = deg2rad(theta) * (1 + ...
TruncGaussian(0,0.01,-0.05,0.05)) # Move distance d with angle t x = x + d * cos(t) y = y + d * sin(t)
#Probability that we went too far?assert(x >= 272)
![Page 49: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/49.jpg)
Example #1: Continuedangles = [10, 60, 110, 160, 140, ...
100, 60, 20, 10, 0]x := TruncGaussian(0,0.05,-0.5,0.5) y := TruncGaussian(0, 0.1,-0.5,0.5)for reps in range(0,100):
for theta in angles: # Distance travelled variation d = Uniform(0.98,1.02) # Steering angle variation t = deg2rad(theta) * (1 + ...
TruncGaussian(0,0.01,-0.05,0.05)) # Move distance d with angle t x = x + d * cos(t) y = y + d * sin(t)
#Probability that we went too far?assert(x >= 272)
Scatter Plot (x,y) - 10^5 Simulations
![Page 50: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/50.jpg)
Example #2: UAV Keep Out Zonetheta := Uniform(-0.1, 0.1)y := Uniform(-0.1, 0.1)for j in range(0, n):
v := 4vw := 1 + random([-0.1, 0.1], 0, 0.01)thetaw := 0.6 + random([-0.1, 0.1], 0, 0.01)y := y + 0.1 * v * sin(theta) +
0.1 * vw * sin(thetaw)theta := 0.95 * theta – 0.03 * y
Probability( y >= 1.0)Probability(y <= -1.0)
![Page 51: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/51.jpg)
Anesthesia InfusioninfusionTimings[7] = {20, 15, 15, 15, 15, 15, 45}; double infusionRates[7] = { 3, 3.2, 3.3, 3.4, 3.2, 3.1, 3.0}; Interval e0(-0.4, 0.4), e1(0.0), e2(0.006,0.0064); for i in range(0, 7):
currentInfusion= 20.0*infusionRates[i]; curTime = infusionTimings[i];
for j in range(0, 40 * infusionTimings[j]):e : = 1+ randomVariable(e0, e1, e2) u : = e * currentInfusionx1n : = 0.9012* x1 + 0.0304 * x2 + 0.0031 * x3
+ 2.676e-1 * ux2n := 0.0139* x1 + 0.9857 * x2 + 2e-3*u x3n := 0.0015 * x1 + 0.9985 * x3+ 2e-4*u x4n := 0.0838 * x1 + 0.0014 * x2 + 0.0001 *x3 +
0.9117 * x4 + 12e-3 * ux1 := x1n; x2 := x2n; x3 := x3; x4 := x4n
![Page 52: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/52.jpg)
Concluding Thoughts
![Page 53: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/53.jpg)
Related Approaches
• Monte Carlo Methods• Statistical model checking. [Younes+Simmons, Jha et al, Clarke et al.]• Importance Sampling [Legay et al.]• Semantic Importance Sampling [Hansen et al. TACAS 2015, RV2016]
• Volume Computation• Solve the integration exactly (expensive) [Geldenhuys et al, S et al.]• Abstract the program by discretizing state space [Abate et al., PRISM]• Abstract the distribution by discretizing [Monniaux, Bouissou et al.]
• Polynomial-Time Approximation [Chistikov et al. TACAS 2015]
[Cousot +Monerau]
![Page 54: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/54.jpg)
Challenge #1: Representing Nonlinear ComputationsHow do you represent nonlinear computations?
theta := Uniform(-0.1, 0.1)y := Uniform(-0.1, 0.1)for j in range(0, n):
v := 4vw := 1 + random([-0.1, 0.1], 0, 0.01)thetaw := 0.6 + random([-0.1, 0.1], 0, 0.01)y := y + 0.1 * v * sin(theta) +
0.1 * vw * sin(thetaw)theta := 0.95 * theta – 0.03 * y
Probability( y >= 1.0)Probability(y <= -1.0)
Option 1: Affine Forms.• Approximations create dependencies.
Option 2: Nonlinear Forms.• Keeps random variables independent.• Hard to reason with.
![Page 55: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/55.jpg)
Challenge #2: Conditional Branches
theta := Uniform(-0.1, 0.1)y := Uniform(-0.1, 0.1)for j in range(0, n):
v := 4vw := 1 + random([-0.1, 0.1], 0, 0.01)thetaw := 0.6 + random([-0.1, 0.1], 0, 0.01)y := y + 0.1 * v * sin(theta) +
0.1 * vw * sin(thetaw)if y >= 0.1
theta := theta – 0.1if y <= - 0.1
theta := theta + 0.1Probability( y >= 1.0)Probability(y <= -1.0)
Approach # 1: Smoothing the Indicator Function.
Approach #2: Moment method.
Bad idea!
• Bounds using the problem of moments.• “Design your own” inequalities.
![Page 56: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/56.jpg)
Probabilistic Program Analysis and Concentration of Measure
Part II: Martingale
Sriram SankaranarayananUniversity of Colorado, Boulder
![Page 57: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/57.jpg)
Concentration of Measure: Experiment #1Heads àGain one dollar
Tails à Lose one dollar
Repeat N times.
At some point in the experiment:• I have won Xi dollars thus far.• If I toss once more, how much do I expect to have?
Expected fortune in next step = fortune in current step.
![Page 58: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/58.jpg)
Concentration of Measure: Experiment #2Vehicle on a road.
Expected value in next step = value in current step.
![Page 59: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/59.jpg)
Conditional Expectation
P(Y=y) > 0
![Page 60: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/60.jpg)
Martingale
Martingale is a special kind of stochastic process.
Revisit Experiment #1 and #2 slides now!
![Page 61: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/61.jpg)
Super/SubMartingales
Supermartingale:
Submartingale:
![Page 62: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/62.jpg)
First Properties of (Super) Martingales
![Page 63: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/63.jpg)
“Adapted” Martingales
![Page 64: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/64.jpg)
Why Martingales?
• Quantitative: Concentration of measure involving martingales.
• Qualitative: Convergence theorems and proofs of temporal properties.
![Page 65: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/65.jpg)
Martingales and Concentration of Measure (Azuma’s Inequality).
![Page 66: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/66.jpg)
Lipschitz Condition
Lipschitz (Bounded Difference) Condition:
![Page 67: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/67.jpg)
Azuma’s Inequality for Martingales
Supermartingale:
Submartingale:
![Page 68: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/68.jpg)
Coin Toss Experiment
Lipschitz Condition:
Azuma theorem:
Chernoff-Hoeffding:
Azuma theorem: No independence assumption.
![Page 69: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/69.jpg)
Doob Martingale or the Method of Bounded Differences
![Page 70: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/70.jpg)
Problem Statement
ProbabilisticProgram
Random Inputs (w0, w1, … , wm)
Output Quantity (y)
![Page 71: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/71.jpg)
Doob Sequence
Constant
![Page 72: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/72.jpg)
Doob Sequences are Martingales
![Page 73: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/73.jpg)
Method of Bounded Differences
Lipschitz Condition:
Azuma Inequality Applied to Doob Martingale:
![Page 74: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/74.jpg)
Application to Programs
ProbabilisticProgram
Random Inputs (w0, w1, … , wm)
Output Quantity (y)
1. Estimate Lipschitz bounds for each variable.• How? [Open Problem].
2. Apply Method of Bounded Differences.
![Page 75: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/75.jpg)
Direct Application of Azuma’s Theorem
![Page 76: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/76.jpg)
Concentration of Measure: Experiment #2Vehicle on a road.
![Page 77: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/77.jpg)
Experiment #2: Azuma’s Inequality
Lipschitz Condition:
![Page 78: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/78.jpg)
Experiment #2: Proving Bounds
L Azuma Inequality Chernoff-Hoeffding
0.38 0.93 0.48
1.5 0.32 7.7 x 10-5
3.0 0.011 9.5 x 10-14
3.8 0.0073 3.8 x 10-19
Fix t = 100
![Page 79: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/79.jpg)
Automatic Inference of Martingales
![Page 80: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/80.jpg)
Concentration of Measure: Experiment #2Vehicle on a road.
How do we find martingales?
![Page 81: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/81.jpg)
Super Martingales of Probabilistic ProgramsPre-Expectation Calculus[McIver & Morgan]
x := F(x, w)
(x, y) := 2* x + Uniform(-1, 2), - y + Uniform(-1, 1)
S
S1
Pre-Expectation of f w.r.t S
x
w1
wn
![Page 82: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/82.jpg)
Pre-Expectation Example #1
(x, y) := 2* x + Uniform(-1, 2), - y + Uniform(-1, 1)
![Page 83: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/83.jpg)
Pre-Expectation Example #2if (x >= 0)
x := x + Uniform(-1,2)y := y -1
else x := 2* x – Uniform(-1, 1)y := y - 2
![Page 84: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/84.jpg)
Loop Supermartingales
var x1,.., xnwhile (C)
do S
od
![Page 85: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/85.jpg)
Concentration of Measure: Experiment #2Vehicle on a road.
while (true)do
y := y + 0.1 * thth := 0.99 th + randomW()
od
S
preE(y + 10 * th, S) = y + 10 * th
![Page 86: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/86.jpg)
Automatic Inference of (Super) Martingale[Katoen + McIver + Morgan, Gretz + Katoen, Chakarov + S]
1. Fix an unknown template form of the desired function.
2. Use Farkas’ Lemma (theorem of the alternative) to derive constraints [Colon+S+Sipma’03]
3. Solve to obtain (super) martingales.
![Page 87: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/87.jpg)
Automatic Inference (Example)Vehicle on a road.
![Page 88: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/88.jpg)
Further Work on Martingale Inference #1
• Using Doob decomposition [ Barthe et al. CAV 2016].
• Start from an given expression and iteratively derive a martingale.
• Can derive very complex expressions.• Lots of avenues for future refinements here.
![Page 89: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/89.jpg)
Further Work on Martingale Inference #2
• Exponential Supermartingales [ Tedrake+Steinhardt’ IJRR 2012]• Using Sum-of-Squares Inequalities and Semi-Definite Programming.• Clever tricks to avoid solving bilinear matrix inequalities.• Comparison with Azuma’s inequality may be interesting.
![Page 90: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/90.jpg)
Probabilistic Program Analysis and Concentration of Measure
Part III: Termination, Persistence and Recurrence, Almost Surely!
Sriram SankaranarayananUniversity of Colorado, Boulder
![Page 91: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/91.jpg)
Quantitative vs. Qualitative Questions
Program
RandomInputs
What is the probability of blah?
Does the program terminate?
![Page 92: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/92.jpg)
Qualitative Questions
• Almost Sure Termination/Reachability.• The program terminates with probability 1.• All executions eventually reach a desired set with probability 1.
• Almost Sure Persistence.• The program executions reach a set S and remain in S forever.
• Almost Sure Recurrence• The program executions visit S infinitely often.
![Page 93: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/93.jpg)
Almost Sure Termination
while (x >= y) x := x + Uniform(-1, 1)y := y + Gaussian(1, 2.0)
Does this loop terminate?
(10,8) à (11,8) à (12, 8) à (13, 8) à …
Nonterminating execution
Almost Sure Termination.Terminates with probability 1.Measure of samples leading to non-termination is 0.
![Page 94: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/94.jpg)
Proving Termination
while (x >= y) x := x y := y + 1
Ranking Function: x – y
• Decreases by 1 on each loop iteration.
• When negative, loop terminates.
while (x >= y) x := x + U(-1,1)y := y + N(1, 2)
Supermartingale Ranking Function: x – y
![Page 95: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/95.jpg)
Supermartingale Ranking Functions (SMRF)
var x1, .., xnwhile ( C ) do
Sod
Function of program state:
• “Foster” Lyapunov Criteria (for discrete time Markov Chains).• Ranking function analogues [McIver + Morgan]
not C
x
![Page 96: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/96.jpg)
Main Result
• Let f(x1,…, xn) be a SMRF.
• If f is positive over the initial state.
• Then f becomes negative almost surely upon repeatedly executing the loop body.
Corollary of Martingale Convergence Thm. (+ technicalities).
var x1, .., xnwhile (C) do
Sod
![Page 97: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/97.jpg)
Example # 1
real h, t// h is hare position// t is tortoise positionwhile (t <= h)
if (flip(0.5))h := h + uniformRandom(0,2)
t := t + 1// Almost sure termination?
0 2
1
“Slow and steady wins the race almost surely”
![Page 98: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/98.jpg)
Example #2 : Betting Strategy For Roulettei := 0;money := 10, betwhile (money >= 10 ) {
bet := rand(5,10) money := money - bet if (flip(36/37)) // bank lost
if flip(1/3) // col. 1 if flip(1/2)
money := money + 1.6*bet // Red else
money := money + 1.2*bet // Black elseif flip(1/2) // col. 2
if flip(1/3) money := money + 1.6*bet; // Red
else money := money + 1.2*bet // Black else // col. 3
if flip(2/3) money := money + 0.4*bet // Red
i := i + 1 }
money – 10 is a SMRF
![Page 99: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/99.jpg)
Obtaining Completeness
• SMRFs are not complete for proving termination.
x = 0while (x != 1 and x != -1)
if (flip(0.5))x := x + 1
else x := x - 1
// Almost sure termination
The program can be shown to terminate almost surely.
No SMRF exists.
Completeness assuming the time taken to terminate (stopping time) is integrable[ Fioriti, Hermanns et al.’15].Proving bounds on time taken to terminate. [Chatterjee et al.’16, Kaminski et al’16].Complexity of proving almost sure termination. [Kaminski + Katoen ’15].
![Page 100: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/100.jpg)
A note of caution…
while C do S
(not C) holds?
x := 0while ( x ! = 1)
if ( flip(0.5))x := x + 1
else x := x - 1
x = 1 holds
x is a martingale of the program
E(x) = 0 at initial state.E(x) = 0 after each loop iteration.
E(x) = 0 holds when program terminates?
Facts about expected values at each loop iteration are not necessarily true when the program terminates.
Doob’s Optional Stopping Theorem: Provides condition when we can transfer.[ Fioriti, Hermanns POPL’15].
![Page 101: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/101.jpg)
Persistence (and Recurrence)
![Page 102: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/102.jpg)
Beyond Termination..
• We are often interested in proving more complex temporal properties.
• Two papers in the same conference!• [Chakarov+Voronin+S’ TACAS 16]• [Dimitrova+Fioriti+Hermanns+Majumdar’TACAS 16]• Both based on ideas using martingale theory.
![Page 103: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/103.jpg)
Room Heater Example [Abate et al. 2010]x0
x1 x2
H H
![Page 104: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/104.jpg)
Persistence
Target SetT
Almost surely, all behaviors enter T eventually and stay in there forever.
![Page 105: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/105.jpg)
From Termination to Persistence
Target SetV < 0
Target Set
Decrease Rule
V(x)
t
0Unsound!
![Page 106: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/106.jpg)
Unsoundness of SMRFs for Persistence
0-1-2-3-x …… -(x+1)p(x)
1-p(x)
V(x) = x satisfies the conditions for SMRF.
The chain visits 0 infinitely often almost surely!
x decreases by 1 large probability
large increase tiny probability
![Page 107: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/107.jpg)
Bounded Increase Condition
Target SetV < 0
Target Set
Decrease Rule
Bounded Decrease Condition
![Page 108: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/108.jpg)
Room Heater Example [Abate et al. 2010]x0
x1 x2
H H
Using Sum-Of-Squares Programming
![Page 109: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/109.jpg)
Open Directions
![Page 110: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/110.jpg)
Challenge #1: Symbolic Domains
• Incorporate Booleans, Graphs and other domains.
• Common in randomized algorithms.
• Benefit by careful mechanization.
• Application areas:• Dynamics on graphs and social networks.• Graph rewriting systems (Graph Grammars).• Self-assembling systems.
![Page 111: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/111.jpg)
Challenge #2: Concentration of Measure Inequalities• Understanding when concentration of measure inequalities work.
• Using more properties about the underlying distributions.
• Designer Inequalities.• Symbolic inference of property specific inequalities.
![Page 112: Probabilistic Program Analysis and Concentration of Measurealfa.di.uminho.pt/~nevrenato/probprogschool_slides/Sriram.pdf · •Sriram Sankaranarayanan, AleksandarChakarov, and Sumit](https://reader034.fdocuments.us/reader034/viewer/2022042407/5f21e8ae4a159f2089390807/html5/thumbnails/112.jpg)
Thank You!Thank you to University of Minho and the Organizers of the Summer School.Work supported by US NSF under award # CCF-1320069 (primary source of support), CNS-0953941, CNS-1016994 and CPS-1035845. All opinions expressed are those of the authors and not necessarily of the NSF