示例#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)