SHARE
TWEET

Untitled

a guest May 23rd, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2.  
  3. def make_env(p_x):
  4.   x = np.random.binomial(1, p_x, size=100*1000)
  5.   y = np.logical_xor(x, np.random.binomial(1, 0.25, size=100*1000))
  6.   return (x, y)
  7.  
  8. def p_x_given_y(env):
  9.   xy = zip(*env)
  10.   x_given_y = [x for x,y in xy if y]
  11.   return np.mean(x_given_y)
  12.  
  13. env1 = make_env(0.5)
  14. env2 = make_env(0.9)
  15.  
  16. print(p_x_given_y(env1)) # 0.7512315762181137
  17. print(p_x_given_y(env2)) # 0.9634053658746433
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top