Пример #1
0
    def test_project_dimensionality_reduction(self):

        test_cases =[(self.x, self.us)]
        red = Svd(2)

        for in_mat, expected_us_mat in test_cases:
            op = DimensionalityReductionOperation(red)
            tmp_mat = in_mat.copy()

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

            op.apply(DenseMatrix(in_mat)).mat
            out_proj_mat = op.project(DenseMatrix(in_mat)).mat
            np.testing.assert_array_almost_equal(expected_us_mat, out_proj_mat, 2)

            np.testing.assert_array_equal(in_mat, tmp_mat)

            self.assertRaises(IllegalStateError, op.apply, SparseMatrix(in_mat))

            out_proj_mat2 = op.project(DenseMatrix(in_mat)).mat
            np.testing.assert_array_almost_equal(expected_us_mat, out_proj_mat2, 2)
Пример #2
0
    def test_project_dimensionality_reduction_nmf(self):

        test_cases = [self.xnmf]
        red = Nmf(2)

        for in_mat in test_cases:
            d_in_mat = DenseMatrix(in_mat)
            op = DimensionalityReductionOperation(red)
            tmp_mat = in_mat.copy()

            self.assertRaises(IllegalStateError, op.project, d_in_mat)

            out_core_mat = op.apply(d_in_mat).mat
            out_proj_mat = op.project(d_in_mat).mat
            np.testing.assert_array_almost_equal(out_proj_mat, out_core_mat, 5)

            np.testing.assert_array_equal(in_mat, tmp_mat)

            self.assertRaises(IllegalStateError, op.apply, d_in_mat)

            out_proj_mat2 = op.project(d_in_mat).mat
            np.testing.assert_array_almost_equal(out_proj_mat2, out_core_mat, 5)