Beispiel #1
0
 def test_update_M_inv(self):
     data = np.array([[1, 3], [1, 6]])
     mixture = PCAMixture(data, 1, 2)
     model = PCAModel(mixture, 2)
     model.var = 3
     model.W = np.array([[1, 2], [2, 1], [1, 3]])
     model.update_M_inv()
     M_inv = np.array([[17, -7], [-7, 9]]) / 104
     res = np.isclose(model.M_inv, M_inv)
     self.assertTrue(res.all())
Beispiel #2
0
    def test_set_C_det(self):
        data = np.array([[1, 3], [1, 6]])
        var = 2
        W = np.array([[2, 3], [1, 0], [2, 1]])
        mixture = PCAMixture(data, 1, 2)
        model = PCAModel(mixture, 2)
        model.var = var
        model.W = W
        model.set_C_det()
        C_det = 136

        self.assertAlmostEqual(model.C_det, C_det)
Beispiel #3
0
    def test_set_var(self):
        S = np.array([[0, 0], [0, 2]])

        data = np.array([[1, 3], [1, 6]])
        mixture = PCAMixture(data, 1, 2)
        model = PCAModel(mixture, 2)
        model.S = S
        W_old = np.array([[1, 1], [3, 2]])
        M_inv_old = np.array([[17, -7], [-7, 9]]) / 104
        model.W = np.array([[0, 0], [104 / 87, 208 / 261]])

        model.set_var(W_old, M_inv_old)

        self.assertAlmostEqual(model.var, 52 / 87)
Beispiel #4
0
    def test_set_C_inv(self):
        data = np.array([[1, 3], [1, 6]])
        M_inv = np.array([[17, -7], [-7, 9]]) / 104
        W = np.array([[0, 0], [104 / 87, 208 / 261]])
        var = 1 + 2 / 87
        mixture = PCAMixture(data, 1, 2)
        model = PCAModel(mixture, 2)
        model.M_inv = M_inv
        model.W = W
        model.var = var

        model.set_C_inv()

        C_inv = np.array([[1, 0], [0, 19067 / 22707]]) / var

        res = np.isclose(model.C_inv, C_inv)
        self.assertTrue(res.all())
Beispiel #5
0
    def test_set_W(self):
        S = np.array([[0, 0], [0, 2]])
        M_inv = np.array([[17, -7], [-7, 9]]) / 104
        W = np.array([[1, 1], [3, 2]])

        data = np.array([[1, 3], [1, 6]])
        mixture = PCAMixture(data, 1, 2)
        model = PCAModel(mixture, 2)
        model.var = 3
        model.S = S
        model.M_inv = M_inv
        model.W = W

        model.set_W()
        new_W = model.W

        #print(new_W)

        res = np.isclose(new_W, np.array([[0, 0], [104 / 87, 208 / 261]]))
        self.assertTrue(res.all())