Example #1
0
    def test_train_exact(self):
        test_cases = [(self.m11, self.m21, self.ph1, 5 / (3.0)),
                      (self.m12, self.m22, self.ph2, 5 / (3.0)),
                      (self.m13, self.m23, self.ph3, 6),
                      (self.m14, self.m24, self.ph4, 6),
                      (self.m15, self.m25, self.ph5, 5 / (3.0)),
                      (self.m16, self.m26, self.ph6, 2),
                      (self.m17, self.m27, self.ph7, 2)]

        for arg1, arg2, phrase, lambda_ in test_cases:
            m = Dilation()
            m._train(arg1, arg2, phrase)
            self.assertAlmostEqual(m._lambda, lambda_)
Example #2
0
 def test_train_exact(self):
     test_cases = [(self.m11, self.m21, self.ph1, 5 / (3.0)),
                   (self.m12, self.m22, self.ph2, 5 / (3.0)),
                   (self.m13, self.m23, self.ph3, 6),
                   (self.m14, self.m24, self.ph4, 6),
                   (self.m15, self.m25, self.ph5, 5 / (3.0)),
                   (self.m16, self.m26, self.ph6, 2),
                   (self.m17, self.m27, self.ph7, 2)
                   ]
     
     for arg1, arg2, phrase, lambda_ in test_cases:
         m = Dilation()
         m._train(arg1, arg2, phrase)
         self.assertAlmostEqual(m._lambda, lambda_)
Example #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._train(DenseMatrix(m1), DenseMatrix(m2), result_p)
            self.assertAlmostEqual(lambda_, m._lambda)
Example #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)
Example #5
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)
Example #6
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)