def test_calculate_cca_copy(self):
     """caluclate_cca must not modify argument."""
     cpy_x = self.dat_x.copy()
     cpy_y = self.dat_y.copy()
     calculate_cca(self.dat_x, self.dat_y)
     self.assertEqual(self.dat_x, cpy_x)
     self.assertEqual(self.dat_y, cpy_y)
Exemple #2
0
 def test_calculate_cca_copy(self):
     """caluclate_cca must not modify argument."""
     cpy_x = self.dat_x.copy()
     cpy_y = self.dat_y.copy()
     calculate_cca(self.dat_x, self.dat_y)
     self.assertEqual(self.dat_x, cpy_x)
     self.assertEqual(self.dat_y, cpy_y)
 def test_calculate_cca_swapaxes(self):
     """caluclate_cca must work with nonstandard timeaxis."""
     res1 = calculate_cca(swapaxes(self.dat_x, 0, 1), swapaxes(self.dat_y, 0, 1), timeaxis=1)
     res2 = calculate_cca(self.dat_x, self.dat_y)
     np.testing.assert_array_equal(res1[0], res2[0])
     np.testing.assert_array_equal(res1[1], res2[1])
     np.testing.assert_array_equal(res1[2], res2[2])
Exemple #4
0
 def test_calculate_cca_swapaxes(self):
     """caluclate_cca must work with nonstandard timeaxis."""
     res1 = calculate_cca(swapaxes(self.dat_x, 0, 1), swapaxes(self.dat_y, 0, 1), timeaxis=1)
     res2 = calculate_cca(self.dat_x, self.dat_y)
     np.testing.assert_array_equal(res1[0], res2[0])
     np.testing.assert_array_equal(res1[1], res2[1])
     np.testing.assert_array_equal(res1[2], res2[2])
 def test_raise_error_with_non_continuous_data(self):
     """Raise error if ``dat_x`` is not continuous Data object."""
     dat = Data(randn(2, self.SAMPLES, self.CHANNELS_X),
                axes=[[0, 1], self.dat_x.axes[0], self.dat_x.axes[1]],
                names=['class', 'time', 'channel'],
                units=['#', 'ms', '#'])
     with self.assertRaises(AssertionError):
         calculate_cca(dat, self.dat_x)
Exemple #6
0
 def test_raise_error_with_non_continuous_data(self):
     """Raise error if ``dat_x`` is not continuous Data object."""
     dat = Data(randn(2, self.SAMPLES, self.CHANNELS_X),
                axes=[[0, 1], self.dat_x.axes[0], self.dat_x.axes[1]],
                names=['class', 'time', 'channel'],
                units=['#', 'ms', '#'])
     with self.assertRaises(AssertionError):
         calculate_cca(dat, self.dat_x)
    def test_diff_between_canonical_variables(self):
        """Test if the scaled canonical variables are almost same."""
        rho, w_x, w_y = calculate_cca(self.dat_x, self.dat_y)
        cv_x = apply_spatial_filter(self.dat_x, w_x)
        cv_y = apply_spatial_filter(self.dat_y, w_y)

        def scale(x):
            tmp = x.data - x.data.mean()
            return tmp / tmp[np.argmax(np.abs(tmp))]

        diff = scale(cv_x) - scale(cv_y)
        diff = np.sum(np.abs(diff)) / self.SAMPLES
        self.assertTrue(diff < 0.1)
Exemple #8
0
    def test_diff_between_canonical_variables(self):
        """Test if the scaled canonical variables are almost same."""
        rho, w_x, w_y = calculate_cca(self.dat_x, self.dat_y)
        cv_x = np.dot(self.X, w_x)
        cv_y = np.dot(self.Y, w_y)

        def scale(x):
            tmp = x - x.mean()
            return tmp / tmp[np.argmax(np.abs(tmp))]

        diff = scale(cv_x) - scale(cv_y)
        diff = np.sum(np.abs(diff)) / self.SAMPLES
        self.assertTrue(diff < 0.1)
 def test_raise_error_with_different_length_data(self):
     """Raise error if the length of ``dat_x`` and ``dat_y`` is different."""
     dat = append(self.dat_x, self.dat_x)
     with self.assertRaises(AssertionError):
         calculate_cca(dat, self.dat_y)
Exemple #10
0
 def test_rho(self):
     """Test if the canonical correlation coefficient almost equals 1."""
     rho, w_x, w_y = calculate_cca(self.dat_x, self.dat_y)
     self.assertAlmostEqual(rho, 1.0, delta=0.01)
Exemple #11
0
 def test_raise_error_with_different_length_data(self):
     """Raise error if the length of ``dat_x`` and ``dat_y`` is different."""
     dat = append(self.dat_x, self.dat_x)
     with self.assertRaises(AssertionError):
         calculate_cca(dat, self.dat_y)
Exemple #12
0
 def test_rho(self):
     """Test if the canonical correlation coefficient almost equals 1."""
     rho, w_x, w_y = calculate_cca(self.dat_x, self.dat_y)
     self.assertAlmostEqual(rho, 1.0, delta=0.01)