Exemplo n.º 1
0
 def test_gradient_function_01(self):
     x = self.training_data[:, :-1]
     y = self.training_data[:, -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, ))
     expected_value = np.array([[-97], [-635], [-635], [-5246.875],
                                [-5246.875], [-3925]])
     expected_value = expected_value.reshape(expected_value.shape[0], )
     output_1 = RadialBasisFunctions.gradient_function(theta, x_vector, y)
     np.testing.assert_equal(output_1, expected_value)
Exemplo n.º 2
0
 def test_gradient_function_03(self):
     x = self.training_data[:, :-1]
     y = self.training_data[:, -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
     theta = theta.reshape(theta.shape[0], )
     expected_value = np.array([[0], [0], [0], [0], [0], [0]
                                ])  # Calculated externally: see Excel sheet
     expected_value = expected_value.reshape(expected_value.shape[0], )
     output_1 = RadialBasisFunctions.gradient_function(theta, x_vector, y)
     np.testing.assert_equal(output_1, expected_value)