title: Metropolis Sampling
body: <p>I'm working through a book called <a href="https://rads.stackoverflow.com/amzn/click/com/1785883801" rel="nofollow noreferrer" rel="nofollow noreferrer">Bayesian Analysis in Python</a>. The book focuses heavily on the package PyMC3 but is a little vague on the theory behind it so I'm quite confused.</p>
  
  <p>Say I have data like this:</p>
  
  <pre><code>data = np.array([51.06, 55.12, 53.73, 50.24, 52.05, 56.40, 48.45, 52.34, 55.65, 51.49, 51.86, 63.43, 53.00, 56.09, 51.93, 52.31, 52.33, 57.48, 57.44, 55.14, 53.93, 54.62, 56.09, 68.58, 51.36, 55.47, 50.73, 51.94, 54.95, 50.39, 52.91, 51.5, 52.68, 47.72, 49.73, 51.82, 54.99, 52.84, 53.19, 54.52, 51.46, 53.73, 51.61, 49.81, 52.42, 54.3, 53.84, 53.16]) 
  </code></pre>
  
  <p>And I'm looking at a model like this:</p>
  
  <p><a href="https://i.stack.imgur.com/jWom1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jWom1.png" alt="enter image description here"></a></p>
  
  <p>Using <a href="https://en.wikipedia.org/wiki/Metropolis%E2%80%93Hastings_algorithm" rel="nofollow noreferrer">Metropolis Sampling</a>,
  how can I fit a model that estimates mu and sigma.</p>
  
  <p>Here is my guess at pseudo-code from what I've read:</p>
  
  <pre><code>M, S = 50, 1
  G = 1
  
  # These are priors right?
  mu = stats.norm(loc=M, scale=S)
  sigma = stats.halfnorm(scale=G)
  
  target = stats.norm
  
  steps = 1000
  
  mu_samples = [50]
  sigma_samples = [1]
  
  for i in range(steps):
      # proposed sample...
      mu_i, sigma_i = mu.rvs(), sigma.rvs()
  
      # Something happens here
      # How do I calculate the likelidhood??
      "..."
      # some evaluation of a likelihood ratio??
  
      a = "some"/"ratio"
  
      acceptance_bar = np.random.random()
  
      if a &gt; acceptance_bar:
          mu_samples.append(mu_i)
          sigma_samples.append(sigma_i)
  </code></pre>
  
  <p>What am I missing??</p>