Beispiel #1
0
 def test_dcor_independence(self):
     """Test the dCor method with independent criteria."""
     z_matrix = np.array([[0.0, 0.0], [0.0, 1.0]], dtype=np.float64)
     obtained_corr_matrix = mcdm.correlate(z_matrix, "dCor")
     expected_corr_matrix = np.array(
         [[1.0000000, 0.0000000], [0.0000000, 1.0000000]], dtype=np.float64)
     np.testing.assert_allclose(obtained_corr_matrix, expected_corr_matrix)
     self.assertEqual(obtained_corr_matrix.dtype,
                      expected_corr_matrix.dtype)
Beispiel #2
0
 def test_dcor_float32(self):
     """Test the dCor method with a float32 NumPy array."""
     z_matrix = np.array([[0.0, 0.0, 1.0], [0.1, 0.2, 0.8], [0.2, 0.4, 0.6],
                          [0.3, 0.7, 0.3], [0.6, 0.8, 0.2], [0.8, 0.9, 0.1],
                          [1.0, 1.0, 0.0]],
                         dtype=np.float32)
     obtained_corr_matrix = mcdm.correlate(z_matrix, "dCor")
     expected_corr_matrix = np.array([[1.0000000, 0.9369189, 0.9369189],
                                      [0.9369189, 1.0000000, 1.0000000],
                                      [0.9369189, 1.0000000, 1.0000000]],
                                     dtype=np.float64)
     np.testing.assert_allclose(obtained_corr_matrix, expected_corr_matrix)
     self.assertEqual(obtained_corr_matrix.dtype,
                      expected_corr_matrix.dtype)
Beispiel #3
0
 def test_abspearson_linear(self):
     """Test the AbsPearson method with a linear association."""
     z_matrix = np.array([[0.0, 0.0, 1.0], [0.1, 0.2, 0.8], [0.2, 0.4, 0.6],
                          [0.3, 0.7, 0.3], [0.6, 0.8, 0.2], [0.8, 0.9, 0.1],
                          [1.0, 1.0, 0.0]],
                         dtype=np.float64)
     obtained_corr_matrix = mcdm.correlate(z_matrix, "AbsPearson")
     expected_corr_matrix = np.array([[1.0000000, 0.9314381, 0.9314381],
                                      [0.9314381, 1.0000000, 1.0000000],
                                      [0.9314381, 1.0000000, 1.0000000]],
                                     dtype=np.float64)
     np.testing.assert_allclose(obtained_corr_matrix, expected_corr_matrix)
     self.assertEqual(obtained_corr_matrix.dtype,
                      expected_corr_matrix.dtype)
Beispiel #4
0
 def test_pearson_nonlinear(self):
     """Test the Pearson method with a non-linear association."""
     z_matrix = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.2, 0.5, 0.0],
                          [0.2, 0.5, 1.0], [0.4, 1.0, 0.0], [0.4, 1.0, 1.0],
                          [0.6, 1.0, 0.0], [0.6, 1.0, 1.0], [0.8, 0.5, 0.0],
                          [0.8, 0.5, 1.0], [1.0, 0.0, 0.0], [1.0, 0.0, 1.0]
                          ],
                         dtype=np.float64)
     obtained_corr_matrix = mcdm.correlate(z_matrix, "Pearson")
     expected_corr_matrix = np.array(
         [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]],
         dtype=np.float64)
     np.testing.assert_allclose(obtained_corr_matrix, expected_corr_matrix)
     self.assertEqual(obtained_corr_matrix.dtype,
                      expected_corr_matrix.dtype)
Beispiel #5
0
 def test_pearson_float32(self):
     """Test the Pearson method with a float32 NumPy array."""
     z_matrix = np.array([[0.0, 0.0, 1.0], [0.1, 0.2, 0.8], [0.2, 0.4, 0.6],
                          [0.3, 0.7, 0.3], [0.6, 0.8, 0.2], [0.8, 0.9, 0.1],
                          [1.0, 1.0, 0.0]],
                         dtype=np.float32)
     obtained_corr_matrix = mcdm.correlate(z_matrix, "Pearson")
     expected_corr_matrix = np.array(
         [
             [1.0000000, 0.9314381, -0.9314381],  # noqa: E201
             [0.9314381, 1.0000000, -1.0000000],  # noqa: E201
             [-0.9314381, -1.0000000, 1.0000000]
         ],  # noqa: E201
         dtype=np.float64)
     np.testing.assert_allclose(obtained_corr_matrix, expected_corr_matrix)
     self.assertEqual(obtained_corr_matrix.dtype,
                      expected_corr_matrix.dtype)