void TestObjectiveFunctional::test_calculate_potential_evaluation(void) { message += "test_calculate_potential_evaluation\n"; MultilayerPerceptron mlp; Vector<double> parameters; MockObjectiveFunctional mof(&mlp); double evaluation; double potential_evaluation; // Only neural parameters mlp.set_network_architecture(1,1,1); mlp.set_independent_parameters_number(0); evaluation = mof.calculate_evaluation(); parameters = mlp.get_parameters(); potential_evaluation = mof.calculate_potential_evaluation(parameters); assert_true(evaluation == potential_evaluation, LOG); // Only independent parameters mlp.set_network_architecture(0,0,0); mlp.set_independent_parameters_number(1); evaluation = mof.calculate_evaluation(); parameters = mlp.get_parameters(); potential_evaluation = mof.calculate_potential_evaluation(parameters); assert_true(evaluation == potential_evaluation, LOG); // Both neural and independent parameters mlp.set_network_architecture(1,1,1); mlp.set_independent_parameters_number(1); evaluation = mof.calculate_evaluation(); parameters = mlp.get_parameters(); potential_evaluation = mof.calculate_potential_evaluation(parameters); assert_true(evaluation == potential_evaluation, LOG); }
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); }
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); }
void TestObjectiveFunctional::test_calculate_independent_parameters_gradient(void) { message += "test_calculate_independent_parameters_gradient\n"; MultilayerPerceptron mlp; MockObjectiveFunctional mof(&mlp); int independent_parameters_number; Vector<double> independent_parameters_gradient; // Test mlp.set(); independent_parameters_number = mlp.get_independent_parameters_number(); independent_parameters_gradient = mof.calculate_independent_parameters_gradient(); assert_true(independent_parameters_gradient.get_size() == independent_parameters_number, LOG); // Test mlp.set(1,1,1); independent_parameters_number = mlp.get_independent_parameters_number(); independent_parameters_gradient = mof.calculate_independent_parameters_gradient(); assert_true(independent_parameters_gradient.get_size() == independent_parameters_number, LOG); // Test mlp.set(1); independent_parameters_number = mlp.get_independent_parameters_number(); independent_parameters_gradient = mof.calculate_independent_parameters_gradient(); assert_true(independent_parameters_gradient.get_size() == independent_parameters_number, LOG); // Test mlp.set(1,1,1); mlp.set_independent_parameters_number(1); independent_parameters_number = mlp.get_independent_parameters_number(); independent_parameters_gradient = mof.calculate_independent_parameters_gradient(); assert_true(independent_parameters_gradient.get_size() == independent_parameters_number, LOG); }