# Runs the naive estimator
import random;
# Variables and probabilities
p = { 'X1': 0.9, 'X2': 0.8, 'Y1': 0.85, 'Y2': 0.75, 'Y3': 0.65 }
# The lineage formula
def phi(theta):
return (
(theta['X1'] and theta['Y1'])
or (theta['X1'] and theta['Y2'])
or (theta['X2'] and theta['Y3'])
)
# Number of MC steps to run
n = 10000
# Array of results
Z = []
# Current valuation (initialized empty)
theta = { }
# Run MC
for k in range(n):
# generate theta
for var,pvar in p.iteritems():
theta[var] = random.random() < pvar
# evaluate the formula
Z.append(phi(theta))
# print information about current step
print 'k : ', k+1
print 'theta_k: ', theta
print 'Z_k : ', Z[k]
print 'phat : ', 1./(k+1)*sum(Z)
print '---'