예제 #1
0
    def test_project_weighting_operation(self):
        test_cases = [(self.m1, self.m3,
                       np.array([[0.69314718,0,0]])),
                      (self.m2, self.m4, np.array([[0]]))]
        w = PpmiWeighting()
        for (core_mat, per_mat, expected_mat) in test_cases:
            op = ScalingOperation(w)
            tmp_mat = per_mat.copy()

            self.assertRaises(IllegalStateError, op.project,
                              DenseMatrix(per_mat))

            op.apply(DenseMatrix(core_mat))
            out_mat = op.project(DenseMatrix(per_mat)).mat
            np.testing.assert_array_almost_equal(expected_mat, out_mat, 7)
            np.testing.assert_array_equal(per_mat, tmp_mat)

            out_mat = op.project(DenseMatrix(per_mat)).mat
            np.testing.assert_array_almost_equal(expected_mat, out_mat, 7)
예제 #2
0
 def test_apply_weighting_operation(self):
     test_cases = [(self.m1, np.array([[0,0,0]])),
                   (self.m2, np.array([[0]]))]
     w = PpmiWeighting()
     for in_mat, expected_mat in test_cases:
         op = ScalingOperation(w)
         tmp_mat = in_mat.copy()
         out_mat = op.apply(DenseMatrix(in_mat)).mat
         np.testing.assert_array_almost_equal(expected_mat, out_mat, 7)
         np.testing.assert_array_equal(in_mat, tmp_mat)
         self.assertRaises(IllegalStateError, op.apply, DenseMatrix(in_mat))