Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- def make_env(p_x):
- x = np.random.binomial(1, p_x, size=100*1000)
- y = np.logical_xor(x, np.random.binomial(1, 0.25, size=100*1000))
- return (x, y)
- def p_x_given_y(env):
- xy = zip(*env)
- x_given_y = [x for x,y in xy if y]
- return np.mean(x_given_y)
- env1 = make_env(0.5)
- env2 = make_env(0.9)
- print(p_x_given_y(env1)) # 0.7512315762181137
- print(p_x_given_y(env2)) # 0.9634053658746433
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement