16 #include "conditions_layer.h"
42 set(new_inputs_number, new_conditions_neurons_number);
68 set(other_conditions_layer);
89 if(
this != &other_conditions_layer)
172 return(
"OneCondition");
176 return(
"TwoConditions");
180 std::ostringstream buffer;
182 buffer <<
"OpenNN Exception: ConditionsLayer class.\n"
183 <<
"std::string write_conditions_method(void) const method.\n"
184 <<
"Unknown conditions method.\n";
186 throw std::logic_error(buffer.str());
265 void ConditionsLayer::set(
const size_t& new_external_inputs_number,
const size_t& new_conditions_neurons_number)
360 if(new_conditions_method ==
"OneCondition")
364 else if(new_conditions_method ==
"TwoConditions")
368 else if(new_conditions_method ==
"UserConditionsMethod")
374 std::ostringstream buffer;
376 buffer <<
"OpenNN Exception: ConditionsLayer class.\n"
377 <<
"void set_conditions_method(const std::string&) method.\n"
378 <<
"Unknown conditions method: " << new_conditions_method <<
".\n";
380 throw std::logic_error(buffer.str());
461 std::ostringstream buffer;
467 buffer <<
"OpenNN Exception: BoundingLayer class.\n"
468 <<
"void check(void) const method.\n"
469 <<
"Number of external inputs must be one.\n";
471 throw std::logic_error(buffer.str());
482 buffer <<
"OpenNN Exception: BoundingLayer class.\n"
483 <<
"void check(void) const method.\n"
484 <<
"Number of rows in output values is not equal to number of conditions neurons.\n";
486 throw std::logic_error(buffer.str());
491 if(external_input_values_size != 1)
493 buffer <<
"OpenNN Exception: BoundingLayer class.\n"
494 <<
"void check(void) const method.\n"
495 <<
"Size of input values is not 1.\n";
497 throw std::logic_error(buffer.str());
500 if(output_values_columns_number != 1)
502 buffer <<
"OpenNN Exception: BoundingLayer class.\n"
503 <<
"void check(void) const method.\n"
504 <<
"Number of columns in output values is not 1.\n";
506 throw std::logic_error(buffer.str());
511 if(external_input_values_size != 2)
513 buffer <<
"OpenNN Exception: BoundingLayer class.\n"
514 <<
"void check(void) const method.\n"
515 <<
"Size of input values is not 2.\n";
517 throw std::logic_error(buffer.str());
520 if(output_values_columns_number != 2)
522 buffer <<
"OpenNN Exception: BoundingLayer class.\n"
523 <<
"void check(void) const method.\n"
524 <<
"Number of columns in output values is not 2.\n";
526 throw std::logic_error(buffer.str());
555 std::ostringstream buffer;
557 buffer <<
"OpenNN Exception: ScalingLayer class\n"
558 <<
"Vector<double> calculate_particular_solution(const Vector<double>&) const method.\n"
559 <<
"Unknown conditions method.\n";
561 throw std::logic_error(buffer.str());
591 std::ostringstream buffer;
593 buffer <<
"OpenNN Exception: ScalingLayer class\n"
594 <<
"Matrix<double> calculate_particular_solution_Jacobian(const Vector<double>&) const method.\n"
595 <<
"Unknown conditions method.\n";
597 throw std::logic_error(buffer.str());
627 std::ostringstream buffer;
629 buffer <<
"OpenNN Exception: ScalingLayer class\n"
630 <<
"Vector< Matrix<double> > calculate_particular_solution_Hessian_form(const Vector<double>&) const method.\n"
631 <<
"Unknown conditions method.\n";
633 throw std::logic_error(buffer.str());
663 std::ostringstream buffer;
665 buffer <<
"OpenNN Exception: ScalingLayer class\n"
666 <<
"Vector<double> calculate_homogeneous_solution(const Vector<double>&) const method.\n"
667 <<
"Unknown conditions method.\n";
669 throw std::logic_error(buffer.str());
699 std::ostringstream buffer;
701 buffer <<
"OpenNN Exception: ScalingLayer class\n"
702 <<
"Matrix<double> calculate_homogeneous_solution_Jacobian(const Vector<double>&) const method.\n"
703 <<
"Unknown conditions method.\n";
705 throw std::logic_error(buffer.str());
735 std::ostringstream buffer;
737 buffer <<
"OpenNN Exception: ScalingLayer class\n"
738 <<
"Matrix<double> calculate_homogeneous_solution_Hessian_form(const Vector<double>&) const method.\n"
739 <<
"Unknown conditions method.\n";
741 throw std::logic_error(buffer.str());
759 return(particular_solution + homogeneous_solution*inputs);
777 return(particular_solution_Jacobian + homogeneous_solution_Jacobian*outputs + homogeneous_solution*Jacobian);
789 return(Hessian_form);
808 return(particular_solution);
826 return(particular_solution_Jacobian);
845 return(particular_solution_Hessian_form);
864 return(homogeneous_solution);
883 return(homogeneous_solution_Jacobian);
902 return(homogeneous_solution_Hessian_form);
919 const double x = external_inputs[0];
926 if(xb - xa < 1.0e-99)
928 std::ostringstream buffer;
930 buffer <<
"OpenNN Exception: BoundingLayer class.\n"
931 <<
"Vector<double> calculate_two_conditions_particular_solution(const Vector<double>&) const method.\n"
932 <<
"Both input values are the same.\n";
934 throw std::logic_error(buffer.str());
949 particular_solutions[i] = ya + (yb-ya)*(x-xa)/(double)(xb-xa);
952 return(particular_solutions);
974 if(xb - xa < 1.0e-99)
976 std::ostringstream buffer;
978 buffer <<
"OpenNN Exception: BoundingLayer class.\n"
979 <<
"Matrix<double> calculate_two_conditions_particular_solution_Jacobian(const Vector<double>&) const method.\n"
980 <<
"Both input values are the same.\n";
982 throw std::logic_error(buffer.str());
990 Matrix<double> particular_solution_Jacobian(1, 1, (yb-ya)/(xb-xa));
992 return(particular_solution_Jacobian);
1011 return(particular_solution_Hessian_form);
1028 const double x = external_inputs[0];
1035 if(xb - xa < 1.0e-99)
1037 std::ostringstream buffer;
1039 buffer <<
"OpenNN Exception: BoundingLayer class.\n"
1040 <<
"Matrix<double> calculate_two_conditions_particular_solution_Jacobian(const Vector<double>&) const method.\n"
1041 <<
"Both input values are the same.\n";
1043 throw std::logic_error(buffer.str());
1050 return(homogeneous_solutions);
1067 const double x = external_inputs[0];
1074 if(xb - xa < 1.0e-99)
1076 std::ostringstream buffer;
1078 buffer <<
"OpenNN Exception: BoundingLayer class.\n"
1079 <<
"Matrix<double> calculate_two_conditions_particular_solution_Jacobian(const Vector<double>&) const method.\n"
1080 <<
"Both input values are the same.\n";
1082 throw std::logic_error(buffer.str());
1087 Matrix<double> homogeneous_solution_Jacobian(1, 1, (x-xa) + (x-xb));
1089 return(homogeneous_solution_Jacobian);
1108 return(homogeneous_solution_Hessian_form);
1122 std::ostringstream buffer;
1130 buffer <<
"particular_solution_" << inputs_names[i];
1131 particular_solutions_names[i] = buffer.str();
1134 buffer <<
"homogeneous_solution_" << inputs_names[i];
1135 homogeneous_solutions_names[i] = buffer.str();
1146 buffer << outputs_names[i] <<
"=\n";
1160 return(buffer.str());
1189 std::ostringstream buffer;
1191 buffer <<
"OpenNN Exception: ScalingLayer class\n"
1192 <<
"std::string write_particular_solution_expression(const Vector<std::string>&, const Vector<std::string>&) const method.\n"
1193 <<
"Unknown conditions method.\n";
1195 throw std::logic_error(buffer.str());
1227 std::ostringstream buffer;
1229 buffer <<
"OpenNN Exception: ScalingLayer class\n"
1230 <<
"std::string write_homogeneous_solution_expression(const Vector<std::string>&, const Vector<std::string>&) const method.\n"
1231 <<
"Unknown conditions method.\n";
1233 throw std::logic_error(buffer.str());
1248 std::ostringstream buffer;
1252 buffer << particular_solutions_names[i] <<
" = " << external_inputs_names[i] <<
"\n";
1255 return(buffer.str());
1267 std::ostringstream buffer;
1271 buffer << homogeneous_solutions_names[i] <<
" = " << external_inputs_names[i] <<
"\n";
1274 return(buffer.str());
1286 std::ostringstream buffer;
1290 buffer << particular_solutions_names[i] <<
" = " << external_inputs_names[i] <<
"\n";
1293 return(buffer.str());
1305 std::ostringstream buffer;
1309 buffer << homogeneous_solutions_names[i] <<
" = " << external_inputs_names[i] <<
"\n";
1312 return(buffer.str());
1326 std::ostringstream buffer;
1330 buffer << outputs_names[i] <<
"=" << particular_solutions_names[i] <<
"+" << homogeneous_solutions_names[i] <<
"*" << inputs_names[i] <<
";\n";
1333 return(buffer.str());
1343 std::ostringstream buffer;
1345 buffer <<
"Conditions layer\n"
1351 <<
"Display: " <<
display <<
"\n";
1353 return(buffer.str());
1363 tinyxml2::XMLDocument* document =
new tinyxml2::XMLDocument;
1365 std::ostringstream buffer;
1367 tinyxml2::XMLElement* conditions_layer_element = document->NewElement(
"ConditionsLayer");
1369 document->InsertFirstChild(conditions_layer_element);
1373 tinyxml2::XMLElement* element = document->NewElement(
"ExternalInputsNumber");
1374 conditions_layer_element->LinkEndChild(element);
1379 tinyxml2::XMLText* text = document->NewText(buffer.str().c_str());
1380 element->LinkEndChild(text);
1385 tinyxml2::XMLElement* element = document->NewElement(
"ConditionsNeuronsNumber");
1386 conditions_layer_element->LinkEndChild(element);
1391 tinyxml2::XMLText* text = document->NewText(buffer.str().c_str());
1392 element->LinkEndChild(text);
1397 tinyxml2::XMLElement* element = document->NewElement(
"ConditionsMethod");
1398 conditions_layer_element->LinkEndChild(element);
1403 tinyxml2::XMLText* text = document->NewText(buffer.str().c_str());
1404 element->LinkEndChild(text);
1409 tinyxml2::XMLElement* element = document->NewElement(
"InputValues");
1410 conditions_layer_element->LinkEndChild(element);
1415 tinyxml2::XMLText* text = document->NewText(buffer.str().c_str());
1416 element->LinkEndChild(text);
1421 tinyxml2::XMLElement* element = document->NewElement(
"OutputValues");
1422 conditions_layer_element->LinkEndChild(element);
1427 tinyxml2::XMLText* text = document->NewText(buffer.str().c_str());
1428 element->LinkEndChild(text);
1433 tinyxml2::XMLElement* display_element = document->NewElement(
"Display");
1434 conditions_layer_element->LinkEndChild(display_element);
1439 tinyxml2::XMLText* display_text = document->NewText(buffer.str().c_str());
1440 display_element->LinkEndChild(display_text);
1457 const tinyxml2::XMLElement* element = document.FirstChildElement(
"ExternalInputsNumber");
1461 const char* text = element->GetText();
1469 catch(
const std::logic_error& e)
1471 std::cout << e.what() << std::endl;
1479 const tinyxml2::XMLElement* element = document.FirstChildElement(
"ConditionsNeuronsNumber");
1483 const char* text = element->GetText();
1491 catch(
const std::logic_error& e)
1493 std::cout << e.what() << std::endl;
1501 const tinyxml2::XMLElement* element = document.FirstChildElement(
"ConditionsMethod");
1505 const char* text = element->GetText();
1511 std::string new_conditions_method(text);
1515 catch(
const std::logic_error& e)
1517 std::cout << e.what() << std::endl;
1525 const tinyxml2::XMLElement* element = document.FirstChildElement(
"InputValues");
1529 const char* text = element->GetText();
1536 new_external_input_values.
parse(text);
1540 catch(
const std::logic_error& e)
1542 std::cout << e.what() << std::endl;
1550 const tinyxml2::XMLElement* element = document.FirstChildElement(
"OutputValues");
1554 const char* text = element->GetText();
1561 new_output_values_vector.
parse(text);
1567 catch(
const std::logic_error& e)
1569 std::cout << e.what() << std::endl;
1577 const tinyxml2::XMLElement* element = document.FirstChildElement(
"Display");
1581 const char* text = element->GetText();
1587 const std::string string(text);
1591 catch(
const std::logic_error& e)
1593 std::cout << e.what() << std::endl;
void parse(const std::string &)
void set_external_input_values(const Vector< double > &)
const size_t & get_external_inputs_number(void) const
Returns the number of external inputs.
Matrix< double > calculate_Jacobian(const Vector< double > &, const Vector< double > &, const Matrix< double > &) const
std::string write_two_conditions_particular_solution_expression(const Vector< std::string > &, const Vector< std::string > &) const
void set_default(void)
Sets the members of this conditions layer object to their default values.
const double & get_output_value(const size_t &, const size_t &) const
Vector< Matrix< double > > calculate_Hessian_form(const Vector< double > &, const Vector< double > &) const
std::string write_expression(const Vector< std::string > &, const Vector< std::string > &, const Vector< std::string > &) const
Vector< double > calculate_outputs(const Vector< double > &, const Vector< double > &) const
void set_conditions_neurons_number(const size_t &)
Vector< double > calculate_two_conditions_particular_solution(const Vector< double > &) const
const size_t & get_conditions_neurons_number(void) const
Returns the number of conditions neurons.
void set(void)
Sets the size of a vector to zero.
void set_external_inputs_number(const size_t &)
Vector< Matrix< double > > calculate_one_condition_homogeneous_solution_Hessian_form(const Vector< double > &) const
Vector< double > calculate_two_conditions_homogeneous_solution(const Vector< double > &) const
void set_output_values(const Matrix< double > &)
void set_display(const bool &)
bool operator==(const ConditionsLayer &) const
Vector< Matrix< double > > calculate_two_conditions_homogeneous_solution_Hessian_form(const Vector< double > &) const
Computes the homogeneous solution Hessian form for the two boundary conditions case.
const Vector< double > & get_external_input_values(void) const
Returns the input values for the conditions.
Vector< double > external_input_values
Independent values of the conditions.
virtual std::string write_particular_solution_expression(const Vector< std::string > &, const Vector< std::string > &) const
Vector< double > calculate_one_condition_homogeneous_solution(const Vector< double > &) const
void set_conditions_method(const ConditionsMethod &)
const ConditionsMethod & get_conditions_method(void) const
const bool & get_display(void) const
virtual ~ConditionsLayer(void)
Destructor.
virtual Matrix< double > calculate_homogeneous_solution_Jacobian(const Vector< double > &) const
Returns the homogeneous solution Jacobian for applying boundary conditions.
ConditionsLayer & operator=(const ConditionsLayer &)
size_t external_inputs_number
std::string write_two_conditions_homogeneous_solution_expression(const Vector< std::string > &, const Vector< std::string > &) const
tinyxml2::XMLDocument * to_XML(void) const
Serializes the conditions layer object into a document of the TinyXML library.
std::string write_one_condition_particular_solution_expression(const Vector< std::string > &, const Vector< std::string > &) const
std::string write_output_expression(const Vector< std::string > &, const Vector< std::string > &, const Vector< std::string > &, const Vector< std::string > &) const
Matrix< double > calculate_one_condition_homogeneous_solution_Jacobian(const Vector< double > &) const
Computes the homogeneous solution Jacobian for the one boundary condition case.
std::string to_string(void) const
Returns a string representation of the current conditions layer object.
void initialize_random(void)
virtual Vector< double > calculate_homogeneous_solution(const Vector< double > &) const
Returns the homogeneous solution for applying boundary conditions.
Matrix< double > calculate_one_condition_particular_solution_Jacobian(const Vector< double > &) const
Computes the Jacobian of the particular solution function for the one boundary condition case...
void from_XML(const tinyxml2::XMLDocument &)
Matrix< T > to_matrix(const size_t &, const size_t &) const
void set(void)
This method set the numbers of rows and columns of the matrix to zero.
const size_t & get_rows_number(void) const
Returns the number of rows in the matrix.
Matrix< double > output_values
Dependent values of the conditions.
Vector< Matrix< double > > calculate_one_condition_particular_solution_Hessian_form(const Vector< double > &) const
void set_external_input_value(const size_t &, const double &)
virtual Vector< double > calculate_particular_solution(const Vector< double > &) const
Returns the particular solution for applying boundary conditions.
virtual std::string write_homogeneous_solution_expression(const Vector< std::string > &, const Vector< std::string > &) const
Vector< Matrix< double > > calculate_two_conditions_particular_solution_Hessian_form(const Vector< double > &) const
size_t conditions_neurons_number
ConditionsMethod conditions_method
Conditions method (one or two conditions).
Matrix< double > calculate_two_conditions_homogeneous_solution_Jacobian(const Vector< double > &) const
ConditionsMethod
Enumeration of available methods for applying conditions.
void set_output_value(const size_t &, const size_t &, const double &)
std::string write_one_condition_homogeneous_solution_expression(const Vector< std::string > &, const Vector< std::string > &) const
std::string write_conditions_method(void) const
const double & get_external_input_value(const size_t &) const
void check(void) const
Checks that all the members of the conditions layer are correct before calculating the outputs from t...
Vector< T > to_vector(void) const
Vector< double > calculate_one_condition_particular_solution(const Vector< double > &) const
virtual Vector< Matrix< double > > calculate_particular_solution_Hessian_form(const Vector< double > &) const
virtual Matrix< double > calculate_particular_solution_Jacobian(const Vector< double > &) const
Returns the particular solution Jacobian for applying boundary conditions.
virtual Vector< Matrix< double > > calculate_homogeneous_solution_Hessian_form(const Vector< double > &) const
Matrix< double > calculate_two_conditions_particular_solution_Jacobian(const Vector< double > &) const
bool display
Display messages to screen.
const Matrix< double > & get_output_values(void) const
Returns the output values for the conditions.