def test_points_selection_01(self): number_of_samples = 5 x = np.array([[8.79], [0.35], [4.56]]) data_feed = LatinHypercubeSampling(self.test_data, number_of_samples) output = data_feed.points_selection(self.test_data.values, x) expected_output = np.array([[9., 100.], [0., 1.], [5., 36.]]) self.assertEqual(output.tolist(), expected_output.tolist())
def test_lhs_points_generation_01(self): number_of_samples = 1 data_feed = LatinHypercubeSampling( self.test_data, number_of_samples) # Three samples requested. output_1 = data_feed.lhs_points_generation() # Test set 1: Check that the output has the right shape self.assertEqual(output_1.shape[0], number_of_samples) self.assertEqual(output_1.shape[1], (self.test_data.shape[1] - 1)) # Test set 2: Check that the values returned are within the expected range expected_lower = 0 # Minimum value for x in input_array expected_upper = 1 # Maximum value for x in input_array self.assertTrue((output_1 > expected_lower) and (output_1 < expected_upper))
def test_initialization_05(self): output_2 = LatinHypercubeSampling(self.test_data) expected_output = 5 expected_output_2 = np.array([[0], [1], [2], [3], [4], [5], [6], [7], [8], [9]]) self.assertEqual(output_2.number_of_samples, expected_output) self.assertEqual(output_2.x_data.tolist(), expected_output_2.tolist())
def test_lhs_points_generation_03(self): number_of_samples = 10 data_feed = LatinHypercubeSampling( self.test_data, number_of_samples) # Three samples requested. output_1 = data_feed.lhs_points_generation() # Test set 1: Check that the output has the right shape self.assertEqual(output_1.shape[0], number_of_samples) self.assertEqual(output_1.shape[1], (self.test_data.shape[1] - 1)) # Test set 2: Check that the values returned are within the expected range. expected_lower_firstvalue = 0 expected_upper_lastvalue = 1 expected_upper_firstvalue = expected_upper_lastvalue * 1 / number_of_samples expected_lower_lastvalue = expected_upper_lastvalue * ( number_of_samples - 1) / number_of_samples self.assertTrue((output_1[0, 0] > expected_lower_firstvalue) and (output_1[0, 0] < expected_upper_firstvalue)) self.assertTrue( (output_1[number_of_samples - 1, 0] > expected_lower_lastvalue) and (output_1[number_of_samples - 1, 0] < expected_upper_lastvalue))
def test_random_shuffling(self): x_pure = np.array([[0, 1, 2, 3], [3, 4, 5, 6], [6, 7, 8, 9], [9, 10, 11, 12], [12, 13, 14, 15], [15, 16, 17, 18]]) x = np.array([[0, 1, 2, 3], [3, 4, 5, 6], [6, 7, 8, 9], [9, 10, 11, 12], [12, 13, 14, 15], [15, 16, 17, 18]]) output_1 = LatinHypercubeSampling.random_shuffling(x) # Test 1: Check that randomization of columns has been done by comparing individual columns before and after self.assertNotEqual(output_1[:, 0].tolist(), x_pure[:, 0].tolist()) self.assertNotEqual(output_1[:, 1].tolist(), x_pure[:, 1].tolist()) self.assertNotEqual(output_1[:, 2].tolist(), x_pure[:, 2].tolist()) self.assertNotEqual(output_1[:, 3].tolist(), x_pure[:, 3].tolist()) # Test 2: Check that the columns still contain exactly the same values as before randomization by comparing the sets self.assertEqual(set(output_1[:, 0]), set(x_pure[:, 0])) self.assertEqual(set(output_1[:, 1]), set(x_pure[:, 1])) self.assertEqual(set(output_1[:, 2]), set(x_pure[:, 2])) self.assertEqual(set(output_1[:, 3]), set(x_pure[:, 3]))
def test_initialization_08(self): test_data_as_list = self.test_data.values.tolist() with self.assertRaises(ValueError): LatinHypercubeSampling(test_data_as_list, 7)
def test_initialization_07(self): test_data_as_array = self.test_data.values output_1 = LatinHypercubeSampling(test_data_as_array, 7) np.testing.assert_array_equal(output_1.data, test_data_as_array)
def test_initialization_06(self): with self.assertRaises(Exception): LatinHypercubeSampling(self.test_data, 1.7)