class_docstr: Tests for the default SMC kernel
class_docstr_tok: ["Tests","for","the","default","SMC","kernel"]
docstr: Verifies that the log marginal likelihood function
  can be correctly computed for a Beta-Bernoulli model.
docstr_tok: ["Verifies","that","the","log","marginal","likelihood","function","can","be","correctly","computed","for","a","Beta-Bernoulli","model","."]
code: def test_marginal_likelihood(self):
      """
      Verifies that the log marginal likelihood function
      can be correctly computed for a Beta-Bernoulli model.
      """
      data = np.repeat([1, 0], [50, 50])
      marginals = []
      a_prior_0, b_prior_0 = 1.0, 1.0
      a_prior_1, b_prior_1 = 20.0, 20.0
  
      for alpha, beta in (
          (a_prior_0, b_prior_0),
          (a_prior_1, b_prior_1),
      ):
          with pm.Model() as model:
              a = pm.Beta("a", alpha, beta)
              y = pm.Bernoulli("y", a, observed=data)
              trace = pm.sample_smc(
                  2000,
                  chains=2,
                  return_inferencedata=False,
                  progressbar=not _IS_WINDOWS,
              )
          # log_marginal_likelihood is found in the last value of each chain
          lml = np.mean(
              [
                  chain[-1]
                  for chain in trace.report.log_marginal_likelihood
              ]
          )
          marginals.append(lml)
  
      # compare to the analytical result
      assert abs(np.exp(marginals[1] - marginals[0]) - 4.0) <= 1
  
imports: import logging
  import platform
  import warnings
  import numpy
  import pytensor.tensor
  import pytest
  import scipy.stats
  from arviz.data.inference_data import InferenceData
  import pymc
  from pymc.backends.base import MultiTrace
  from pymc.pytensorf import floatX
  from pymc.smc.kernels import IMH, systematic_resampling
  from tests.helpers import assert_random_state_equal
label_desc: Use image node_id 6 for calling the TestSMC obj's underlying member method code with example usage: obj.test_marginal_likelihood() without return types