16 #include "independent_parameters_error.h"
86 if(
this != &other_independent_parameters_error)
234 const size_t independent_parameters_number = independent_parameters_pointer->
get_parameters_number();
259 std::ostringstream buffer;
265 buffer <<
"OpenNN Exception: IndependentParametersError class.\n"
266 <<
"void check(void) const method.\n"
267 <<
"Pointer to neural network is NULL.\n";
269 throw std::logic_error(buffer.str());
274 if(!independent_parameters_pointer)
276 buffer <<
"OpenNN Exception: IndependentParametersError class.\n"
277 <<
"void check(void) const method.\n"
278 <<
"Pointer to independent parameters is NULL.\n";
280 throw std::logic_error(buffer.str());
283 const size_t independent_parameters_number = independent_parameters_pointer->
get_parameters_number();
285 if(independent_parameters_number == 0)
287 buffer <<
"OpenNN Exception: IndependentParametersError class.\n"
288 <<
"void check(void) const method.\n"
289 <<
"Number of independent parameters is zero.\n";
291 throw std::logic_error(buffer.str());
298 buffer <<
"OpenNN Exception: IndependentParametersError class.\n"
299 <<
"void check(void) const method.\n"
300 <<
"Pointer to mathematical model is NULL.\n";
302 throw std::logic_error(buffer.str());
309 if(target_independent_parameters_size != independent_parameters_number)
311 buffer <<
"OpenNN Exception: IndependentParametersError class." << std::endl
312 <<
"double calculate_performance(void) const method." << std::endl
313 <<
"Size of target independent parameters must be equal to number of independent parameters." << std::endl;
315 throw std::logic_error(buffer.str());
320 if(independent_parameters_errors_weights_size != independent_parameters_number)
322 buffer <<
"OpenNN Exception: IndependentParametersError class." << std::endl
323 <<
"double calculate_performance(void) const method." << std::endl
324 <<
"Size of independent parameters errors weights must be equal to number of independent parameters." << std::endl;
326 throw std::logic_error(buffer.str());
375 const size_t size = parameters.size();
379 if(size != parameters_number)
381 std::ostringstream buffer;
383 buffer <<
"OpenNN Exception: IndependentParametersError class." << std::endl
384 <<
"double calculate_performance(const Vector<double>&) const method." << std::endl
385 <<
"Size of parameters (" << size <<
") must be equal to number of parameters (" << parameters_number <<
")." << std::endl;
387 throw std::logic_error(buffer.str());
420 const size_t independent_parameters_number = independent_parameters_pointer->
get_parameters_number();
422 const size_t neural_parameters_number = parameters_number - independent_parameters_number;
424 Vector<double> multilayer_perceptron_gradient(neural_parameters_number, 0.0);
430 return(multilayer_perceptron_gradient.
assemble(independent_parameters_gradient));
450 const size_t independent_parameters_number = independent_parameters_pointer->
get_parameters_number();
452 const size_t neural_parameters_number = parameters_number - independent_parameters_number;
454 Matrix<double> Hessian(parameters_number, parameters_number, 0.0);
456 for(
size_t i = neural_parameters_number; i < parameters_number; i++)
458 for(
size_t j = neural_parameters_number; j < parameters_number; j++)
474 return(
"INDEPENDENT_PARAMETERS_ERROR");
482 std::ostringstream buffer;
486 return(buffer.str());
497 std::ostringstream buffer;
499 tinyxml2::XMLDocument* document =
new tinyxml2::XMLDocument;
503 tinyxml2::XMLElement* independent_parameters_error_element = document->NewElement(
"IndependentParametersError");
505 document->InsertFirstChild(independent_parameters_error_element);
518 tinyxml2::XMLElement* element = document->NewElement(
"TargetIndependentParamters");
519 independent_parameters_error_element->LinkEndChild(element);
524 tinyxml2::XMLText* text = document->NewText(buffer.str().c_str());
525 element->LinkEndChild(text);
531 tinyxml2::XMLElement* element = document->NewElement(
"IndependentParametersErrorsWeights");
532 independent_parameters_error_element->LinkEndChild(element);
537 tinyxml2::XMLText* text = document->NewText(buffer.str().c_str());
538 element->LinkEndChild(text);
544 tinyxml2::XMLElement* display_element = document->NewElement(
"Display");
545 independent_parameters_error_element->LinkEndChild(display_element);
550 tinyxml2::XMLText* display_text = document->NewText(buffer.str().c_str());
551 display_element->LinkEndChild(display_text);
565 const tinyxml2::XMLElement* root_element = document.FirstChildElement(
"IndependentParametersError");
569 std::ostringstream buffer;
571 buffer <<
"OpenNN Exception: IndependentParametersError class.\n"
572 <<
"void from_XML(const tinyxml2::XMLDocument&) method.\n"
573 <<
"Independent parameters error element is NULL.\n";
575 throw std::logic_error(buffer.str());
580 const tinyxml2::XMLElement* display_element = root_element->FirstChildElement(
"Display");
584 const std::string new_display_string = display_element->GetText();
590 catch(
const std::logic_error& e)
592 std::cout << e.what() << std::endl;
bool has_independent_parameters(void) const
size_t count_parameters_number(void) const
const Vector< double > & get_independent_parameters_errors_weights(void) const
Returns the weight for each error between the actual independent parameters and their target values...
Matrix< double > calculate_Hessian(void) const
Returns the performance term Hessian.
size_t get_parameters_number(void) const
const Vector< double > & get_parameters(void) const
Returns the values of the independent parameters.
void set(void)
Sets the size of a vector to zero.
std::string write_performance_term_type(void) const
Returns a string with the name of the independent parameters error performance type, "INDEPENDENT_PARAMETERS_ERROR".
void set_target_independent_parameter(const size_t &, const double &)
std::string write_information(void) const
const Vector< double > & get_target_independent_parameters(void) const
Returns the desired values for the independent parameter.
Vector< T > assemble(const Vector< T > &) const
const double & get_independent_parameter_error_weight(const size_t &) const
IndependentParametersError(void)
void set_independent_parameter_error_weight(const size_t &, const double &)
double calculate_performance(void) const
Returns the dot product between the independent parameters vector and its targets vector...
Vector< double > independent_parameters_errors_weights
Weight for each error between the actual independent parameters and their target values.
void set_target_independent_parameters(const Vector< double > &)
void set_independent_parameters_errors_weights(const Vector< double > &)
Vector< double > target_independent_parameters
Desired independent parameter values.
virtual ~IndependentParametersError(void)
Destructor.
Vector< double > calculate_gradient(void) const
Returns the performance term gradient.
tinyxml2::XMLDocument * to_XML(void) const
IndependentParameters * get_independent_parameters_pointer(void) const
Returns a pointer to the independent parameters object composing this neural network.
const double & get_target_independent_parameter(const size_t &) const
bool operator==(const IndependentParametersError &) const
Equal to operator.
IndependentParametersError & operator=(const IndependentParametersError &)
Assignment operator.
void from_XML(const tinyxml2::XMLDocument &)
void set_parameters(const Vector< double > &)