title: Posterior Probability python example
body: <p>I've been building a simple Approximate Bayes Calculation application and ran into a problem. I don't know how to properly implement <a href="https://en.wikipedia.org/wiki/Posterior_probability" rel="nofollow noreferrer">posterior probability</a>.</p>
  
  <p>My prior: non-informative (uniform distribution)</p>
  
  <p>Generative model: random yes/no guessing implemented using numpy binomial distribution</p>
  
  <p>Here is the code:</p>
  
  <pre><code>import numpy as np
  import pandas as pd
  
  def pprob():
      pass
  
  def generative_model(n_events, p):
      return np.random.binomial(n_events, p)
  
  def ABC(n_occured, n_events, n_draws=100000):
      prior = pd.Series(np.random.uniform(0, 1, size=n_draws))
      sim_data = [generative_model(n_events, p) for p in prior]
      posterior = prior[list(map(lambda x: x == n_occured, sim_data))]
      posterior_probability = pprob()
  
  ABC(10, 16)
  </code></pre>
  
  <p>Thanks in advance!</p>