def test_str(self): p = JointNormal(labels=['x', 'y'], mu=[0, 0], cov=[[1e-19, 1e-19], [1e-19, 1e-19]]) p.ingest(self.df) s = str(p) self.assertTrue('N' in s) self.assertTrue('x' in s) self.assertTrue('x' in s)
def test_cov(self): p = JointNormal(labels=['x', 'y']) p.ingest(self.df) self.assertAlmostEqual(p.cov[0, 0], self.cov[0, 0]) self.assertAlmostEqual(p.cov[1, 1], self.cov[1, 1]) self.assertAlmostEqual(p.cov[1, 0], self.cov[1, 0]) self.assertAlmostEqual(p.cov[0, 1], self.cov[0, 1]) self.assertAlmostEqual(self.N, p.N)
def test_list_input(self): p = JointNormal(labels=['x', 'y'], mu=[0, 0], cov=[[1e-19, 1e-19], [1e-19, 1e-19]]) df = self.df[['y', 'x']] p.ingest(df) mu, cov, N = p.mu_cov_n self.assertAlmostEqual(p.mu[0, 0], self.mu[0]) self.assertAlmostEqual(p.mu[1, 0], self.mu[1]) self.assertEqual(tuple(cov.shape), (2, 2)) self.assertEqual(N, len(self.df))
def test_array_input(self): p = JointNormal(labels=['x', 'y'], mu=np.array([0, 0]), cov=np.array([[1e-19, 1e-19], [1e-19, 1e-19]])) p.ingest(self.df) self.assertAlmostEqual(p.mu[0, 0], self.mu[0]) self.assertAlmostEqual(p.mu[1, 0], self.mu[1])
def test_list_input_bad_frame(self): p = JointNormal(labels=['a', 'b'], mu=[0, 0], cov=[[1e-19, 1e-19], [1e-19, 1e-19]]) with self.assertRaises(ValueError): p.ingest(self.df)
def test_n_limit(self): p = JointNormal(labels=['x', 'y'], n_max=5) p.ingest(self.df.values) self.assertAlmostEqual(5, p.N)
def test_numpy_bad_input(self): p = JointNormal(labels=['x', 'y']) self.df['z'] = self.df.x with self.assertRaises(ValueError): p.ingest(self.df.values)
def test_numpy_input(self): p = JointNormal(labels=['x', 'y']) p.ingest(self.df.values) self.assertAlmostEqual(p.mu[0, 0], self.mu[0]) self.assertAlmostEqual(p.mu[1, 0], self.mu[1]) self.assertAlmostEqual(self.N, p.N)
def test_mean(self): p = JointNormal(labels=['x', 'y']) p.ingest(self.df) self.assertAlmostEqual(p.mu[0, 0], self.mu[0]) self.assertAlmostEqual(p.mu[1, 0], self.mu[1]) self.assertAlmostEqual(self.N, p.N)