principles of probabilistic programming
play

Principles of Probabilistic Programming Lectures at EWSCS 2020 - PowerPoint PPT Presentation

Principles of Probabilistic Programming Lectures at EWSCS 2020 Winter School Joost-Pieter Katoen EWSCS 2020, Palmse, Estonia Joost-Pieter Katoen Principles of Probabilistic Programming 1/56 Expected runtime analysis Overview Expected


  1. Principles of Probabilistic Programming Lectures at EWSCS 2020 Winter School Joost-Pieter Katoen EWSCS 2020, Palmse, Estonia Joost-Pieter Katoen Principles of Probabilistic Programming 1/56

  2. Expected runtime analysis Overview Expected runtime analysis 1 Analysing Bayesian networks 2 Epilogue 3 Joost-Pieter Katoen Principles of Probabilistic Programming 2/56

  3. Expected runtime analysis Olivier Bournez Florent Garnier Nuances of termination . . . . . . certain termination . . . . . . termination with probability one almost-sure termination º . . . . . . in an expected finite number of steps “positive” almost-sure termination º . . . . . . in an expected infinite number of steps “null” almost-sure termination º Joost-Pieter Katoen Principles of Probabilistic Programming 3/56

  4. Expected runtime analysis This lecture A weakest-precondition technique for proving “positive” almost-sure termination. In fact: A weakest-precondition technique for determining the expected runtime of a probabilistic program. Joost-Pieter Katoen Principles of Probabilistic Programming 4/56

  5. Expected runtime analysis Expected run-time analysis Z What? AST+termination in finite expected time Z Generalise. How? Z Provide a weakest precondition calculus Z . . . . . . for expected run-times Z a compositional calculus to reason at program syntax level Z Why? Z Classical weakest-preconditions cannot be used Z Proving positive AST is a special instance Z Reason about the e ffi ciency of randomised algorithms Z Reason about simulative inference of Bayesian networks Joost-Pieter Katoen Principles of Probabilistic Programming 5/56

  6. Expected runtime analysis The run time of a probabilistic program is random int i := 0; repeat {i++; (c := false [1/2] c := true )} until (c) The expected runtime is 1 + 3 � 1 / 2 + 5 � 1 / 4 + . . . + ( 2 n + 1 ) � 1 / 2 n = . . . < ô . Joost-Pieter Katoen Principles of Probabilistic Programming 6/56

  7. Expected runtime analysis Hurdles in runtime analysis 1. Programs may diverge while having a finite expected runtime: while (x > 0) { x-- [1/2] skip } 2. Expected runtimes are extremely sensitive to variations in probabilities while (x > 0) { x-- [1/2+e] x++ } // 0 <= e <= 1/2 Z For e = 0, the expected runtime is infinite. Z For any e > 0, the expected runtime is finite. 3. Having a finite expected time is not compositional (cf. next slide) Joost-Pieter Katoen Principles of Probabilistic Programming 7/56

  8. Expected runtime analysis PAST is not compositional Consider the two probabilistic programs: int x := 1; bool c := true ; while (c) { c := false [0.5] c := true ; x := 2*x } Finite expected termination time Joost-Pieter Katoen Principles of Probabilistic Programming 8/56

  9. Expected runtime analysis = IT { k ) Pr iterations PAST is not compositional ! Te 2 ' , Consider the two probabilistic programs: , § Efx , ^ PAST k=o int x := 1; PAST bool c := true ; while (c) { while (x > 0) { ; c := false [0.5] c := true ; x-- x := 2*x } } Finite termination time Finite expected termination time - AST PAST n Joost-Pieter Katoen Principles of Probabilistic Programming 8/56

  10. Expected runtime analysis PAST is not compositional Consider the two probabilistic programs: int x := 1; bool c := true ; while (c) { while (x > 0) { c := false [0.5] c := true ; x-- x := 2*x } } Finite termination time Finite expected termination time Running the right after the left program yields an infinite expected termination time Joost-Pieter Katoen Principles of Probabilistic Programming 8/56

  11. Expected runtime analysis Using wp for expected runtimes? while ( true ) { x++ } Z Consider the post-expectation x Z Characteristic function Φ x ( X ) = X ( x ( x + 1 ) Z Candidate upper bound is I = 0 Z Induction: Φ x ( I ) = 0 ( x ⇥ = x + 1 ) = 0 = I & I We — wrongly — conclude that 0 is the runtime. Using weakest pre-expectations is unsound for expected run-time analysis. Joost-Pieter Katoen Principles of Probabilistic Programming 9/56

  12. Expected runtime analysis Expected run-times Z Expected run-time of program P on input s : ô k � Pr ⌅ “ P terminates after k steps on input s ” ⌦ 9 k = 1 Z In general, ert () is a function t ⇥ Σ � R ' 0 < { ô } Z Let’s call this a run-time. Let T denote the set of run-times. Z Complete partial order on T : t 1 V t 2 i ff º s " Σ . t 1 ( s ) & t 2 ( s ) Joost-Pieter Katoen Principles of Probabilistic Programming 10/56

  13. Expected runtime analysis Continuation passing - ④ ti - - r O O - = 9 Same principle as for weakest pre-conditions: reason backwards Joost-Pieter Katoen Principles of Probabilistic Programming 11/56

  14. Expected runtime analysis Expected runtime transformer 0 Semantics ert ( P , t ) Syntax Z skip Z 1 + t Z diverge Z ô Z x := E Z 1 + t [ x ⇥ = E ] Z ert ( P 1 , ert ( P 2 , t )) Z P1 ; P2 Z 1 + [ G ] � ert ( P 1 , t ) + [ ¬ G ] � ert ( P 2 , t ) Z if (G) P1 else P2 Z 1 + p � ert ( P 1 , t ) + ( 1 � p ) � ert ( P 2 , t ) Z P1 [p] P2 Z lfp X . 1 + ([ G ] � ert ( P , X ) + [ ¬ G ] � t ) Z while (G)P Joost-Pieter Katoen Principles of Probabilistic Programming 12/56

  15. Expected runtime analysis Expected runtime transformer Semantics ert ( P , t ) Syntax Z skip Z 1 + t Z diverge Z ô ⑤ Z x := E Z 1 + t [ x ⇥ = E ] Z ert ( P 1 , ert ( P 2 , t )) Z P1 ; P2 % Z 1 + [ G ] � ert ( P 1 , t ) + [ ¬ G ] � ert ( P 2 , t ) Z if (G) P1 else P2 Z 1 + p � ert ( P 1 , t ) + ( 1 � p ) � ert ( P 2 , t ) Z P1 [p] P2 Z lfp X . 1 + ([ G ] � ert ( P , X ) + [ ¬ G ] � t ) Z while (G)P lfp is the least fixed point operator wrt. the ordering & on run-times This simple mild twist of weakest pre-expectations is sound. Joost-Pieter Katoen Principles of Probabilistic Programming 12/56

  16. Expected runtime analysis Example: straight-line code Joost-Pieter Katoen Principles of Probabilistic Programming 13/56

  17. 0 ) ) g ( x I ( t tin at at t g Cx HD ) 3- a = g Exc id O ① is x at > . . 4 2 P 7 6 53 2 It I t 1+1=2 on 00

  18. Expected runtime analysis A simple rule for upper bounds We have ert ( while ( G ) P , t ) = lfp X . Φ t ( X ) with Φ t ( X ) = 1 + ([ G ] � ert ( P , X ) + [ ¬ G ] � t ) By Park’s lemma: if Φ t ( I ) V I then ert ( while ( G ) P , t ) V I . Joost-Pieter Katoen Principles of Probabilistic Programming 14/56

  19. Expected runtime analysis Induction on loops while (c) { (x++ [1/2] c := false ) } Z Post runtime equals 0 Z Characteristic function: Φ 0 ( X ) = 1 + [ c = 1 ] � ⇤ 2 + 1 / 2 � ( X ( x ( x + 1 ) + X ( c ( 0 )) Z Candidate for upper bound: I = 1 + [ c = 1 ] � 6 Z Induction: Φ 0 ( I ) = 1 + [ c = 1 ] � ⇤ 2 + 1 / 2 � ( 1 + [ c = 1 ] � 6 + 1 + [ 0 = 1 ] � 6 ) = 1 + [ c = 1 ] � 6 & I By Park’s lemma: ert ( while . . . ) & 1 + [ c = 1 ] � 6 Joost-Pieter Katoen Principles of Probabilistic Programming 15/56

  20. Expected runtime analysis Coupon collector’s problem 00 O O Joost-Pieter Katoen Principles of Probabilistic Programming 16/56

  21. Expected runtime analysis Coupon collector’s problem cp := [0,...,0]; // no coupons yet i := 1; // coupon to be collected next x := 0: // number of coupons collected while (x < N) { while (cp[i] != 0) { i := uniform (1..N) // next coupon } cp[i] := 1; // coupon i obtained x++; // one coupon less to go } Using our ert-calculus one can prove that expected runtime is Θ ( N � log N ) . By systematic formal verification à la Floyd-Hoare. Machine checkable. Joost-Pieter Katoen Principles of Probabilistic Programming 17/56

  22. Expected runtime analysis Elementary properties of the ert-calculus Z Continuity: ert ( P , t ) is continuous, that is for every chain T = t 0 & t 1 & t 2 & . . . ⇥ ert ( P , sup T ) = sup ert ( P , T ) t & t ¨ implies ert ( P , t ) & ert ( P , t ¨ ) Z Monotonicity: Z Constant propagation: ert ( P , k + t ) = k + ert ( P , t ) Z Preservation of ô : ert ( P , ô ) = ô Z Connection to wp: ert ( P , t ) = ert ( P , 0 ) + wp ( P , t ) Z A ffi inity: ert ( P , r � t + u ) = ert ( P , 0 ) + r � wp ( P , t ) + wp ( P , u ) Joost-Pieter Katoen Principles of Probabilistic Programming 18/56

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend