def test_poisson_loglikelihood(self): l = 4.2 poisson = Poisson(l) samples = poisson.sample(100) loglik0 = stats.poisson.logpmf(samples, l) loglik1 = poisson.loglikelihood(samples) self.assertLess(max(abs(loglik0 - loglik1)), 1e-8)
def test_poisson_pickle(self): tmp_file = mkstemp()[1] p0 = Poisson(2.5) with open(tmp_file, 'w') as handle: dump({'p': p0}, handle) with open(tmp_file) as handle: p1 = load(handle)['p'] x = p0.sample(100) self.assertLess(max(abs(p0.loglikelihood(x) - p1.loglikelihood(x))), 1e-6)