Ejemplo n.º 1
0
void TestObjectiveFunctional::test_calculate_potential_Hessian(void)
{
   message += "test_calculate_potential_Hessian\n";

   MultilayerPerceptron mlp;
   int parameters_number;
   Vector<double> parameters;
   
   MockObjectiveFunctional mof(&mlp);
   Matrix<double> potential_Hessian;

   mlp.set_network_architecture(1, 1, 1);
   mlp.set_independent_parameters_number(0);

   mlp.initialize_parameters(0.0);

   parameters_number = mlp.get_parameters_number();
   parameters = mlp.get_parameters();

   potential_Hessian = mof.calculate_potential_Hessian(parameters);

   assert_true(potential_Hessian.get_rows_number() == parameters_number, LOG);
   assert_true(potential_Hessian.get_columns_number() == parameters_number, LOG);

   mlp.set_network_architecture(0, 0, 0);
   mlp.set_independent_parameters_number(1);

   mlp.initialize_parameters(0.0);

   parameters_number = mlp.get_parameters_number();
   parameters = mlp.get_parameters();

   potential_Hessian = mof.calculate_potential_Hessian(parameters);

   assert_true(potential_Hessian.get_rows_number() == parameters_number, LOG);
   assert_true(potential_Hessian.get_columns_number() == parameters_number, LOG);

   mlp.set_network_architecture(1, 1, 1);
   mlp.set_independent_parameters_number(1);

   mlp.initialize_parameters(0.0);

   parameters_number = mlp.get_parameters_number();
   parameters = mlp.get_parameters();

   potential_Hessian = mof.calculate_potential_Hessian(parameters);

   assert_true(potential_Hessian.get_rows_number() == parameters_number, LOG);
   assert_true(potential_Hessian.get_columns_number() == parameters_number, LOG);
}
Ejemplo n.º 2
0
void TestObjectiveFunctional::test_calculate_potential_gradient(void)
{
   message += "test_calculate_potential_gradient\n";
   
   MultilayerPerceptron mlp;

   MockObjectiveFunctional mof(&mlp);

   Vector<double> parameters;

   // Only neural parameters

   mlp.set_network_architecture(1, 1, 1);
   mlp.set_independent_parameters_number(0);

   mlp.initialize_parameters(0.0);

   parameters = mlp.get_parameters();

   assert_true(mof.calculate_potential_gradient(parameters) == 0.0, LOG);

   // Only independent parameters

   mlp.set_network_architecture(0, 0, 0);
   mlp.set_independent_parameters_number(1);

   mlp.initialize_parameters(0.0);

   parameters = mlp.get_parameters();

   assert_true(mof.calculate_potential_gradient(parameters) == 0.0, LOG);

   // Both neural and independent parameters

   mlp.set_network_architecture(1, 1, 1);
   mlp.set_independent_parameters_number(1);

   mlp.initialize_parameters(0.0);

   parameters = mlp.get_parameters();

   assert_true(mof.calculate_potential_gradient(parameters) == 0.0, LOG);
}