16 #include "training_strategy.h"
28 : performance_functional_pointer(NULL)
29 , random_search_pointer(NULL)
30 , evolutionary_algorithm_pointer(NULL)
31 , gradient_descent_pointer(NULL)
32 , conjugate_gradient_pointer(NULL)
33 , quasi_Newton_method_pointer(NULL)
34 , Levenberg_Marquardt_algorithm_pointer(NULL)
35 , Newton_method_pointer(NULL)
53 : performance_functional_pointer(new_performance_functional_pointer)
54 , random_search_pointer(NULL)
55 , evolutionary_algorithm_pointer(NULL)
56 , gradient_descent_pointer(NULL)
57 , conjugate_gradient_pointer(NULL)
58 , quasi_Newton_method_pointer(NULL)
59 , Levenberg_Marquardt_algorithm_pointer(NULL)
60 , Newton_method_pointer(NULL)
78 : performance_functional_pointer(NULL)
79 , random_search_pointer(NULL)
80 , evolutionary_algorithm_pointer(NULL)
81 , gradient_descent_pointer(NULL)
82 , conjugate_gradient_pointer(NULL)
83 , quasi_Newton_method_pointer(NULL)
84 , Levenberg_Marquardt_algorithm_pointer(NULL)
85 , Newton_method_pointer(NULL)
105 : performance_functional_pointer(NULL)
106 , random_search_pointer(NULL)
107 , evolutionary_algorithm_pointer(NULL)
108 , gradient_descent_pointer(NULL)
109 , conjugate_gradient_pointer(NULL)
110 , quasi_Newton_method_pointer(NULL)
111 , Levenberg_Marquardt_algorithm_pointer(NULL)
112 , Newton_method_pointer(NULL)
154 std::ostringstream buffer;
156 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
157 <<
"void check_performance_functional(void) const.\n"
158 <<
"Pointer to performance functional is NULL.\n";
160 throw std::logic_error(buffer.str());
176 std::ostringstream buffer;
178 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
179 <<
"void check_training_algorithms(void) const method.\n"
180 <<
"None initialization, main or refinement terms are used.\n";
182 throw std::logic_error(buffer.str());
210 std::ostringstream buffer;
212 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
213 <<
"void initialize_random(void) method.\n"
214 <<
"Unknown initialization training algorithm.\n";
216 throw std::logic_error(buffer.str());
236 std::ostringstream buffer;
238 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
239 <<
"PerformanceFunctional* get_performance_functional_pointer(void) const method.\n"
240 <<
"Performance functional pointer is NULL.\n";
242 throw std::logic_error(buffer.str());
276 std::ostringstream buffer;
278 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
279 <<
"RandomSearch* get_random_search_pointer(void) const method.\n"
280 <<
"Random search pointer is NULL.\n";
282 throw std::logic_error(buffer.str());
298 std::ostringstream buffer;
300 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
301 <<
"EvolutionaryAlgorithm* get_evolutionary_algorithm_pointer(void) const method.\n"
302 <<
"Evolutionary algorithm pointer is NULL.\n";
304 throw std::logic_error(buffer.str());
320 std::ostringstream buffer;
322 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
323 <<
"GradientDescent* get_gradient_descent_pointer(void) const method.\n"
324 <<
"Gradient descent pointer is NULL.\n";
326 throw std::logic_error(buffer.str());
342 std::ostringstream buffer;
344 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
345 <<
"ConjugateGradient* get_conjugate_gradient_pointer(void) const method.\n"
346 <<
"Conjugate gradient pointer is NULL.\n";
348 throw std::logic_error(buffer.str());
364 std::ostringstream buffer;
366 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
367 <<
"QuasiNetwtonMethod* get_quasi_Newton_method_pointer(void) const method.\n"
368 <<
"Quasi-Newton method pointer is NULL.\n";
370 throw std::logic_error(buffer.str());
386 std::ostringstream buffer;
388 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
389 <<
"LevenbergMarquardtAlgorithm* get_Levenberg_Marquardt_algorithm_pointer(void) const method.\n"
390 <<
"Levenberg-Marquardt algorithm pointer is NULL.\n";
392 throw std::logic_error(buffer.str());
408 std::ostringstream buffer;
410 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
411 <<
"NewtonMethod* get_Newton_method_pointer(void) const method.\n"
412 <<
"Newton method pointer is NULL.\n";
414 throw std::logic_error(buffer.str());
459 return(
"NO_INITIALIZATION");
463 return(
"RANDOM_SEARCH");
467 return(
"EVOLUTIONARY_ALGORITHM");
471 return(
"USER_INITIALIZATION");
475 std::ostringstream buffer;
477 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
478 <<
"std::string write_initialization_type(void) const method.\n"
479 <<
"Unknown training algorithm type.\n";
481 throw std::logic_error(buffer.str());
498 return(
"GRADIENT_DESCENT");
502 return(
"CONJUGATE_GRADIENT");
504 else if(
main_type == QUASI_NEWTON_METHOD)
506 return(
"QUASI_NEWTON_METHOD");
508 else if(
main_type == LEVENBERG_MARQUARDT_ALGORITHM)
510 return(
"LEVENBERG_MARQUARDT_ALGORITHM");
518 std::ostringstream buffer;
520 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
521 <<
"std::string write_main_type(void) const method.\n"
522 <<
"Unknown main type.\n";
524 throw std::logic_error(buffer.str());
537 return(
"NO_REFINEMENT");
541 return(
"NEWTON_METHOD");
545 return(
"USER_REFINEMENT");
549 std::ostringstream buffer;
551 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
552 <<
"std::string write_refinement_type(void) const method.\n"
553 <<
"Unknown refinement type.\n";
555 throw std::logic_error(buffer.str());
572 return(
"random search");
576 return(
"evolutionary algorithm");
580 return(
"user defined");
584 std::ostringstream buffer;
586 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
587 <<
"std::string write_initialization_type_text(void) const method.\n"
588 <<
"Unknown training algorithm type.\n";
590 throw std::logic_error(buffer.str());
607 return(
"gradient descent");
611 return(
"conjugate gradient");
613 else if(
main_type == QUASI_NEWTON_METHOD)
615 return(
"quasi-Newton method");
617 else if(
main_type == LEVENBERG_MARQUARDT_ALGORITHM)
619 return(
"Levenberg-Marquardt algorithm");
623 return(
"user defined");
627 std::ostringstream buffer;
629 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
630 <<
"std::string write_main_type_text(void) const method.\n"
631 <<
"Unknown main type.\n";
633 throw std::logic_error(buffer.str());
650 return(
"Newton method");
654 return(
"user defined");
658 std::ostringstream buffer;
660 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
661 <<
"std::string write_refinement_type_text(void) const method.\n"
662 <<
"Unknown refinement type.\n";
664 throw std::logic_error(buffer.str());
730 case NO_INITIALIZATION:
742 case EVOLUTIONARY_ALGORITHM:
748 case USER_INITIALIZATION:
756 std::ostringstream buffer;
758 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
759 <<
"void set_initialization_type(const InitializationType&) method.\n"
760 <<
"Unknown initialization type.\n";
762 throw std::logic_error(buffer.str());
788 case GRADIENT_DESCENT:
794 case CONJUGATE_GRADIENT:
800 case QUASI_NEWTON_METHOD:
806 case LEVENBERG_MARQUARDT_ALGORITHM:
820 std::ostringstream buffer;
822 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
823 <<
"void set_initialization_type(const MainType&) method.\n"
824 <<
"Unknown main type.\n";
826 throw std::logic_error(buffer.str());
859 case USER_REFINEMENT:
867 std::ostringstream buffer;
869 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
870 <<
"void set_refinement_type(const RefinementType&) method.\n"
871 <<
"Unknown refinement type.\n";
873 throw std::logic_error(buffer.str());
887 if(new_initialization_type ==
"NO_INITIALIZATION")
891 else if(new_initialization_type ==
"RANDOM_SEARCH")
895 else if(new_initialization_type ==
"EVOLUTIONARY_ALGORITHM")
899 else if(new_initialization_type ==
"USER_INITIALIZATION")
905 std::ostringstream buffer;
907 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
908 <<
"void set_initialization_type(const std::string&) method.\n"
909 <<
"Unknown initialization type: " << new_initialization_type <<
".\n";
911 throw std::logic_error(buffer.str());
923 if(new_main_type ==
"NO_MAIN")
927 else if(new_main_type ==
"GRADIENT_DESCENT")
931 else if(new_main_type ==
"CONJUGATE_GRADIENT")
935 else if(new_main_type ==
"QUASI_NEWTON_METHOD")
939 else if(new_main_type ==
"LEVENBERG_MARQUARDT_ALGORITHM")
943 else if(new_main_type ==
"USER_MAIN")
949 std::ostringstream buffer;
951 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
952 <<
"void set_main_type(const std::string&) method.\n"
953 <<
"Unknown main type: " << new_main_type <<
".\n";
955 throw std::logic_error(buffer.str());
968 if(new_refinement_type ==
"NO_REFINEMENT")
972 else if(new_refinement_type ==
"NEWTON_METHOD")
976 else if(new_refinement_type ==
"USER_REFINEMENT")
982 std::ostringstream buffer;
984 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
985 <<
"void set_refinement_type(const std::string&) method.\n"
986 <<
"Unknown refinement type: " << new_refinement_type <<
".\n";
988 throw std::logic_error(buffer.str());
1006 case NO_INITIALIZATION:
1018 case EVOLUTIONARY_ALGORITHM:
1024 case USER_INITIALIZATION:
1032 std::ostringstream buffer;
1034 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
1035 <<
"void set_performance_functional_pointer(PerformanceFunctional*) method.\n"
1036 <<
"Unknown initialization type.\n";
1038 throw std::logic_error(buffer.str());
1053 case GRADIENT_DESCENT:
1059 case CONJUGATE_GRADIENT:
1065 case QUASI_NEWTON_METHOD:
1071 case LEVENBERG_MARQUARDT_ALGORITHM:
1085 std::ostringstream buffer;
1087 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
1088 <<
"void set_performance_functional_pointer(PerformanceFunctional*) method.\n"
1089 <<
"Unknown main type.\n";
1091 throw std::logic_error(buffer.str());
1112 case USER_REFINEMENT:
1120 std::ostringstream buffer;
1122 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
1123 <<
"void set_performance_functional_pointer(PerformanceFunctional) method.\n"
1124 <<
"Unknown refinement type.\n";
1126 throw std::logic_error(buffer.str());
1229 Results training_strategy_results;
1235 case NO_INITIALIZATION:
1248 case EVOLUTIONARY_ALGORITHM:
1255 case USER_INITIALIZATION:
1263 std::ostringstream buffer;
1265 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
1266 <<
"Results perform_training(void) method.\n"
1267 <<
"Unknown initialization type.\n";
1269 throw std::logic_error(buffer.str());
1284 case GRADIENT_DESCENT:
1292 case CONJUGATE_GRADIENT:
1299 case QUASI_NEWTON_METHOD:
1306 case LEVENBERG_MARQUARDT_ALGORITHM:
1321 std::ostringstream buffer;
1323 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
1324 <<
"Results perform_training(void) method.\n"
1325 <<
"Unknown main type.\n";
1327 throw std::logic_error(buffer.str());
1349 case USER_REFINEMENT:
1357 std::ostringstream buffer;
1359 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
1360 <<
"Results perform_training(void) method.\n"
1361 <<
"Unknown refinement type.\n";
1363 throw std::logic_error(buffer.str());
1368 return(training_strategy_results);
1378 std::ostringstream buffer;
1380 buffer <<
"Training strategy\n";
1388 case NO_INITIALIZATION:
1401 case EVOLUTIONARY_ALGORITHM:
1407 case USER_INITIALIZATION:
1415 std::ostringstream buffer;
1417 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
1418 <<
"std::string to_string(void) const method.\n"
1419 <<
"Unknown initialization type.\n";
1421 throw std::logic_error(buffer.str());
1438 case GRADIENT_DESCENT:
1445 case CONJUGATE_GRADIENT:
1451 case QUASI_NEWTON_METHOD:
1457 case LEVENBERG_MARQUARDT_ALGORITHM:
1471 std::ostringstream buffer;
1473 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
1474 <<
"std::string to_string(void) const method.\n"
1475 <<
"Unknown main type.\n";
1477 throw std::logic_error(buffer.str());
1500 case USER_REFINEMENT:
1508 std::ostringstream buffer;
1510 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
1511 <<
"std::string to_string(void) const method.\n"
1512 <<
"Unknown refinement type.\n";
1514 throw std::logic_error(buffer.str());
1519 return(buffer.str());
1540 std::ostringstream buffer;
1542 tinyxml2::XMLDocument* document =
new tinyxml2::XMLDocument;
1546 tinyxml2::XMLElement* training_strategy_element = document->NewElement(
"TrainingStrategy");
1548 document->InsertFirstChild(training_strategy_element);
1550 tinyxml2::XMLElement* element = NULL;
1551 tinyxml2::XMLText* text = NULL;
1557 case NO_INITIALIZATION:
1559 tinyxml2::XMLElement* initialization_element = document->NewElement(
"Initialization");
1560 training_strategy_element->LinkEndChild(initialization_element);
1562 initialization_element->SetAttribute(
"Type",
"NO_INITIALIZATION");
1568 tinyxml2::XMLElement* initialization_element = document->NewElement(
"Initialization");
1569 training_strategy_element->LinkEndChild(initialization_element);
1571 initialization_element->SetAttribute(
"Type",
"RANDOM_SEARCH");
1575 const tinyxml2::XMLElement* random_search_element = random_search_document->FirstChildElement(
"RandomSearch");
1577 DeepClone(initialization_element, random_search_element, document, NULL);
1579 delete random_search_document;
1583 case EVOLUTIONARY_ALGORITHM:
1585 tinyxml2::XMLElement* initialization_element = document->NewElement(
"Initialization");
1586 training_strategy_element->LinkEndChild(initialization_element);
1588 initialization_element->SetAttribute(
"Type",
"EVOLUTIONARY_ALGORITHM");
1592 const tinyxml2::XMLElement* evolutionary_algorithm_element = evolutionary_algorithm_document->FirstChildElement(
"EvolutionaryAlgorithm");
1594 DeepClone(initialization_element, evolutionary_algorithm_element, document, NULL);
1596 delete evolutionary_algorithm_document;
1600 case USER_INITIALIZATION:
1608 std::ostringstream buffer;
1610 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
1611 <<
"tinyxml2::XMLDocument* to_XML(void) const method.\n"
1612 <<
"Unknown initialization type.\n";
1614 throw std::logic_error(buffer.str());
1625 tinyxml2::XMLElement* main_element = document->NewElement(
"Main");
1626 training_strategy_element->LinkEndChild(main_element);
1628 main_element->SetAttribute(
"Type",
"NO_MAIN");
1632 case GRADIENT_DESCENT:
1634 tinyxml2::XMLElement* main_element = document->NewElement(
"Main");
1635 training_strategy_element->LinkEndChild(main_element);
1637 main_element->SetAttribute(
"Type",
"GRADIENT_DESCENT");
1641 const tinyxml2::XMLElement* gradient_descent_element = gradient_descent_document->FirstChildElement(
"GradientDescent");
1643 DeepClone(main_element, gradient_descent_element, document, NULL);
1645 delete gradient_descent_document;
1649 case CONJUGATE_GRADIENT:
1651 tinyxml2::XMLElement* main_element = document->NewElement(
"Main");
1652 training_strategy_element->LinkEndChild(main_element);
1654 main_element->SetAttribute(
"Type",
"CONJUGATE_GRADIENT");
1658 const tinyxml2::XMLElement* conjugate_gradient_element = conjugate_gradient_document->FirstChildElement(
"ConjugateGradient");
1660 DeepClone(main_element, conjugate_gradient_element, document, NULL);
1662 delete conjugate_gradient_document;
1666 case QUASI_NEWTON_METHOD:
1668 tinyxml2::XMLElement* main_element = document->NewElement(
"Main");
1669 training_strategy_element->LinkEndChild(main_element);
1671 main_element->SetAttribute(
"Type",
"QUASI_NEWTON_METHOD");
1675 const tinyxml2::XMLElement* quasi_Newton_method_element = quasi_Newton_method_document->FirstChildElement(
"QuasiNewtonMethod");
1677 DeepClone(main_element, quasi_Newton_method_element, document, NULL);
1679 delete quasi_Newton_method_document;
1683 case LEVENBERG_MARQUARDT_ALGORITHM:
1685 tinyxml2::XMLElement* main_element = document->NewElement(
"Main");
1686 training_strategy_element->LinkEndChild(main_element);
1688 main_element->SetAttribute(
"Type",
"LEVENBERG_MARQUARDT_ALGORITHM");
1692 const tinyxml2::XMLElement* Levenberg_Marquardt_algorithm_element = Levenberg_Marquardt_algorithm_document->FirstChildElement(
"LevenbergMarquardtAlgorithm");
1694 DeepClone(main_element, Levenberg_Marquardt_algorithm_element, document, NULL);
1696 delete Levenberg_Marquardt_algorithm_document;
1708 std::ostringstream buffer;
1710 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
1711 <<
"tinyxml2::XMLDocument* to_XML(void) const method.\n"
1712 <<
"Unknown main type.\n";
1714 throw std::logic_error(buffer.str());
1729 tinyxml2::XMLElement* refinement_element = document->NewElement(
"Refinement");
1730 training_strategy_element->LinkEndChild(refinement_element);
1732 refinement_element->SetAttribute(
"Type",
"NEWTON_METHOD");
1736 const tinyxml2::XMLElement* Newton_method_element = Newton_method_document->FirstChildElement(
"NewtonMethod");
1738 DeepClone(refinement_element, Newton_method_element, document, NULL);
1740 delete Newton_method_document;
1744 case USER_REFINEMENT:
1752 std::ostringstream buffer;
1754 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
1755 <<
"tinyxml2::XMLDocument* to_XML(void) const method.\n"
1756 <<
"Unknown refinement type.\n";
1758 throw std::logic_error(buffer.str());
1765 element = document->NewElement(
"Display");
1766 training_strategy_element->LinkEndChild(element);
1771 text = document->NewText(buffer.str().c_str());
1772 element->LinkEndChild(text);
1786 const tinyxml2::XMLElement* root_element = document.FirstChildElement(
"TrainingStrategy");
1790 std::ostringstream buffer;
1792 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
1793 <<
"void from_XML(const tinyxml2::XMLDocument&) method.\n"
1794 <<
"Training strategy element is NULL.\n";
1796 throw std::logic_error(buffer.str());
1801 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"Initialization");
1805 const std::string new_initialization_type = element->Attribute(
"Type");
1811 case NO_INITIALIZATION:
1819 tinyxml2::XMLDocument new_document;
1821 tinyxml2::XMLElement* element_clone = new_document.NewElement(
"RandomSearch");
1822 new_document.InsertFirstChild(element_clone);
1824 DeepClone(element_clone, element, &new_document, NULL);
1830 case EVOLUTIONARY_ALGORITHM:
1832 tinyxml2::XMLDocument new_document;
1834 tinyxml2::XMLElement* element_clone = new_document.NewElement(
"EvolutionaryAlgorithm");
1835 new_document.InsertFirstChild(element_clone);
1837 DeepClone(element_clone, element, &new_document, NULL);
1843 case USER_INITIALIZATION:
1851 std::ostringstream buffer;
1853 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
1854 <<
"void from_XML(const tinyxml2::XMLDocument&) method.\n"
1855 <<
"Unknown initialization type.\n";
1857 throw std::logic_error(buffer.str());
1866 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"Main");
1870 const std::string new_main_type = element->Attribute(
"Type");
1882 case GRADIENT_DESCENT:
1884 tinyxml2::XMLDocument new_document;
1886 tinyxml2::XMLElement* element_clone = new_document.NewElement(
"GradientDescent");
1887 new_document.InsertFirstChild(element_clone);
1889 DeepClone(element_clone, element, &new_document, NULL);
1895 case CONJUGATE_GRADIENT:
1897 tinyxml2::XMLDocument new_document;
1899 tinyxml2::XMLElement* element_clone = new_document.NewElement(
"ConjugateGradient");
1900 new_document.InsertFirstChild(element_clone);
1902 DeepClone(element_clone, element, &new_document, NULL);
1908 case QUASI_NEWTON_METHOD:
1910 tinyxml2::XMLDocument new_document;
1912 tinyxml2::XMLElement* element_clone = new_document.NewElement(
"QuasiNewtonMethod");
1913 new_document.InsertFirstChild(element_clone);
1915 DeepClone(element_clone, element, &new_document, NULL);
1921 case LEVENBERG_MARQUARDT_ALGORITHM:
1923 tinyxml2::XMLDocument new_document;
1925 tinyxml2::XMLElement* element_clone = new_document.NewElement(
"LevenbergMarquardtAlgorithm");
1926 new_document.InsertFirstChild(element_clone);
1928 DeepClone(element_clone, element, &new_document, NULL);
1942 std::ostringstream buffer;
1944 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
1945 <<
"void from_XML(const tinyxml2::XMLDocument&) method.\n"
1946 <<
"Unknown main type.\n";
1948 throw std::logic_error(buffer.str());
1957 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"Refinement");
1961 const std::string new_refinement_type = element->Attribute(
"Type");
1975 tinyxml2::XMLDocument new_document;
1977 tinyxml2::XMLElement* element_clone = new_document.NewElement(
"NewtonMethod");
1978 new_document.InsertFirstChild(element_clone);
1980 DeepClone(element_clone, element, &new_document, NULL);
1986 case USER_REFINEMENT:
1994 std::ostringstream buffer;
1996 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
1997 <<
"void from_XML(const tinyxml2::XMLDocument&) method.\n"
1998 <<
"Unknown refinement type.\n";
2000 throw std::logic_error(buffer.str());
2009 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"Display");
2013 const std::string new_display = element->GetText();
2019 catch(
const std::logic_error& e)
2021 std::cout << e.what() << std::endl;
2036 tinyxml2::XMLDocument* document =
to_XML();
2038 document->SaveFile(file_name.c_str());
2054 tinyxml2::XMLDocument document;
2056 if (document.LoadFile(file_name.c_str()))
2058 std::ostringstream buffer;
2060 buffer <<
"OpenNN Exception: TrainingStrategy class.\n"
2061 <<
"void load(const std::string&) method.\n"
2062 <<
"Cannot load XML file " << file_name <<
".\n";
2064 throw std::logic_error(buffer.str());
2119 std::ofstream file(file_name.c_str());
2121 if(random_search_results_pointer)
2123 file << random_search_results_pointer->to_string();
2126 if(evolutionary_algorithm_results_pointer)
2128 file << evolutionary_algorithm_results_pointer->to_string();
2131 if(gradient_descent_results_pointer)
2133 file << gradient_descent_results_pointer->to_string();
2136 if(conjugate_gradient_results_pointer)
2138 file << conjugate_gradient_results_pointer->to_string();
2141 if(quasi_Newton_method_results_pointer)
2143 file << quasi_Newton_method_results_pointer->to_string();
2146 if(Levenberg_Marquardt_algorithm_results_pointer)
2148 file << Levenberg_Marquardt_algorithm_results_pointer->to_string();
2151 if(Newton_method_results_pointer)
2153 file << Newton_method_results_pointer->to_string();
std::string write_main_type_text(void) const
Returns a string with the main type in text format.
void destruct_main(void)
This method deletes the main training algorithm object which composes this training strategy object...
GradientDescent::GradientDescentResults * gradient_descent_results_pointer
Pointer to a structure with the results from the gradient descent training algorithm.
std::string write_refinement_type_text(void) const
Returns a string with the refinement type in text format.
PerformanceFunctional * get_performance_functional_pointer(void) const
Returns a pointer to the performance functional object to which the training strategy is associated...
NewtonMethodResults * perform_training(void)
void set_display(const bool &)
tinyxml2::XMLDocument * to_XML(void) const
void from_XML(const tinyxml2::XMLDocument &)
void load(const std::string &)
virtual ~Results(void)
Destructor.
QuasiNewtonMethod * quasi_Newton_method_pointer
Pointer to a quasi-Newton method object to be used as a main training algorithm.
EvolutionaryAlgorithm * evolutionary_algorithm_pointer
Pointer to a evolutionary training object to be used for initialization in the training strategy...
tinyxml2::XMLDocument * to_XML(void) const
void from_XML(const tinyxml2::XMLDocument &)
void print(void) const
Prints to the screen the string representation of the training strategy object.
InitializationType initialization_type
Type of initialization training algorithm.
bool has_performance_functional(void) const
NewtonMethod * get_Newton_method_pointer(void) const
RandomSearch * get_random_search_pointer(void) const
void set_refinement_type(const RefinementType &)
const RefinementType & get_refinement_type(void) const
Returns the type of the refinement training algorithm composing this training strategy object...
void check_training_algorithms(void) const
QuasiNewtonMethod * get_quasi_Newton_method_pointer(void) const
LevenbergMarquardtAlgorithm::LevenbergMarquardtAlgorithmResults * Levenberg_Marquardt_algorithm_results_pointer
Pointer to a structure with the results from the Levenberg-Marquardt training algorithm.
EvolutionaryAlgorithmResults * perform_training(void)
NewtonMethod::NewtonMethodResults * Newton_method_results_pointer
Pointer to a structure with results from the Newton method training algorithm.
void from_XML(const tinyxml2::XMLDocument &)
void save(const std::string &) const
void set_performance_functional_pointer(PerformanceFunctional *)
ConjugateGradient::ConjugateGradientResults * conjugate_gradient_results_pointer
Pointer to a structure with the results from the conjugate gradient training algorithm.
NewtonMethod * Newton_method_pointer
Pointer to a Newton method object to be used for refinement in the training strategy.
virtual ~TrainingStrategy(void)
void from_XML(const tinyxml2::XMLDocument &)
GradientDescentResults * perform_training(void)
std::string to_string(void) const
Returns a string representation of the training strategy.
std::string write_initialization_type(void) const
Returns a string with the type of the initialization training algorithm composing this training strat...
void set_performance_functional_pointer(PerformanceFunctional *)
void from_XML(const tinyxml2::XMLDocument &)
tinyxml2::XMLDocument * to_XML(void) const
GradientDescent * gradient_descent_pointer
Pointer to a gradient descent object to be used as a main training algorithm.
std::string write_refinement_type(void) const
Returns a string with the type of the refinement training algorithm composing this training strategy ...
ConjugateGradientResults * perform_training(void)
PerformanceFunctional * performance_functional_pointer
Pointer to an external performance functional object.
LevenbergMarquardtAlgorithm * get_Levenberg_Marquardt_algorithm_pointer(void) const
EvolutionaryAlgorithm::EvolutionaryAlgorithmResults * evolutionary_algorithm_results_pointer
Pointer to a structure with the results from the evolutionary training algorithm. ...
void save(const std::string &) const
void set_performance_functional_pointer(PerformanceFunctional *)
ConjugateGradient * get_conjugate_gradient_pointer(void) const
void set_initialization_type(const InitializationType &)
QuasiNewtonMethodResults * perform_training(void)
RefinementType refinement_type
Type of refinement training algorithm.
bool display
Display messages to screen.
QuasiNewtonMethod::QuasiNewtonMethodResults * quasi_Newton_method_results_pointer
Pointer to a structure with the results from the quasi-Newton method training algorithm.
void initialize_random(void)
tinyxml2::XMLDocument * to_XML(void) const
std::string write_initialization_type_text(void) const
Returns a string with the initialization type in text format.
void from_XML(const tinyxml2::XMLDocument &)
Results perform_training(void)
RandomSearchResults * perform_training(void)
std::string to_string(void) const
Returns a default string representation of a training algorithm.
void set_main_type(const MainType &)
void from_XML(const tinyxml2::XMLDocument &)
void destruct_initialization(void)
This method deletes the initialization training algorithm object which composes this training strateg...
const MainType & get_main_type(void) const
Returns the type of the main training algorithm composing this training strategy object.
void from_XML(const tinyxml2::XMLDocument &)
virtual void set_default(void)
void destruct_refinement(void)
This method deletes the refinement training algorithm object which composes this training strategy ob...
void set_performance_functional_pointer(PerformanceFunctional *)
Results(void)
Default constructor.
LevenbergMarquardtAlgorithmResults * perform_training(void)
virtual std::string to_string(void) const
Returns a default string representation of a training algorithm.
void set_performance_functional_pointer(PerformanceFunctional *)
MainType
Enumeration of all the available types of training algorithms.
void check_performance_functional(void) const
Throws an exception if the training strategy has not a performance functional associated.
ConjugateGradient * conjugate_gradient_pointer
Pointer to a conjugate gradient object to be used as a main training algorithm.
tinyxml2::XMLDocument * to_XML(void) const
GradientDescent * get_gradient_descent_pointer(void) const
RefinementType
Enumeration of all the available types of training algorithms.
RandomSearch * random_search_pointer
Pointer to a random search object to be used for initialization in the training strategy.
virtual void set_performance_functional_pointer(PerformanceFunctional *)
const bool & get_display(void) const
tinyxml2::XMLDocument * to_XML(void) const
tinyxml2::XMLDocument * to_XML(void) const
EvolutionaryAlgorithm * get_evolutionary_algorithm_pointer(void) const
const InitializationType & get_initialization_type(void) const
Returns the type of the initialization training algorithm composing this training strategy object...
LevenbergMarquardtAlgorithm * Levenberg_Marquardt_algorithm_pointer
Pointer to a Levenberg-Marquardt algorithm object to be used as a main training algorithm.
InitializationType
Enumeration of all the available types of training algorithms.
MainType main_type
Type of main training algorithm.
RandomSearch::RandomSearchResults * random_search_results_pointer
Pointer to a structure with the results from the random search training algorithm.
tinyxml2::XMLDocument * to_XML(void) const
std::string write_main_type(void) const
Returns a string with the type of the main training algorithm composing this training strategy object...