def test_error_calculation_01(self): x = self.training_data[:, :-1] y = self.training_data[:, -1].reshape(self.training_data.shape[0], 1) x_data_nr = x.shape[0] x_data_nc = 6 x_vector = np.zeros((x_data_nr, x_data_nc)) x_vector[:, 0] = 1 x_vector[:, 1] = x[:, 0] x_vector[:, 2] = x[:, 1] x_vector[:, 3] = x[:, 0]**2 x_vector[:, 4] = x[:, 1]**2 x_vector[:, 5] = x[:, 0] * x[:, 1] theta = np.zeros((x_data_nc, 1)) expected_value_1 = 2 * 6613.875 # Calculated externally as sum(y^2) / m expected_value_2 = expected_value_1**0.5 output_1, output_2, _ = RadialBasisFunctions.error_calculation( theta, x_vector, y) self.assertEqual(output_1, expected_value_1) self.assertEqual(output_2, expected_value_2)
def test_error_calculation_02(self): x = self.training_data[:, :-1] y = self.training_data[:, -1].reshape(self.training_data.shape[0], 1) x_data_nr = x.shape[0] x_data_nc = 6 x_vector = np.zeros((x_data_nr, x_data_nc)) x_vector[:, 0] = 1 x_vector[:, 1] = x[:, 0] x_vector[:, 2] = x[:, 1] x_vector[:, 3] = x[:, 0]**2 x_vector[:, 4] = x[:, 1]**2 x_vector[:, 5] = x[:, 0] * x[:, 1] theta = np.array([[4.5], [3], [3], [1], [1], [0] ]) # coefficients in (x1 + 1.5)^2 + (x2 + 1.5) ^ 2 expected_value_1 = 2 * 90.625 # Calculated externally as sum(dy^2) / 2m expected_value_2 = expected_value_1**0.5 output_1, output_2, _ = RadialBasisFunctions.error_calculation( theta, x_vector, y) self.assertEqual(output_1, expected_value_1) self.assertEqual(output_2, expected_value_2)
def test_error_calculation_03(self): x = self.training_data[:, :-1] y = self.training_data[:, -1].reshape(self.training_data.shape[0], 1) x_data_nr = x.shape[0] x_data_nc = 6 x_vector = np.zeros((x_data_nr, x_data_nc)) x_vector[:, 0] = 1 x_vector[:, 1] = x[:, 0] x_vector[:, 2] = x[:, 1] x_vector[:, 3] = x[:, 0]**2 x_vector[:, 4] = x[:, 1]**2 x_vector[:, 5] = x[:, 0] * x[:, 1] theta = np.array( [[2], [2], [2], [1], [1], [0]]) # Actual coefficients in (x1 + 1)^2 + (x2 + 1) ^ 2 expected_value_1 = 2 * 0 # Value should return zero for exact solution expected_value_2 = expected_value_1**0.5 output_1, output_2, _ = RadialBasisFunctions.error_calculation( theta, x_vector, y) self.assertEqual(output_1, expected_value_1) self.assertEqual(output_2, expected_value_2)