Example 1a: Two Fair Coins

Example 1a: Two Fair Coins

Example 1a: Joint Probability Mass Function (JPMF) of two Independent Bernoulli Random Variables

Andrew D. Gordon, Thomas A. Henzinger, Aditya V. Nori, and Sriram K. Rajamani. 2014. Probabilistic programming. In Proceedings of the on Future of Software Engineering (FOSE 2014). ACM, New York, NY, USA, 167-181. DOI=10.1145/2593882.2593900 doi.acm.org/10.1145/2593882.2593900

 
   

PROB-Code for P(C1, C2) and E[(C1, C2)] = (1/2, 1/2)

"The program in Example 1(a), tosses two fair coins (simulated by draws from a Bernoulli distribution with mean 0.5), and assigns the outcomes of these coin tosses to the Boolean variables c1 and c2 respectively, and returns (c1 , c2). The semantics of this program is the expectation of its return value. In this case, this is equal to (1/2, 1/2). Since we have that Pr(c1 = false, c2 = false) = Pr(c1 = false, c2 = true) = Pr(c1 = true, c2 = false) = Pr(c1 = true, c2 = true) = 1/4, we have that the expectation on the return value is given by 1/4x(0, 0) + 1/4x(0, 1) + 1/4x(1, 0) + 1/4x(1, 1) = (1/2, 1/2) (by treating true as 1 and false as 0)." (Gordon et al., ICSE-FoSE 2014, p.2)

CHURCH-Code for P(C1, C2) and E[(C1, C2)] = (1/2, 1/2)

The PROB-code snippet from Gordon et al. is translated by us to a functional CHURCH-script to clarify its semantics. The generative model is contained in the CHURCH function "take-a-sample". The number of samples taken was set to 1000 in this run. This number can be increased to get a better precision of estimates. The sampling method used is the simple-to-understand 'rejection sampling'. The screen-shot presented was generated by using the PlaySpace environment of WebCHURCH.

WebPPL-Code for JPMF P(C1, C2) "Two Fair Coins"

R-Code for P(C1, C2) and E[<C1, C2>] = <1/2, 1/2>

R-Code and a plot of the joint probability distribution P(C1, C2) can be found here.

(Changed: 20 Jun 2024)  | 
Zum Seitananfang scrollen Scroll to the top of the page