Beispiel #1
0
 def test_none_nested_list(self):
     """
     Test the processing of a nested list that is already normalized.
     """
     obtained_z_matrix, obtained_is_benefit_z = normalize(
         get_matrix01(),
         [True, True, True],
         None,
     )
     self.assertAlmostEqualArrays(
         obtained_z_matrix,
         np.array(get_matrix01(), dtype=np.float64),
     )
     self.assertEqual(obtained_is_benefit_z, [True, True, True])
Beispiel #2
0
 def test_vector_float32(self):
     """Test the Vector method with a float32 NumPy array."""
     x_matrix = np.array([[0.0, 0.0, 5.0, 5.0], [6.0, 6.0, 5.0, 5.0],
                          [0.0, 0.0, 5.0, 5.0], [8.0, 8.0, 5.0, 5.0]],
                         dtype=np.float32)
     is_benefit_x = [True, False, True, False]
     obtained_z_matrix, obtained_is_benefit_z = mcdm.normalize(
         x_matrix, is_benefit_x, "Vector")
     expected_z_matrix = np.array(
         [[0.0, 0.0, 0.5, 0.5], [0.6, 0.6, 0.5, 0.5], [0.0, 0.0, 0.5, 0.5],
          [0.8, 0.8, 0.5, 0.5]],
         dtype=np.float64)
     expected_is_benefit_z = [True, False, True, False]
     np.testing.assert_allclose(obtained_z_matrix, expected_z_matrix)
     self.assertEqual(obtained_z_matrix.dtype, expected_z_matrix.dtype)
     self.assertEqual(obtained_is_benefit_z, expected_is_benefit_z)
Beispiel #3
0
 def test_linear3_float32(self):
     """Test the Linear3 method with a float32 NumPy array."""
     x_matrix = np.array(
         [[4.0, 4.0, 7.0, 7.0], [3.0, 3.0, 7.0, 7.0], [2.0, 2.0, 7.0, 7.0],
          [1.0, 1.0, 7.0, 7.0], [0.0, 0.0, 7.0, 7.0]],
         dtype=np.float32)
     is_benefit_x = [True, False, True, False]
     obtained_z_matrix, obtained_is_benefit_z = mcdm.normalize(
         x_matrix, is_benefit_x, "Linear3")
     expected_z_matrix = np.array(
         [[0.4, 0.4, 0.2, 0.2], [0.3, 0.3, 0.2, 0.2], [0.2, 0.2, 0.2, 0.2],
          [0.1, 0.1, 0.2, 0.2], [0.0, 0.0, 0.2, 0.2]],
         dtype=np.float64)
     expected_is_benefit_z = [True, False, True, False]
     np.testing.assert_allclose(obtained_z_matrix, expected_z_matrix)
     self.assertEqual(obtained_z_matrix.dtype, expected_z_matrix.dtype)
     self.assertEqual(obtained_is_benefit_z, expected_is_benefit_z)
Beispiel #4
0
 def test_none_float32(self):
     """Test a float32 NumPy array that is already normalized."""
     x_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)
     is_benefit_x = [True, True, True]
     obtained_z_matrix, obtained_is_benefit_z = mcdm.normalize(
         x_matrix, is_benefit_x, None)
     expected_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)
     expected_is_benefit_z = [True, True, True]
     np.testing.assert_allclose(obtained_z_matrix, expected_z_matrix)
     self.assertEqual(obtained_z_matrix.dtype, expected_z_matrix.dtype)
     self.assertEqual(obtained_is_benefit_z, expected_is_benefit_z)
Beispiel #5
0
 def test_linear2_nested_list(self):
     """Test the Linear2 method with a nested list."""
     x_matrix = [
         [8.0, 8.0, -1.0, -1.0, 5.0, 5.0],  # noqa: E201
         [24.0, 24.0, -11.0, -11.0, 0.0, 0.0],  # noqa: E201
         [4.0, 4.0, -10.0, -10.0, 40.0, 40.0],  # noqa: E201
         [14.0, 14.0, -9.0, -9.0, 15.0, 15.0],  # noqa: E201
         [6.0, 6.0, -7.0, -7.0, -5.0, -5.0],  # noqa: E201
         [18.0, 18.0, -5.0, -5.0, -10.0, -10.0],  # noqa: E201
     ]
     is_benefit_x = [True, False, True, False, True, False]
     obtained_z_matrix, obtained_is_benefit_z = mcdm.normalize(
         x_matrix, is_benefit_x, "Linear2")
     expected_z_matrix = np.array(
         [[0.2, 0.8, 1.0, 0.0, 0.3, 0.7], [1.0, 0.0, 0.0, 1.0, 0.2, 0.8],
          [0.0, 1.0, 0.1, 0.9, 1.0, 0.0], [0.5, 0.5, 0.2, 0.8, 0.5, 0.5],
          [0.1, 0.9, 0.4, 0.6, 0.1, 0.9], [0.7, 0.3, 0.6, 0.4, 0.0, 1.0]],
         dtype=np.float64)
     expected_is_benefit_z = [True, True, True, True, True, True]
     np.testing.assert_allclose(obtained_z_matrix, expected_z_matrix)
     self.assertEqual(obtained_z_matrix.dtype, expected_z_matrix.dtype)
     self.assertEqual(obtained_is_benefit_z, expected_is_benefit_z)
Beispiel #6
0
 def test_linear1_nested_list(self):
     """Test the Linear1 method with a nested list."""
     x_matrix = [
         [2.0, 12.0, 7.0, 7.0],  # noqa: E201
         [4.0, 100.0, 7.0, 7.0],  # noqa: E201
         [10.0, 200.0, 7.0, 7.0],  # noqa: E201
         [0.0, 300.0, 7.0, 7.0],  # noqa: E201
         [6.0, 400.0, 7.0, 7.0],  # noqa: E201
         [1.0, 600.0, 7.0, 7.0],  # noqa: E201
     ]
     is_benefit_x = [True, False, True, False]
     obtained_z_matrix, obtained_is_benefit_z = mcdm.normalize(
         x_matrix, is_benefit_x, "Linear1")
     expected_z_matrix = np.array(
         [[0.2, 1.00, 1.0, 1.0], [0.4, 0.12, 1.0, 1.0],
          [1.0, 0.06, 1.0, 1.0], [0.0, 0.04, 1.0, 1.0],
          [0.6, 0.03, 1.0, 1.0], [0.1, 0.02, 1.0, 1.0]],
         dtype=np.float64)
     expected_is_benefit_z = [True, True, True, True]
     np.testing.assert_allclose(obtained_z_matrix, expected_z_matrix)
     self.assertEqual(obtained_z_matrix.dtype, expected_z_matrix.dtype)
     self.assertEqual(obtained_is_benefit_z, expected_is_benefit_z)