Пример #1
0
	def test_binomial_loglikelihood(self):
		n = 17
		p = .9

		binomial = Binomial(n, p)

		samples = binomial.sample(100)

		loglik0 = stats.binom.logpmf(samples, n, p)
		loglik1 = binomial.loglikelihood(samples)

		self.assertLess(max(abs(loglik0 - loglik1)), 1e-8)
Пример #2
0
	def test_binomial_pickle(self):
		tmp_file = mkstemp()[1]

		p0 = Binomial(13, .76)

		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)