PMAF : AN ALGEBRAIC FRAMEWORK FOR STATIC ANALYSIS OF PROBABILISTIC PROGRAMS Di Wang 1 , Jan Hoffmann 1 , Thomas Reps 2 1 Carnegie Mellon University 2 University of Wisconsin; GrammaTech, Inc.
PROBABILISTIC PROGRAMS Draw random data from distributions Condition control-flow at random
PROBABILISTIC PROGRAMS b1 ~ Bernoulli (0.5); b2 ~ Bernoulli (0.7); while (b1 && b2) do if prob (0.6) then True randomness b1 ~ Bernoulli (0.5) else b2 ~ Bernoulli (0.7) Distributions on executions fi ; tick (1.0) od ; return (b1, b2)
BAYESIAN NETWORKS Conditional distributions Pollution Smoker Query about the posterior Cancer Xray Res Dyspnea
BAYESIAN NETWORKS Conditional distributions Pollution Smoker Query about the posterior Cancer Prob [ Cancer ∣ Smoker ∧ Xray Res ] = ? Xray Res Dyspnea
BAYESIAN NETWORKS AS PROB. PROG. p b1 b2 0.6 0.5 0.7 p b1 b2 0.6 0.5 0.7
BAYESIAN NETWORKS AS PROB. PROG. if prob (0.6) then p b1 ~ Bernoulli (0.5) else b1 b2 0.6 b2 ~ Bernoulli (0.7) fi 0.5 0.7 p b1 b2 0.6 0.5 0.7
BAYESIAN NETWORKS AS PROB. PROG. 0.5 0.7 b1 ~ Bernoulli (0.5); ret b2 ~ Bernoulli (0.7); b1 b2 while (b1 && b2) do if prob (0.6) then b1 ~ Bernoulli (0.5) else && b2 ~ Bernoulli (0.7) fi ; tick (1.0) od ; p p return (b1, b2) b1 b1 b2 b2 0.6 0.6 0.5 0.5 0.7 0.7
BAYESIAN NETWORKS AS PROB. PROG. 0.5 0.7 b1 ~ Bernoulli (0.5); ret b2 ~ Bernoulli (0.7); b1 b2 while (b1 && b2) do if prob (0.6) then b1 ~ Bernoulli (0.5) else && b2 ~ Bernoulli (0.7) fi ; tick (1.0) od ; p p return (b1, b2) b1 b1 b2 b2 0.6 0.6 Query: probability that b1 and b2 are both false ? 0.5 0.5 0.7 0.7
BAYESIAN NETWORKS AS PROB. PROG. 0.5 0.7 b1 ~ Bernoulli (0.5); ret b2 ~ Bernoulli (0.7); b1 b2 while (b1 && b2) do if prob (0.6) then b1 ~ Bernoulli (0.5) else && b2 ~ Bernoulli (0.7) fi ; tick (1.0) od ; p p return (b1, b2) b1 b1 b2 b2 0.6 0.6 Query: expected termination time? 0.5 0.5 0.7 0.7
SAMPLING-BASED TECHNIQUES Simulation & frequency count sample Flexible & universal Potentially unsound & inefficient approximate
SAMPLING-BASED TECHNIQUES Simulation & frequency count sample Flexible & universal Potentially unsound & inefficient approximate What about static analysis ?
ABSTRACT INTERPRETATION Cousot et al. proposed Probabilistic Abstract Interpretation 1 Sound , flexible, and universal 1 P . Cousot and M. Monerau. Probabilistic Abstract Interpretation. In ESOP’12 .
ABSTRACT INTERPRETATION Cousot et al. proposed Probabilistic Abstract Interpretation 1 Sound , flexible, and universal Their concrete semantics resolves probabilities prior to nondeterminism 1 P . Cousot and M. Monerau. Probabilistic Abstract Interpretation. In ESOP’12 .
ABSTRACT INTERPRETATION Cousot et al. proposed Probabilistic Abstract Interpretation 1 Sound , flexible, and universal Their concrete semantics resolves probabilities prior to nondeterminism Sometimes desirable to revolve nondeterminism prior to probabilities 1 P . Cousot and M. Monerau. Probabilistic Abstract Interpretation. In ESOP’12 .
COUSOT ET AL.’S SEMANTICS * denotes nondeterministic choice tick(q) increases by q T if * then if prob (0.5) then tick (1.0) else tick (2.0) fi else if prob (0.5) then tick (1.0) else tick (2.0) fi fi
COUSOT ET AL.’S SEMANTICS * denotes nondeterministic choice tick(q) increases by q T if * then if prob (0.5) then tick (1.0) else tick (2.0) fi else if prob (0.5) then tick (1.0) else tick (2.0) fi fi with prob. 1 4
COUSOT ET AL.’S SEMANTICS * denotes nondeterministic choice tick(q) increases by q T if * then if prob (0.5) then tick (1.0) else tick (2.0) fi else if prob (0.5) then tick (1.0) else tick (2.0) fi fi
COUSOT ET AL.’S SEMANTICS * denotes nondeterministic choice tick(q) increases by q T if * then if prob (0.5) then tick (1.0) else tick (2.0) fi else if prob (0.5) then tick (1.0) else tick (2.0) fi fi with prob. 1 4
COUSOT ET AL.’S SEMANTICS * denotes nondeterministic choice tick(q) increases by q T if * then if prob (0.5) then tick (1.0) else tick (2.0) fi else if prob (0.5) then tick (1.0) else tick (2.0) fi fi
COUSOT ET AL.’S SEMANTICS * denotes nondeterministic choice tick(q) increases by q T if * then if prob (0.5) then tick (1.0) else tick (2.0) fi else if prob (0.5) then tick (1.0) else tick (2.0) fi fi with prob. 1 4
COUSOT ET AL.’S SEMANTICS * denotes nondeterministic choice tick(q) increases by q T if * then if prob (0.5) then tick (1.0) else tick (2.0) fi else if prob (0.5) then tick (1.0) else tick (2.0) fi fi
COUSOT ET AL.’S SEMANTICS * denotes nondeterministic choice tick(q) increases by q T if * then if prob (0.5) then tick (1.0) else tick (2.0) fi else if prob (0.5) then tick (1.0) else tick (2.0) fi fi with prob. 1 4
COUSOT ET AL.’S SEMANTICS * denotes nondeterministic choice tick(q) increases by q T if * then if prob (0.5) then tick (1.0) else tick (2.0) fi else if prob (0.5) then tick (1.0) else tick (2.0) fi fi
COUSOT ET AL.’S SEMANTICS * denotes nondeterministic choice tick(q) increases by q T if * then if prob (0.5) then tick (1.0) else tick (2.0) fi else if prob (0.5) then tick (1.0) else tick (2.0) fi fi Their concrete semantics yields 𝔽 [ T ] ∈ 1 4 ⋅ {1} + 1 4 ⋅ {2} + 1 4 ⋅ {1,2} + 1 4 ⋅ {1,2} = {1.25,1.5,1.75}
COUSOT ET AL.’S SEMANTICS * denotes nondeterministic choice tick(q) increases by q T if * then if prob (0.5) then tick (1.0) else tick (2.0) fi Identical! else if prob (0.5) then tick (1.0) else tick (2.0) fi fi Their concrete semantics yields 𝔽 [ T ] ∈ 1 4 ⋅ {1} + 1 4 ⋅ {2} + 1 4 ⋅ {1,2} + 1 4 ⋅ {1,2} = {1.25,1.5,1.75}
COUSOT ET AL.’S SEMANTICS * denotes nondeterministic choice tick(q) increases by q T if * then if prob (0.5) then tick (1.0) else tick (2.0) fi Identical! else if prob (0.5) then tick (1.0) else tick (2.0) fi fi Their concrete semantics yields 𝔽 [ T ] ∈ 1 4 ⋅ {1} + 1 4 ⋅ {2} + 1 4 ⋅ {1,2} + 1 4 ⋅ {1,2} = {1.25,1.5,1.75} while our semantics yields 𝔽 [ T ] = 1.5
CONTRIBUTIONS A denotational semantics with nondeterminism resolved first An algebraic framework for interprocedural dataflow analysis of first-order probabilistic programs PMAF Recursion Unstructured control-flow Divergence Nondeterminism …
CONTRIBUTIONS A denotational semantics with nondeterminism resolved first An algebraic framework for interprocedural dataflow analysis of first-order probabilistic programs PMAF
CONTRIBUTIONS A denotational semantics with nondeterminism resolved first An algebraic framework for interprocedural dataflow analysis of first-order probabilistic programs PMAF Implement Prove Design
CONTRIBUTIONS A denotational semantics with nondeterminism resolved first An algebraic framework for interprocedural dataflow analysis of first-order probabilistic programs PMAF
CONTRIBUTIONS A denotational semantics with nondeterminism resolved first An algebraic framework for interprocedural dataflow analysis of first-order probabilistic programs Existing PMAF Bayesian Inference Markov Decision Problem
CONTRIBUTIONS A denotational semantics with nondeterminism resolved first An algebraic framework for interprocedural dataflow analysis of first-order probabilistic programs Existing New PMAF Bayesian Inference Expectation-Invariant Analysis Markov Decision Problem
EXAMPLE ANALYSES b1 ~ Bernoulli (0.5); Our framework can be b2 ~ Bernoulli (0.7); instantiated to prove : while (b1 && b2) do if prob (0.6) then b1 ~ Bernoulli (0.5) the probability that b1 and b2 else are both false at the end of b2 ~ Bernoulli (0.7) the program = 0.15 fi ; tick (1.0) the expected termination time od ; (ticks) = 5/6 return (b1, b2)
OVERVIEW Motivation The Algebraic Framework Hyper-Graph Analysis Evaluation
THE ALGEBRAIC FRAMEWORK Any static analysis method performs reasoning in some space of program properties and property operations Sequencing Cond.-choice Actions Prob.-choice Semantic Nondet.-choice skip Function Program x := x + 5 Properties b ~ Bernoulli (0.4) tick (1.0) …
THE ALGEBRAIC FRAMEWORK Concrete Concrete Semantic Function Semantics Actions Concrete Operations skip Sound x := x + 5 Abstraction b ~ Bernoulli (0.4) tick (1.0) Abstract … Abstract Semantic Abstract Operations Function Semantics
THE ALGEBRAIC FRAMEWORK Characterize program properties and property operations by algebraic laws
THE ALGEBRAIC FRAMEWORK Characterize program properties and property operations by algebraic laws ⟨ M , ⊑ , ⊗ , φ ⋄ , p ⊕ , ⋓ , ⊥ , 1 ⟩
THE ALGEBRAIC FRAMEWORK Characterize program properties and property operations by algebraic laws ⟨ M , ⊑ , ⊗ , φ ⋄ , p ⊕ , ⋓ , ⊥ , 1 ⟩ Program properties and approximation order
THE ALGEBRAIC FRAMEWORK Characterize program properties and property operations by algebraic laws ⟨ M , ⊑ , ⊗ , φ ⋄ , p ⊕ , ⋓ , ⊥ , 1 ⟩ Program properties and approximation order Sequencing, cond.-choice, prob.-choice, and nondet.-choice
Recommend
More recommend