class_docstr: Unit test for posterior sampling with Bernoulli likelihood and Beta prior
class_docstr_tok: ["Unit","test","for","posterior","sampling","with","Bernoulli","likelihood","and","Beta","prior"]
docstr: Tests posterior estimation using NUTS sampling 
docstr_tok: ["Tests","posterior","estimation","using","NUTS","sampling"]
code: def test_posterior_NUTS(self):
      """Tests posterior estimation using NUTS sampling"""
      self.report(
          "Test posterior estimation with Bernoulli likelihood and Beta prior "
          "using NUTS sampling"
      )
  
      model_a = Model(self._pdf, self._logp, self._grad_logp)
      samples = model_a.draw_samples(
          "nuts", self.size, np.array([0.1]), 10
      )
  
      # Map estimation
      alpha_a = self.Y + self.alpha
      beta_a = self.n - self.Y + self.beta
      mean_a = alpha_a / float(alpha_a + beta_a)
      var_a = (alpha_a * beta_a) / (
          (np.power(alpha_a + beta_a, 2)) * (alpha_a + beta_a + 1)
      )
  
      mean_r = self._compute_mean(samples)
      var_r = self._compute_variance(samples)
  
      self._check_sample_sizes(samples)
      assert abs(mean_a - mean_r) <= self.threshold
      assert abs(var_a - var_r) <= self.threshold
      self.report(
          "Map Estimation: mean=%0.3f, variance=%0.3f :: test result: mean=%0.3f, "
          "variance=%0.3f" % (mean_a, var_a, mean_r, var_r),
          "test_result",
      )
  
file_path: dragonfly/dragonfly/distributions/unittest_posterior_mixed.py
imports: from __future__ import absolute_import
  from __future__ import division
  import unittest
  import numpy
  from .continuous import Beta
  from .model import Model
  from ..utils.base_test_class import BaseTestClass, execute_tests
label_desc: Use image node_id 8 for calling the PosteriorMixedTestCase obj's underlying member method code with example usage: obj.test_posterior_NUTS() without return types