16 #include "solutions_error.h"
77 :
PerformanceTerm(new_neural_network_pointer, new_mathematical_model_pointer)
153 if(
this != &other_solutions_error)
213 return(
"SolutionsErrorSum");
217 return(
"SolutionsErrorIntegral");
221 std::ostringstream buffer;
223 buffer <<
"OpenNN Exception: SolutionsError class.\n"
224 <<
"std::string write_solutions_error_method(void) const method.\n"
225 <<
"Unknown solutions error method.\n";
227 throw std::logic_error(buffer.str());
294 if(new_solutions_error_method ==
"SolutionsErrorSum")
298 else if(new_solutions_error_method ==
"SolutionsErrorIntegral")
304 std::ostringstream buffer;
306 buffer <<
"OpenNN Exception: SolutionsError class.\n"
307 <<
"void set_solutions_error_method(const std::string&) method.\n"
308 <<
"Unknown solutions error method: " << new_solutions_error_method <<
".\n";
310 throw std::logic_error(buffer.str());
384 const Matrix<double> target_dependent_variables(rows_number, dependent_variables_number, 0.0);
386 return(target_dependent_variables);
403 std::ostringstream buffer;
409 buffer <<
"OpenNN Exception: SolutionsError class.\n"
410 <<
"void check(void) const method.\n"
411 <<
"Pointer to neural network is NULL.\n";
413 throw std::logic_error(buffer.str());
418 if(!multilayer_perceptron_pointer)
420 buffer <<
"OpenNN Exception: SolutionsError class.\n"
421 <<
"void check(void) const method.\n"
422 <<
"Pointer to multilayer perceptron is NULL.\n";
424 throw std::logic_error(buffer.str());
430 if(inputs_number == 0)
432 buffer <<
"OpenNN Exception: SolutionsError class.\n"
433 <<
"void check(void) const method.\n"
434 <<
"Number of inputs in multilayer perceptron object is zero.\n";
436 throw std::logic_error(buffer.str());
439 if(outputs_number == 0)
441 buffer <<
"OpenNN Exception: SolutionsError class.\n"
442 <<
"void check(void) const method.\n"
443 <<
"Number of outputs in multilayer perceptron object is zero.\n";
445 throw std::logic_error(buffer.str());
452 buffer <<
"OpenNN Exception: SolutionsError class.\n"
453 <<
"void check(void) const method.\n"
454 <<
"Pointer to mathematical model is NULL.\n";
456 throw std::logic_error(buffer.str());
465 if(solutions_errors_weights_size != dependent_variables_number)
467 buffer <<
"OpenNN Exception: SolutionsError class.\n"
468 <<
"void check(void) const method.\n"
469 <<
"Size of solutions errors weights (" << solutions_errors_weights_size <<
") is not equal to number of dependent variables (" << dependent_variables_number <<
").\n";
471 throw std::logic_error(buffer.str());
498 const Vector<size_t> independent_variables_indices(0, 1, independent_variables_number-1);
499 const Vector<size_t> dependent_variables_indices(independent_variables_number, 1, variables_number-1);
506 double performance = 0.0;
508 for(
size_t i = 0; i < dependent_variables_number; i++)
521 return(performance/(
double)rows_number);
551 case SolutionsErrorSum:
557 case SolutionsErrorIntegral:
565 std::ostringstream buffer;
567 buffer <<
"OpenNN Exception: SolutionsError class\n"
568 <<
"double calculate_performance(void) const method.\n"
569 <<
"Unknown solutions error method.\n";
571 throw std::logic_error(buffer.str());
612 return(
"SOLUTION_ERROR");
620 std::ostringstream buffer;
624 return(buffer.str());
636 std::cout <<
"Solutions error:\n"
649 std::ostringstream buffer;
651 tinyxml2::XMLDocument* document =
new tinyxml2::XMLDocument;
655 tinyxml2::XMLElement* root_element = document->NewElement(
"SolutionsError");
657 document->InsertFirstChild(root_element);
659 tinyxml2::XMLElement* element = NULL;
660 tinyxml2::XMLText* text = NULL;
667 root_element->LinkEndChild(element);
673 root_element->LinkEndChild(element);
678 element = document->NewElement(
"SolutionsErrorMethod");
679 root_element->LinkEndChild(element);
682 element->LinkEndChild(text);
687 element = document->NewElement(
"SolutionsErrorWeights");
688 root_element->LinkEndChild(element);
693 text = document->NewText(buffer.str().c_str());
694 element->LinkEndChild(text);
699 element = document->NewElement(
"Display");
700 root_element->LinkEndChild(element);
705 text = document->NewText(buffer.str().c_str());
706 element->LinkEndChild(text);
722 const tinyxml2::XMLElement* display_element = document.FirstChildElement(
"Display");
726 std::string new_display_string = display_element->GetText();
732 catch(
const std::logic_error& e)
734 std::cout << e.what() << std::endl;
virtual Matrix< double > calculate_solutions(const NeuralNetwork &) const
Vector< T > arrange_column(const size_t &) const
std::string write_solutions_error_method(void) const
Returns a string with the name of the method for computing the solutions error.
const Vector< double > & get_solutions_errors_weights(void) const
Returns the weights for every single solution error, corresponding to a dependent variable...
tinyxml2::XMLDocument * to_XML(void) const
Returns a representation of the solutions error object, in XML format.
const SolutionsErrorMethod & get_solutions_error_method(void) const
Returns the method for computing the solutions error.
virtual Matrix< double > calculate_target_dependent_variables(const Matrix< double > &) const
Returns the default target solution matrix.
SolutionsErrorMethod solutions_error_method
Method used to compute the error between the mathematical model solutions and the target solutions...
size_t get_inputs_number(void) const
Returns the number of inputs to the multilayer perceptron.
void set(void)
Sets the size of a vector to zero.
virtual ~SolutionsError(void)
void set_solutions_error_method(const SolutionsErrorMethod &)
size_t get_outputs_number(void) const
Returns the number of outputs neurons in the multilayer perceptron.
const size_t & get_independent_variables_number(void) const
Returns the number of independent variables in the mathematical model.
SolutionsErrorMethod
Enumeration of the different methods to compute the errors between the mathematical model solutions a...
Vector< double > solutions_errors_weights
Weights for the different dependent variables errors.
double calculate_solutions_error_integral(void) const
const size_t & get_dependent_variables_number(void) const
Returns the number of dependent variables in the mathematical model.
tinyxml2::XMLDocument * to_XML(void) const
Serializes this numerical integration object into a XML document.
Matrix< T > arrange_submatrix_columns(const Vector< size_t > &) const
size_t count_variables_number(void) const
bool operator==(const SolutionsError &) const
std::string write_performance_term_type(void) const
Returns a string with the name of the solutions error performance type, "SOLUTIONS_ERROR".
const double & get_solution_error_weight(const size_t &) const
Returns the weight for a single solution error, corresponding to a dependent variable.
std::string write_information(void) const
NumericalIntegration numerical_integration
Numerical integration object.
MultilayerPerceptron * get_multilayer_perceptron_pointer(void) const
Returns a pointer to the multilayer perceptron composing this neural network.
double calculate_solutions_error_sum(void) const
virtual double calculate_performance(void) const
Returns the objective value of a neural network according to the solutions error on a mathematical mo...
const size_t & get_rows_number(void) const
Returns the number of rows in the matrix.
void set_solution_error_weight(const size_t &, const double &)
virtual void print(void) const
Prints to the screen the string representation of this solutions error object.
SolutionsError & operator=(const SolutionsError &)
tinyxml2::XMLDocument * to_XML(void) const
Serializes this numerical differentiation object into a XML document->
void set_solutions_errors_weights(const Vector< double > &)
void set_parameters(const Vector< double > &)
void from_XML(const tinyxml2::XMLDocument &)