def test_log_likelihood2(self): data = np.random.randn(1000, 600) mu = np.random.randn(600) sigmas = np.random.uniform(1, 2, size=600) d = distributions.DiagonalGaussian(mu=mu, sigmas=sigmas) pdf1 = d.log_likelihood(data) import scipy.stats as stats pdf2 = stats.norm.logpdf(data, loc=mu, scale=np.sqrt(sigmas)).sum(1) assert np.allclose(pdf1, pdf2)
np.seterr(invalid='raise') from matplotlib import pyplot as plt import copy from pybasicbayes import models, distributions from pybasicbayes.util.text import progprint_xrange alpha_0 = 5.0 obs_hypparams = dict(mu_0=np.zeros(2), alphas_0=2 * np.ones(2), betas_0=np.ones(2), nus_0=0.1 * np.ones(2)) priormodel = models.Mixture(alpha_0=alpha_0, components=[ distributions.DiagonalGaussian(**obs_hypparams) for itr in range(30) ]) data, _ = priormodel.generate(500) data2, _ = priormodel.generate(500) del priormodel posteriormodel = models.Mixture( alpha_0=alpha_0, components=[ distributions.DiagonalGaussian(**obs_hypparams) for itr in range(30) ]) posteriormodel.add_data(data)