16 #include "training_algorithm.h"
28 : performance_functional_pointer(NULL)
41 : performance_functional_pointer(new_performance_functional_pointer)
54 : performance_functional_pointer(NULL)
77 if(
this != &other_training_algorithm)
120 std::ostringstream buffer;
122 buffer <<
"OpenNN Exception: TrainingAlgorithm class.\n"
123 <<
"PerformanceFunctional* get_performance_functional_pointer(void) const method.\n"
124 <<
"Performance functional pointer is NULL.\n";
126 throw std::logic_error(buffer.str());
257 if(new_display_period <= 0)
259 std::ostringstream buffer;
261 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
262 <<
"void set_display_period(const size_t&) method.\n"
263 <<
"Display period must be greater than 0.\n";
265 throw std::logic_error(buffer.str());
286 if(new_save_period <= 0)
288 std::ostringstream buffer;
290 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
291 <<
"void set_save_period(const size_t&) method.\n"
292 <<
"Save period must be greater than 0.\n";
294 throw std::logic_error(buffer.str());
337 return(
"USER_TRAINING_ALGORITHM");
350 std::ostringstream buffer;
354 buffer <<
"OpenNN Exception: TrainingAlgorithm class.\n"
355 <<
"void check(void) const method.\n"
356 <<
"Pointer to performance functional is NULL.\n";
358 throw std::logic_error(buffer.str());
363 if(neural_network_pointer == NULL)
365 buffer <<
"OpenNN Exception: TrainingAlgorithm class.\n"
366 <<
"void check(void) const method.\n"
367 <<
"Pointer to neural network is NULL.\n";
369 throw std::logic_error(buffer.str());
381 std::ostringstream buffer;
383 tinyxml2::XMLDocument* document =
new tinyxml2::XMLDocument;
387 tinyxml2::XMLElement* training_algorithm_element = document->NewElement(
"TrainingAlgorithm");
389 document->InsertFirstChild(training_algorithm_element);
393 tinyxml2::XMLElement* element = document->NewElement(
"Display");
394 training_algorithm_element->LinkEndChild(element);
399 tinyxml2::XMLText* text = document->NewText(buffer.str().c_str());
400 element->LinkEndChild(text);
414 const tinyxml2::XMLElement* root_element = document.FirstChildElement(
"TrainingAlgorithm");
418 std::ostringstream buffer;
420 buffer <<
"OpenNN Exception: TrainingAlgorithm class.\n"
421 <<
"void from_XML(const tinyxml2::XMLDocument&) method.\n"
422 <<
"Training algorithm element is NULL.\n";
424 throw std::logic_error(buffer.str());
429 const tinyxml2::XMLElement* display_element = root_element->FirstChildElement(
"Display");
433 const std::string new_display_string = display_element->GetText();
439 catch(
const std::logic_error& e)
441 std::cout << e.what() << std::endl;
455 std::ostringstream buffer;
457 buffer <<
"Training strategy\n"
458 <<
"Display: " <<
display <<
"\n";
460 return(buffer.str());
473 return(string_matrix);
494 tinyxml2::XMLDocument* document =
to_XML();
496 document->SaveFile(file_name.c_str());
512 tinyxml2::XMLDocument document;
514 if (document.LoadFile(file_name.c_str()))
516 std::ostringstream buffer;
518 buffer <<
"OpenNN Exception: TrainingAlgorithm class.\n"
519 <<
"void load(const std::string&) method.\n"
520 <<
"Cannot load XML file " << file_name <<
".\n";
522 throw std::logic_error(buffer.str());
552 std::ostringstream buffer;
554 buffer <<
"OpenNN Exception: TrainingAlgorithm class.\n"
555 <<
"void initialize_random(void) method.\n"
556 <<
"Unknown display value.\n";
558 throw std::logic_error(buffer.str());
void set_display_period(const size_t &)
virtual void set_default(void)
Sets the members of the training algorithm object to their default values.
void save(const std::string &) const
const size_t & get_save_period(void) const
Returns the number of iterations between the training saving progress.
bool display
Display messages to screen.
PerformanceFunctional * get_performance_functional_pointer(void) const
bool has_performance_functional(void) const
void print(void) const
Prints to the screen the XML-type representation of the training algorithm object.
void set_save_period(const size_t &)
size_t save_period
Number of iterations between the training saving progress.
virtual tinyxml2::XMLDocument * to_XML(void) const
void set_display(const bool &)
std::string neural_network_file_name
Path where the neural network is saved.
void set_neural_network_file_name(const std::string &)
virtual std::string write_training_algorithm_type(void) const
This method writes a string with the type of training algoritm.
virtual Matrix< std::string > to_string_matrix(void) const
virtual TrainingAlgorithm & operator=(const TrainingAlgorithm &)
virtual bool operator==(const TrainingAlgorithm &) const
virtual void check(void) const
virtual std::string to_string(void) const
Returns a default string representation of a training algorithm.
const bool & get_display(void) const
virtual void initialize_random(void)
const size_t & get_display_period(void) const
Returns the number of iterations between the training showing progress.
virtual void from_XML(const tinyxml2::XMLDocument &)
PerformanceFunctional * performance_functional_pointer
Pointer to a performance functional for a multilayer perceptron object.
virtual void set_performance_functional_pointer(PerformanceFunctional *)
virtual ~TrainingAlgorithm(void)
Destructor.
size_t display_period
Number of iterations between the training showing progress.
void load(const std::string &)
const std::string & get_neural_network_file_name(void) const
Returns the file name where the neural network will be saved.