def setup_class(cls): covx = np.array([[1.0, 0.5], [0.5, 1.0]]) mu3 = [-1, 0., 2.] cov3 = np.array([[1., 0.5, 0.75], [0.5, 1.5, 0.6], [0.75, 0.6, 2.]]) cls.mu3 = mu3 cls.cov3 = cov3 mvn3 = MVNormal(mu3, cov3) mvn3c = MVNormal(np.array([0, 0, 0]), cov3) cls.mvn3 = mvn3 cls.mvn3c = mvn3c
def __init__(self): covx = np.array([[1.0, 0.5], [0.5, 1.0]]) mu3 = [-1, 0., 2.] cov3 = np.array([[ 1. , 0.5 , 0.75], [ 0.5 , 1.5 , 0.6 ], [ 0.75, 0.6 , 2. ]]) self.mu3 = mu3 self.cov3 = cov3 mvn3 = MVNormal(mu3, cov3) mvn3c = MVNormal(np.array([0,0,0]), cov3) self.mvn3 = mvn3 self.mvn3c = mvn3c
def test_mvn_pdf(self): cov3 = self.cov3 mvn3 = self.mvn3 mvn3c = self.mvn3c r_val = [-7.667977543898155, -6.917977543898155, -5.167977543898155] assert_array_almost_equal( mvn3.logpdf(cov3), r_val, decimal = 14) #decimal 18 r_val = [0.000467562492721686, 0.000989829804859273, 0.005696077243833402] assert_array_almost_equal( mvn3.pdf(cov3), r_val, decimal = 17) #cheating new mean, same cov, too dangerous, got wrong instance in tests #mvn3.mean = np.array([0,0,0]) mvn3b = MVNormal(np.array([0,0,0]), cov3) r_val = [0.02914269740502042, 0.02269635555984291, 0.01767593948287269] assert_array_almost_equal( mvn3b.pdf(cov3), r_val, decimal = 16)
def test_mvn_pdf(self): cov3 = self.cov3 mvn3 = self.mvn3 r_val = [-7.667977543898155, -6.917977543898155, -5.167977543898155] assert_allclose(mvn3.logpdf(cov3), r_val, rtol=1e-13) r_val = [ 0.000467562492721686, 0.000989829804859273, 0.005696077243833402 ] assert_allclose(mvn3.pdf(cov3), r_val, rtol=1e-13) mvn3b = MVNormal(np.array([0, 0, 0]), cov3) r_val = [0.02914269740502042, 0.02269635555984291, 0.01767593948287269] assert_allclose(mvn3b.pdf(cov3), r_val, rtol=1e-13)
def test_mvn_pdf(self): cov3 = self.cov3 mvn3 = self.mvn3 mvn3c = self.mvn3c r_val = [-7.667977543898155, -6.917977543898155, -5.167977543898155] assert_array_almost_equal( mvn3.logpdf(cov3), r_val, decimal = 14) #decimal 18 r_val = [0.000467562492721686, 0.000989829804859273, 0.005696077243833402] assert_array_almost_equal( mvn3.pdf(cov3), r_val, decimal = 17) #cheating new mean, same cov, too dangerous, got wrong instance in tests #mvn3.mean = np.array([0,0,0]) mvn3b = MVNormal(np.array([0,0,0]), cov3) r_val = [0.02914269740502042, 0.02269635555984291, 0.01767593948287269] assert_array_almost_equal( mvn3b.pdf(cov3), r_val, decimal = 16)
def gen_data(mu, cov, n, lowd, highd): lams = MVNormal(mu, cov).rvs(n) ps = np.empty_like(lams) ps = di.poisson.rvs( di.uniform.rvs(lowd, highd - lowd, size=lams.shape) * np.exp(lams)) return ps