code: def reject_sv(m, s, y):
      
      mp = m + 0.5 * s**2 * (-1. + y**2 * np.exp(-m))
      ntries = 0
      while True:
          ntries += 1
          x = stats.norm.rvs(loc=mp, scale=s)
          u = stats.uniform.rvs()
          if np.log(u) < - 0.5 * y**2 * (np.exp(-x) - np.exp(-m) * (1. + m - x)):
              break
          if ntries > 1000:
              print('1000 failed attempt, m,s,y=%f, %f, %f' % (m, s, y))
              break
      return x
docs: Sample from N(m, s^2) times SV likelihood using rejection. 
  
      SV likelihood (in x) corresponds to y ~ N(0, exp(x)).