def setUp(self): particles = np.array([ [1., 2., 23.67, 0.], [2., 4., 23.67, 1.], [3., 6., 23.67, 3.], [4., 8., 23.67, 6.], ]) self.emp = pb.EmpPdf(particles)
def test_shape(self): # there were an error where EmpPdf returned nr of particles, so we use # different data-set to detect such error particles = np.array([ [1., 2.], [2., 4.], [3., 6.], [4., 8.], ]) emp = pb.EmpPdf(particles) self.assertEqual(emp.shape(), 2)
def test_sample(self): """Test LogNormPdf.sample() mean and variance.""" N = 500 # number of samples samples = np.log(self.lognorm.samples(N)) # note the logarithm emp = pb.EmpPdf( samples) # Emipirical pdf computes sample mean and variance for us mean, fuzz = 2., 0.2 self.assertTrue(np.all(abs(emp.mean() - mean) <= fuzz)) var, fuzz = 0.3, 0.1 self.assertTrue(np.all(abs(emp.variance() - var) <= fuzz))
def test_sample_multi(self): """Test GaussPdf.sample() mean and variance (multivariate case).""" N = 500 mean = np.array([124.6, -1.5]) cov = np.array([[0.7953, 0.], [0., 1.7]]) samples = pb.GaussPdf(mean, cov).samples(N) emp = pb.EmpPdf(samples) self.assertAlmostEqual(np.max(abs(emp.mean() - mean)), 0., delta=0.2) self.assertAlmostEqual(np.max(abs(emp.variance() - cov.diagonal())), 0., delta=0.3)
def test_sample(self): """Test GaussPdf.sample() mean and variance.""" N = 1000 # number of samples, variance is very sensible here emp1 = pb.EmpPdf(self.gamma1.samples( N)) # Emipirical pdf computes sample mean and variance for us emp2 = pb.EmpPdf(self.gamma2.samples( N)) # Emipirical pdf computes sample mean and variance for us self.assertAlmostEqual(np.max(abs(emp1.mean() - self.gamma1.mean())), 0., delta=0.4) self.assertAlmostEqual(np.max(abs(emp2.mean() - self.gamma2.mean())), 0., delta=0.033) self.assertAlmostEqual(np.max( abs(emp1.variance() - self.gamma1.variance())), 0., delta=34.0) self.assertAlmostEqual(np.max( abs(emp2.variance() - self.gamma2.variance())), 0., delta=0.06)
def test_sample(self): """Test GaussPdf.sample() mean and variance.""" N = 500 # number of samples emp1 = pb.EmpPdf(self.gamma1.samples( N)) # Emipirical pdf computes sample mean and variance for us emp2 = pb.EmpPdf(self.gamma2.samples( N)) # Emipirical pdf computes sample mean and variance for us self.assertAlmostEqual(np.max(abs(emp1.mean() - self.gamma1.mean())), 0., delta=0.4) self.assertAlmostEqual(np.max(abs(emp2.mean() - self.gamma2.mean())), 0., delta=0.35) self.assertAlmostEqual(np.max( abs(emp1.variance() - self.gamma1.variance())), 0., delta=3.0) self.assertAlmostEqual(np.max( abs(emp2.variance() - self.gamma2.variance())), 0., delta=1.4)
def test_sample_uni(self): """Test GaussPdf.sample() mean and variance (univariate case).""" N = 500 mean = np.array([124.6]) cov = np.array([[0.7953]]) samples = pb.GaussPdf(mean, cov).samples(N) emp = pb.EmpPdf(samples) fuzz = 0.2 self.assertTrue(np.all(abs(emp.mean() - mean) <= fuzz)) var, fuzz = cov.diagonal(), 0.2 self.assertTrue(np.all(abs(emp.variance() - var) <= fuzz))
def test_sample(self): """Test GaussCPdf.sample() mean and variance.""" N = 500 # number of samples samples = self.cgauss.samples(N, self.cond) emp = pb.EmpPdf( samples) # Emipirical pdf computes sample mean and variance for us fuzz = np.array([0.3, 0.3]) mean = self.cgauss.mean(self.cond) self.assertTrue(np.all(abs(emp.mean() - mean) <= fuzz)) var = self.cgauss.variance(self.cond) self.assertTrue(np.all(abs(emp.variance() - var) <= fuzz))