예제 #1
0
    def test_compose_exact(self):

        test_cases = [(self.m11, self.m21, self.ph1, 5 / (3.0)),
                      (self.m13, self.m23, self.ph3, 6),
                      (self.m14, self.m24, self.ph4, 6)]
        for arg1, arg2, phrase, lambda_ in test_cases:

            m = Dilation()
            m._solve(arg1, arg2, phrase)
            res = m._compose(arg1, arg2)
            np.testing.assert_array_almost_equal(res.mat, phrase.mat, 2)

            m = Dilation(lambda_)
            res = m._compose(arg1, arg2)
            np.testing.assert_array_almost_equal(res.mat, phrase.mat, 2)
예제 #2
0
 def test_compose_exact(self):
     
     test_cases = [(self.m11, self.m21, self.ph1, 5 / (3.0)),
                   (self.m13, self.m23, self.ph3, 6),
                   (self.m14, self.m24, self.ph4, 6)
                   ]
     for arg1, arg2, phrase, lambda_ in test_cases:
         
         m = Dilation()
         m._train(arg1, arg2, phrase)
         res = m._compose(arg1, arg2)
         np.testing.assert_array_almost_equal(res.mat, phrase.mat, 2)
         
         m = Dilation(lambda_)
         res = m._compose(arg1, arg2)
         np.testing.assert_array_almost_equal(res.mat, phrase.mat, 2)
예제 #3
0
    def test_train_random(self):
        test_cases = [1.0, 2.0, 3.0]
        rows = 4
        cols = 3
        m1 = np.random.rand(rows, cols)
        m2 = np.random.rand(rows, cols)

        for lambda_ in test_cases:
            m = Dilation(lambda_)
            result_p = m._compose(DenseMatrix(m1), DenseMatrix(m2))

            m = Dilation()
            m._solve(DenseMatrix(m1), DenseMatrix(m2), result_p)
            self.assertAlmostEqual(lambda_, m._lambda)
예제 #4
0
 def test_train_random(self):
     test_cases = [1.0,2.0,3.0]
     rows = 4
     cols = 3
     m1 = np.random.rand(rows,cols)
     m2 = np.random.rand(rows,cols)
     
     
     for lambda_ in test_cases:
         m = Dilation(lambda_)
         result_p = m._compose(DenseMatrix(m1), DenseMatrix(m2))
         
         m = Dilation()
         m._train(DenseMatrix(m1),DenseMatrix(m2),result_p)
         self.assertAlmostEqual(lambda_, m._lambda)