class_docstr: Unit test for posterior sampling with Gaussian likelihood and Gaussian prior
class_docstr_tok: ["Unit","test","for","posterior","sampling","with","Gaussian","likelihood","and","Gaussian","prior"]
docstr: Tests posterior estimation using Slice sampling 
docstr_tok: ["Tests","posterior","estimation","using","Slice","sampling"]
code: def test_posterior_Slice(self):
      """Tests posterior estimation using Slice sampling"""
      self.report(
          "Test posterior estimation with Gaussian likelihood and Gaussian prior "
          "using Slice sampling"
      )
  
      model_a = Model(self._pdf, self._logp, self._grad_logp)
      samples = model_a.draw_samples(
          "slice", self.size, np.array([4.5])
      )
  
      avg = 0
      for i in range(len(self.data)):
          avg = avg + self.data[i]
      avg = avg / len(self.data)
  
      # Map estimation
      val = self.var / len(self.data)
      mean_a = (self.tau * avg) / (self.tau + val) + self.m * (
          val / (self.tau + val)
      )
      var_a = (val * self.tau) / (self.tau + val)
  
      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.py
imports: from __future__ import absolute_import
  from __future__ import division
  import unittest
  import numpy
  from .continuous import Normal
  from .model import Model
  from ..utils.base_test_class import BaseTestClass, execute_tests
label_desc: Use image node_id 9 for calling the PosteriorTestCase obj's underlying member method code with example usage: obj.test_posterior_Slice() without return types