16 #include "gradient_descent.h"
448 if(new_warning_parameters_norm < 0.0)
450 std::ostringstream buffer;
452 buffer <<
"OpenNN Exception: GradientDescent class.\n"
453 <<
"void set_warning_parameters_norm(const double&) method.\n"
454 <<
"Warning parameters norm must be equal or greater than 0.\n";
456 throw std::logic_error(buffer.str());
479 if(new_warning_gradient_norm < 0.0)
481 std::ostringstream buffer;
483 buffer <<
"OpenNN Exception: GradientDescent class.\n"
484 <<
"void set_warning_gradient_norm(const double&) method.\n"
485 <<
"Warning gradient norm must be equal or greater than 0.\n";
487 throw std::logic_error(buffer.str());
510 if(new_warning_training_rate < 0.0)
512 std::ostringstream buffer;
514 buffer <<
"OpenNN Exception: GradientDescent class.\n"
515 <<
"void set_warning_training_rate(const double&) method.\n"
516 <<
"Warning training rate must be equal or greater than 0.\n";
518 throw std::logic_error(buffer.str());
539 if(new_error_parameters_norm < 0.0)
541 std::ostringstream buffer;
543 buffer <<
"OpenNN Exception: GradientDescent class.\n"
544 <<
"void set_error_parameters_norm(const double&) method.\n"
545 <<
"Error parameters norm must be equal or greater than 0.\n";
547 throw std::logic_error(buffer.str());
570 if(new_error_gradient_norm < 0.0)
572 std::ostringstream buffer;
574 buffer <<
"OpenNN Exception: GradientDescent class.\n"
575 <<
"void set_error_gradient_norm(const double&) method.\n"
576 <<
"Error gradient norm must be equal or greater than 0.\n";
578 throw std::logic_error(buffer.str());
601 if(new_error_training_rate < 0.0)
603 std::ostringstream buffer;
605 buffer <<
"OpenNN Exception: GradientDescent class.\n"
606 <<
"void set_error_training_rate(const double&) method.\n"
607 <<
"Error training rate must be equal or greater than 0.\n";
609 throw std::logic_error(buffer.str());
631 if(new_minimum_parameters_increment_norm < 0.0)
633 std::ostringstream buffer;
635 buffer <<
"OpenNN Exception: GradientDescent class.\n"
636 <<
"void new_minimum_parameters_increment_norm(const double&) method.\n"
637 <<
"Minimum parameters increment norm must be equal or greater than 0.\n";
639 throw std::logic_error(buffer.str());
661 if(new_minimum_performance_increase < 0.0)
663 std::ostringstream buffer;
665 buffer <<
"OpenNN Exception: GradientDescent class.\n"
666 <<
"void set_minimum_performance_increase(const double&) method.\n"
667 <<
"Minimum performance improvement must be equal or greater than 0.\n";
669 throw std::logic_error(buffer.str());
704 if(new_gradient_norm_goal < 0.0)
706 std::ostringstream buffer;
708 buffer <<
"OpenNN Exception: GradientDescent class.\n"
709 <<
"void set_gradient_norm_goal(const double&) method.\n"
710 <<
"Gradient norm goal must be equal or greater than 0.\n";
712 throw std::logic_error(buffer.str());
756 if(new_maximum_time < 0.0)
758 std::ostringstream buffer;
760 buffer <<
"OpenNN Exception: GradientDescent class.\n"
761 <<
"void set_maximum_time(const double&) method.\n"
762 <<
"Maximum time must be equal or greater than 0.\n";
764 throw std::logic_error(buffer.str());
891 if(new_display_period <= 0)
893 std::ostringstream buffer;
895 buffer <<
"OpenNN Exception: GradientDescent class.\n"
896 <<
"void set_display_period(const double&) method.\n"
897 <<
"First training rate must be greater than 0.\n";
899 throw std::logic_error(buffer.str());
921 std::ostringstream buffer;
925 buffer <<
"OpenNN Exception: GradientDescent class.\n"
926 <<
"Vector<double> calculate_training_direction(const Vector<double>&) const method.\n"
927 <<
"Performance functional pointer is NULL.\n";
929 throw std::logic_error(buffer.str());
936 const size_t gradient_size = gradient.size();
938 if(gradient_size != parameters_number)
940 buffer <<
"OpenNN Exception: GradientDescent class.\n"
941 <<
"Vector<double> calculate_training_direction(const Vector<double>&) const method.\n"
942 <<
"Size of gradient (" << gradient_size <<
") is not equal to number of parameters (" << parameters_number <<
").\n";
944 throw std::logic_error(buffer.str());
957 std::ostringstream buffer;
965 buffer <<
"% Parameters history:\n"
974 buffer <<
"% Parameters norm history:\n"
982 buffer <<
"% Performance history:\n"
990 buffer <<
"% Generalization performance history:\n"
1000 buffer <<
"% Gradient history:\n"
1009 buffer <<
"% Gradient norm history:\n"
1019 buffer <<
"% Training direction history:\n"
1028 buffer <<
"% Training rate history:\n"
1036 buffer <<
"% Elapsed time history:\n"
1044 buffer <<
"% Stopping criterion:\n"
1048 return(buffer.str());
1056 std::ostringstream buffer;
1063 names.push_back(
"Final parameters norm");
1066 buffer << std::setprecision(precision) << final_parameters_norm;
1068 values.push_back(buffer.str());
1072 names.push_back(
"Final performance");
1075 buffer << std::setprecision(precision) << final_performance;
1077 values.push_back(buffer.str());
1085 names.push_back(
"Final generalization performance");
1088 buffer << std::setprecision(precision) << final_generalization_performance;
1090 values.push_back(buffer.str());
1095 names.push_back(
"Final gradient norm");
1098 buffer << std::setprecision(precision) << final_gradient_norm;
1100 values.push_back(buffer.str());
1113 names.push_back(
"Iterations number");
1116 buffer << iterations_number;
1118 values.push_back(buffer.str());
1122 names.push_back(
"Elapsed time");
1125 buffer << elapsed_time;
1127 values.push_back(buffer.str());
1129 const size_t rows_number = names.size();
1130 const size_t columns_number = 2;
1137 return(final_results);
1152 if(gradient_descent_pointer == NULL)
1154 std::ostringstream buffer;
1156 buffer <<
"OpenNN Exception: GradientDescentResults structure.\n"
1157 <<
"void resize_training_history(const size_t&) method.\n"
1158 <<
"Gradient descent pointer is NULL.\n";
1160 throw std::logic_error(buffer.str());
1165 if(gradient_descent_pointer->get_reserve_parameters_history())
1167 parameters_history.resize(new_size);
1170 if(gradient_descent_pointer->get_reserve_parameters_norm_history())
1172 parameters_norm_history.resize(new_size);
1175 if(gradient_descent_pointer->get_reserve_performance_history())
1177 performance_history.resize(new_size);
1180 if(gradient_descent_pointer->get_reserve_generalization_performance_history())
1182 generalization_performance_history.resize(new_size);
1185 if(gradient_descent_pointer->get_reserve_gradient_history())
1187 gradient_history.resize(new_size);
1190 if(gradient_descent_pointer->get_reserve_gradient_norm_history())
1192 gradient_norm_history.resize(new_size);
1195 if(gradient_descent_pointer->get_reserve_training_direction_history())
1197 training_direction_history.resize(new_size);
1200 if(gradient_descent_pointer->get_reserve_training_rate_history())
1202 training_rate_history.resize(new_size);
1205 if(gradient_descent_pointer->get_reserve_elapsed_time_history())
1207 elapsed_time_history.resize(new_size);
1235 std::cout <<
"Training with gradient descent...\n";
1245 double parameters_norm;
1248 double parameters_increment_norm;
1252 double generalization_performance = 0.0;
1253 double old_generalization_performance = 0.0;
1255 double performance = 0.0;
1256 double old_performance = 0.0;
1257 double performance_increase = 0.0;
1260 double gradient_norm;
1266 size_t generalization_failures = 0;
1270 const double first_training_rate = 0.01;
1272 double initial_training_rate = 0.0;
1273 double training_rate = 0.0;
1274 double old_training_rate = 0.0;
1278 bool stop_training =
false;
1280 time_t beginning_time, current_time;
1281 time(&beginning_time);
1282 double elapsed_time;
1298 std::cout <<
"OpenNN Warning: Parameters norm is " << parameters_norm <<
".\n";
1306 performance_increase = 1.0e99;
1310 performance = directional_point[1];
1311 performance_increase = old_performance - performance;
1320 std::cout <<
"OpenNN Warning: Gradient norm is " << gradient_norm <<
".\n";
1325 if(iteration != 0 && generalization_performance > old_generalization_performance)
1327 generalization_failures++;
1336 initial_training_rate = first_training_rate;
1340 initial_training_rate = old_training_rate;
1345 training_rate = directional_point[0];
1347 parameters_increment = training_direction*training_rate;
1348 parameters_increment_norm = parameters_increment.
calculate_norm();
1352 time(¤t_time);
1353 elapsed_time = difftime(current_time, beginning_time);
1412 std::cout <<
"Iteration " << iteration <<
": Minimum parameters increment norm reached.\n";
1413 std::cout <<
"Parameters increment norm: " << parameters_increment_norm << std::endl;
1416 stop_training =
true;
1423 std::cout <<
"Iteration " << iteration <<
": Minimum performance increase reached.\n"
1424 <<
"Performance increase: " << performance_increase << std::endl;
1427 stop_training =
true;
1434 std::cout <<
"Iteration " << iteration <<
": Performance goal reached.\n";
1437 stop_training =
true;
1444 std::cout <<
"Iteration " << iteration <<
": Maximum generalization failures reached.\n"
1445 <<
"Generalization failures: " << generalization_failures << std::endl;
1448 stop_training =
true;
1455 std::cout <<
"Iteration " << iteration <<
": Gradient norm goal reached.\n";
1458 stop_training =
true;
1465 std::cout <<
"Iteration " << iteration <<
": Maximum number of iterations reached.\n";
1468 stop_training =
true;
1475 std::cout <<
"Iteration " << iteration <<
": Maximum training time reached.\n";
1478 stop_training =
true;
1481 if(iteration != 0 && iteration %
save_period == 0)
1490 std::cout <<
"Parameters norm: " << parameters_norm <<
"\n"
1491 <<
"Performance: " << performance <<
"\n"
1492 <<
"Gradient norm: " << gradient_norm <<
"\n"
1494 <<
"Training rate: " << training_rate <<
"\n"
1495 <<
"Elapsed time: " << elapsed_time << std::endl;
1497 if(generalization_performance != 0)
1499 std::cout <<
"Generalization performance: " << generalization_performance << std::endl;
1529 std::cout <<
"Iteration " << iteration <<
";\n"
1530 <<
"Parameters norm: " << parameters_norm <<
"\n"
1531 <<
"Performance: " << performance <<
"\n"
1532 <<
"Gradient norm: " << gradient_norm <<
"\n"
1534 <<
"Training rate: " << training_rate <<
"\n"
1535 <<
"Elapsed time: " << elapsed_time << std::endl;
1537 if(generalization_performance != 0)
1539 std::cout <<
"Generalization performance: " << generalization_performance << std::endl;
1545 parameters += parameters_increment;
1551 old_performance = performance;
1552 old_generalization_performance = generalization_performance;
1554 old_training_rate = training_rate;
1557 return(results_pointer);
1565 return(
"GRADIENT_DESCENT");
1575 std::ostringstream buffer;
1582 labels.push_back(
"Training rate method");
1586 values.push_back(training_rate_method);
1590 labels.push_back(
"Training rate tolerance");
1595 values.push_back(buffer.str());
1599 labels.push_back(
"Minimum parameters increment norm");
1604 values.push_back(buffer.str());
1608 labels.push_back(
"Minimum performance increase");
1613 values.push_back(buffer.str());
1617 labels.push_back(
"Performance goal");
1622 values.push_back(buffer.str());
1626 labels.push_back(
"Gradient norm goal");
1631 values.push_back(buffer.str());
1635 labels.push_back(
"Maximum generalization failures");
1640 values.push_back(buffer.str());
1644 labels.push_back(
"Maximum iterations number");
1649 values.push_back(buffer.str());
1653 labels.push_back(
"Maximum time");
1658 values.push_back(buffer.str());
1662 labels.push_back(
"Reserve parameters norm history");
1667 values.push_back(buffer.str());
1671 labels.push_back(
"Reserve performance history");
1676 values.push_back(buffer.str());
1680 labels.push_back(
"Reserve gradient norm history");
1685 values.push_back(buffer.str());
1689 labels.push_back(
"Reserve generalization performance history");
1694 values.push_back(buffer.str());
1714 labels.push_back(
"Reserve elapsed time history");
1719 values.push_back(buffer.str());
1721 const size_t rows_number = labels.size();
1722 const size_t columns_number = 2;
1729 return(string_matrix);
1740 std::ostringstream buffer;
1742 tinyxml2::XMLDocument* document =
new tinyxml2::XMLDocument;
1746 tinyxml2::XMLElement* root_element = document->NewElement(
"GradientDescent");
1748 document->InsertFirstChild(root_element);
1750 tinyxml2::XMLElement* element = NULL;
1751 tinyxml2::XMLText* text = NULL;
1755 tinyxml2::XMLElement* element = document->NewElement(
"TrainingRateAlgorithm");
1756 root_element->LinkEndChild(element);
1760 const tinyxml2::XMLElement* training_rate_algorithm_element = training_rate_algorithm_document->FirstChildElement(
"TrainingRateAlgorithm");
1762 DeepClone(element, training_rate_algorithm_element, document, NULL);
1764 delete training_rate_algorithm_document;
1770 element = document->NewElement(
"WarningParametersNorm");
1771 root_element->LinkEndChild(element);
1776 text = document->NewText(buffer.str().c_str());
1777 element->LinkEndChild(text);
1781 element = document->NewElement(
"WarningGradientNorm");
1782 root_element->LinkEndChild(element);
1787 text = document->NewText(buffer.str().c_str());
1788 element->LinkEndChild(text);
1792 element = document->NewElement(
"WarningTrainingRate");
1793 root_element->LinkEndChild(element);
1798 text = document->NewText(buffer.str().c_str());
1799 element->LinkEndChild(text);
1803 element = document->NewElement(
"ErrorParametersNorm");
1804 root_element->LinkEndChild(element);
1809 text = document->NewText(buffer.str().c_str());
1810 element->LinkEndChild(text);
1814 element = document->NewElement(
"ErrorGradientNorm");
1815 root_element->LinkEndChild(element);
1820 text = document->NewText(buffer.str().c_str());
1821 element->LinkEndChild(text);
1825 element = document->NewElement(
"ErrorTrainingRate");
1826 root_element->LinkEndChild(element);
1831 text = document->NewText(buffer.str().c_str());
1832 element->LinkEndChild(text);
1836 element = document->NewElement(
"MinimumParametersIncrementNorm");
1837 root_element->LinkEndChild(element);
1842 text = document->NewText(buffer.str().c_str());
1843 element->LinkEndChild(text);
1847 element = document->NewElement(
"MinimumPerformanceIncrease");
1848 root_element->LinkEndChild(element);
1853 text = document->NewText(buffer.str().c_str());
1854 element->LinkEndChild(text);
1858 element = document->NewElement(
"PerformanceGoal");
1859 root_element->LinkEndChild(element);
1864 text = document->NewText(buffer.str().c_str());
1865 element->LinkEndChild(text);
1869 element = document->NewElement(
"GradientNormGoal");
1870 root_element->LinkEndChild(element);
1875 text = document->NewText(buffer.str().c_str());
1876 element->LinkEndChild(text);
1880 element = document->NewElement(
"MaximumGeneralizationPerformanceDecreases");
1881 root_element->LinkEndChild(element);
1886 text = document->NewText(buffer.str().c_str());
1887 element->LinkEndChild(text);
1891 element = document->NewElement(
"MaximumIterationsNumber");
1892 root_element->LinkEndChild(element);
1897 text = document->NewText(buffer.str().c_str());
1898 element->LinkEndChild(text);
1902 element = document->NewElement(
"MaximumTime");
1903 root_element->LinkEndChild(element);
1908 text = document->NewText(buffer.str().c_str());
1909 element->LinkEndChild(text);
1913 element = document->NewElement(
"ReserveParametersHistory");
1914 root_element->LinkEndChild(element);
1919 text = document->NewText(buffer.str().c_str());
1920 element->LinkEndChild(text);
1924 element = document->NewElement(
"ReserveParametersNormHistory");
1925 root_element->LinkEndChild(element);
1930 text = document->NewText(buffer.str().c_str());
1931 element->LinkEndChild(text);
1935 element = document->NewElement(
"ReservePerformanceHistory");
1936 root_element->LinkEndChild(element);
1941 text = document->NewText(buffer.str().c_str());
1942 element->LinkEndChild(text);
1946 element = document->NewElement(
"ReserveGeneralizationPerformanceHistory");
1947 root_element->LinkEndChild(element);
1952 text = document->NewText(buffer.str().c_str());
1953 element->LinkEndChild(text);
1957 element = document->NewElement(
"ReserveGradientHistory");
1958 root_element->LinkEndChild(element);
1963 text = document->NewText(buffer.str().c_str());
1964 element->LinkEndChild(text);
1968 element = document->NewElement(
"ReserveGradientNormHistory");
1969 root_element->LinkEndChild(element);
1974 text = document->NewText(buffer.str().c_str());
1975 element->LinkEndChild(text);
1979 element = document->NewElement(
"ReserveTrainingDirectionHistory");
1980 root_element->LinkEndChild(element);
1985 text = document->NewText(buffer.str().c_str());
1986 element->LinkEndChild(text);
1990 element = document->NewElement(
"ReserveTrainingRateHistory");
1991 root_element->LinkEndChild(element);
1996 text = document->NewText(buffer.str().c_str());
1997 element->LinkEndChild(text);
2001 element = document->NewElement(
"ReserveElapsedTimeHistory");
2002 root_element->LinkEndChild(element);
2007 text = document->NewText(buffer.str().c_str());
2008 element->LinkEndChild(text);
2012 element = document->NewElement(
"ReserveGeneralizationPerformanceHistory");
2013 root_element->LinkEndChild(element);
2018 text = document->NewText(buffer.str().c_str());
2019 element->LinkEndChild(text);
2023 element = document->NewElement(
"DisplayPeriod");
2024 root_element->LinkEndChild(element);
2029 text = document->NewText(buffer.str().c_str());
2030 element->LinkEndChild(text);
2034 element = document->NewElement(
"SavePeriod");
2035 root_element->LinkEndChild(element);
2040 text = document->NewText(buffer.str().c_str());
2041 element->LinkEndChild(text);
2045 element = document->NewElement(
"NeuralNetworkFileName");
2046 root_element->LinkEndChild(element);
2049 element->LinkEndChild(text);
2053 element = document->NewElement(
"Display");
2054 root_element->LinkEndChild(element);
2059 text = document->NewText(buffer.str().c_str());
2060 element->LinkEndChild(text);
2070 const tinyxml2::XMLElement* root_element = document.FirstChildElement(
"GradientDescent");
2074 std::ostringstream buffer;
2076 buffer <<
"OpenNN Exception: GradientDescent class.\n"
2077 <<
"void from_XML(const tinyxml2::XMLDocument&) method.\n"
2078 <<
"Gradient descent element is NULL.\n";
2080 throw std::logic_error(buffer.str());
2085 const tinyxml2::XMLElement* training_rate_algorithm_element = root_element->FirstChildElement(
"TrainingRateAlgorithm");
2087 if(training_rate_algorithm_element)
2089 tinyxml2::XMLDocument training_rate_algorithm_document;
2091 tinyxml2::XMLElement* element_clone = training_rate_algorithm_document.NewElement(
"TrainingRateAlgorithm");
2092 training_rate_algorithm_document.InsertFirstChild(element_clone);
2094 DeepClone(element_clone, training_rate_algorithm_element, &training_rate_algorithm_document, NULL);
2102 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"WarningParametersNorm");
2106 const double new_warning_parameters_norm = atof(element->GetText());
2112 catch(
const std::logic_error& e)
2114 std::cout << e.what() << std::endl;
2121 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"WarningGradientNorm");
2125 const double new_warning_gradient_norm = atof(element->GetText());
2131 catch(
const std::logic_error& e)
2133 std::cout << e.what() << std::endl;
2140 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"WarningTrainingRate");
2144 const double new_warning_training_rate = atof(element->GetText());
2150 catch(
const std::logic_error& e)
2152 std::cout << e.what() << std::endl;
2159 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"ErrorParametersNorm");
2163 const double new_error_parameters_norm = atof(element->GetText());
2169 catch(
const std::logic_error& e)
2171 std::cout << e.what() << std::endl;
2178 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"ErrorGradientNorm");
2182 const double new_error_gradient_norm = atof(element->GetText());
2188 catch(
const std::logic_error& e)
2190 std::cout << e.what() << std::endl;
2197 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"ErrorTrainingRate");
2201 const double new_error_training_rate = atof(element->GetText());
2207 catch(
const std::logic_error& e)
2209 std::cout << e.what() << std::endl;
2216 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"MinimumParametersIncrementNorm");
2220 const double new_minimum_parameters_increment_norm = atof(element->GetText());
2226 catch(
const std::logic_error& e)
2228 std::cout << e.what() << std::endl;
2235 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"MinimumPerformanceIncrease");
2239 const double new_minimum_performance_increase = atof(element->GetText());
2245 catch(
const std::logic_error& e)
2247 std::cout << e.what() << std::endl;
2254 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"PerformanceGoal");
2258 const double new_performance_goal = atof(element->GetText());
2264 catch(
const std::logic_error& e)
2266 std::cout << e.what() << std::endl;
2273 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"GradientNormGoal");
2277 const double new_gradient_norm_goal = atof(element->GetText());
2283 catch(
const std::logic_error& e)
2285 std::cout << e.what() << std::endl;
2292 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"MaximumGeneralizationPerformanceDecreases");
2296 const size_t new_maximum_generalization_performance_decreases = atoi(element->GetText());
2302 catch(
const std::logic_error& e)
2304 std::cout << e.what() << std::endl;
2311 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"MaximumIterationsNumber");
2315 const size_t new_maximum_iterations_number = atoi(element->GetText());
2321 catch(
const std::logic_error& e)
2323 std::cout << e.what() << std::endl;
2330 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"MaximumTime");
2334 const double new_maximum_time = atof(element->GetText());
2340 catch(
const std::logic_error& e)
2342 std::cout << e.what() << std::endl;
2349 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"ReserveParametersHistory");
2353 const std::string new_reserve_parameters_history = element->GetText();
2359 catch(
const std::logic_error& e)
2361 std::cout << e.what() << std::endl;
2368 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"ReserveParametersNormHistory");
2372 const std::string new_reserve_parameters_norm_history = element->GetText();
2378 catch(
const std::logic_error& e)
2380 std::cout << e.what() << std::endl;
2387 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"ReservePerformanceHistory");
2391 const std::string new_reserve_performance_history = element->GetText();
2397 catch(
const std::logic_error& e)
2399 std::cout << e.what() << std::endl;
2406 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"ReserveGeneralizationPerformanceHistory");
2410 const std::string new_reserve_generalization_performance_history = element->GetText();
2416 catch(
const std::logic_error& e)
2418 std::cout << e.what() << std::endl;
2425 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"ReserveGradientHistory");
2429 const std::string new_reserve_gradient_history = element->GetText();
2435 catch(
const std::logic_error& e)
2437 std::cout << e.what() << std::endl;
2444 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"ReserveGradientNormHistory");
2448 const std::string new_reserve_gradient_norm_history = element->GetText();
2454 catch(
const std::logic_error& e)
2456 std::cout << e.what() << std::endl;
2463 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"ReserveTrainingDirectionHistory");
2467 const std::string new_reserve_training_direction_history = element->GetText();
2473 catch(
const std::logic_error& e)
2475 std::cout << e.what() << std::endl;
2482 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"ReserveTrainingRateHistory");
2486 const std::string new_reserve_training_rate_history = element->GetText();
2492 catch(
const std::logic_error& e)
2494 std::cout << e.what() << std::endl;
2501 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"ReserveElapsedTimeHistory");
2505 const std::string new_reserve_elapsed_time_history = element->GetText();
2511 catch(
const std::logic_error& e)
2513 std::cout << e.what() << std::endl;
2520 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"ReserveGeneralizationPerformanceHistory");
2524 const std::string new_reserve_generalization_performance_history = element->GetText();
2530 catch(
const std::logic_error& e)
2532 std::cout << e.what() << std::endl;
2539 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"DisplayPeriod");
2543 const size_t new_display_period = atoi(element->GetText());
2549 catch(
const std::logic_error& e)
2551 std::cout << e.what() << std::endl;
2558 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"SavePeriod");
2562 const size_t new_save_period = atoi(element->GetText());
2568 catch(
const std::logic_error& e)
2570 std::cout << e.what() << std::endl;
2577 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"NeuralNetworkFileName");
2581 const std::string new_neural_network_file_name = element->GetText();
2587 catch(
const std::logic_error& e)
2589 std::cout << e.what() << std::endl;
2596 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"Display");
2600 const std::string new_display = element->GetText();
2606 catch(
const std::logic_error& e)
2608 std::cout << e.what() << std::endl;
const bool & get_reserve_elapsed_time_history(void) const
Returns true if the elapsed time history vector is to be reserved, and false otherwise.
bool reserve_training_direction_history
True if the training direction history matrix is to be reserved, false otherwise. ...
bool reserve_training_rate_history
True if the training rate history vector is to be reserved, false otherwise.
Vector< double > training_rate_history
History of the random search training rate over the training iterations.
void set_reserve_all_training_history(const bool &)
void set_performance_goal(const double &)
size_t count_parameters_number(void) const
const bool & get_reserve_gradient_norm_history(void) const
Returns true if the gradient norm history vector is to be reserved, and false otherwise.
void set_reserve_elapsed_time_history(const bool &)
const double & get_minimum_performance_increase(void) const
Returns the minimum performance improvement during training.
TrainingRateAlgorithm * get_training_rate_algorithm_pointer(void)
Returns a pointer to the training rate algorithm object inside the gradient descent object...
Vector< double > final_training_direction
Final gradient descent training direction.
Matrix< std::string > to_string_matrix(void) const
size_t maximum_iterations_number
Maximum number of iterations to perform_training. It is used as a stopping criterion.
double warning_parameters_norm
Value for the parameters norm at which a warning message is written to the screen.
double minimum_performance_increase
Minimum performance improvement between two successive iterations. It is used as a stopping criterion...
Vector< double > arrange_parameters(void) const
bool reserve_parameters_norm_history
True if the parameters norm history vector is to be reserved, false otherwise.
Matrix< std::string > write_final_results(const size_t &precision=3) const
Returns a default (empty) string matrix with the final results from training.
size_t iterations_number
Maximum number of training iterations.
void set_performance_functional_pointer(PerformanceFunctional *)
const bool & get_reserve_training_rate_history(void) const
Returns true if the training rate history vector is to be reserved, and false otherwise.
Vector< Vector< double > > gradient_history
History of the performance function gradient over the training iterations.
void set_minimum_performance_increase(const double &)
void set_maximum_generalization_performance_decreases(const size_t &)
double final_parameters_norm
Final neural network parameters norm.
const double & get_gradient_norm_goal(void) const
void set_display_period(const size_t &)
bool display
Display messages to screen.
double maximum_time
Maximum training time. It is used as a stopping criterion.
void set_maximum_iterations_number(const size_t &)
const double & get_warning_gradient_norm(void) const
bool reserve_gradient_history
True if the gradient history matrix is to be reserved, false otherwise.
std::string to_string(void) const
Returns a string representation of the results structure.
const double & get_error_gradient_norm(void) const
void set_warning_parameters_norm(const double &)
const TrainingRateAlgorithm & get_training_rate_algorithm(void) const
Returns a constant reference to the training rate algorithm object inside the gradient descent object...
void set_warning_gradient_norm(const double &)
std::string write_training_rate_method(void) const
Returns a string with the name of the training rate method to be used.
tinyxml2::XMLDocument * to_XML(void) const
void set_reserve_training_rate_history(const bool &)
void set_reserve_gradient_norm_history(const bool &)
double error_gradient_norm
Value for the gradient norm at which the training process is assumed to fail.
bool reserve_gradient_norm_history
True if the gradient norm history vector is to be reserved, false otherwise.
void set_warning_training_rate(const double &)
void set_save_period(const size_t &)
Vector< double > generalization_performance_history
History of the generalization performance over the training iterations.
void set_minimum_parameters_increment_norm(const double &)
double warning_training_rate
Training rate value at wich a warning message is written to the screen.
std::string write_training_algorithm_type(void) const
This method writes a string with the type of training algoritm.
GradientDescentResults * perform_training(void)
const double & get_error_training_rate(void) const
Vector< Vector< double > > training_direction_history
History of the random search training direction over the training iterations.
Vector< Vector< double > > parameters_history
History of the neural network parameters over the training iterations.
void set_default(void)
Sets the members of the training algorithm object to their default values.
const bool & get_reserve_training_direction_history(void) const
Returns true if the training direction history matrix is to be reserved, and false otherwise...
size_t save_period
Number of iterations between the training saving progress.
Vector< double > calculate_directional_point(const double &, const Vector< double > &, const double &) const
double warning_gradient_norm
Value for the gradient norm at which a warning message is written to the screen.
tinyxml2::XMLDocument * to_XML(void) const
double performance_goal
Goal value for the performance. It is used as a stopping criterion.
bool reserve_parameters_history
True if the parameters history matrix is to be reserved, false otherwise.
double final_generalization_performance
Final generalization performance.
void set_error_training_rate(const double &)
double calculate_norm(void) const
Returns the vector norm.
const bool & get_reserve_gradient_history(void) const
Returns true if the gradient history vector of vectors is to be reserved, and false otherwise...
Vector< double > calculate_training_direction(const Vector< double > &) const
void resize_training_history(const size_t &)
void set_display(const bool &)
bool reserve_elapsed_time_history
True if the elapsed time history vector is to be reserved, false otherwise.
TrainingRateAlgorithm training_rate_algorithm
Training rate algorithm object for one-dimensional minimization.
void set_gradient_norm_goal(const double &)
std::string neural_network_file_name
Path where the neural network is saved.
const size_t & get_maximum_generalization_performance_decreases(void) const
Returns the maximum number of generalization failures during the training process.
double error_parameters_norm
Value for the parameters norm at which the training process is assumed to fail.
void set_neural_network_file_name(const std::string &)
void set_reserve_training_direction_history(const bool &)
void set_reserve_performance_history(const bool &)
void set_column(const size_t &, const Vector< T > &)
void set_reserve_generalization_performance_history(const bool &)
Vector< T > calculate_normalized(void) const
Returns this vector divided by its norm.
double gradient_norm_goal
Goal value for the norm of the objective function gradient. It is used as a stopping criterion...
double elapsed_time
Elapsed time of the training process.
Vector< double > performance_history
History of the performance function performance over the training iterations.
void from_XML(const tinyxml2::XMLDocument &)
void set_maximum_time(const double &)
void set_reserve_parameters_norm_history(const bool &)
const double & get_minimum_parameters_increment_norm(void) const
Returns the minimum norm of the parameter increment vector used as a stopping criteria when training...
void from_XML(const tinyxml2::XMLDocument &)
void set_reserve_gradient_history(const bool &)
void set_error_gradient_norm(const double &)
const double & get_training_rate_tolerance(void) const
Returns the tolerance value in line minimization.
Vector< double > final_gradient
Final performance function gradient.
void save(const std::string &) const
const size_t & get_maximum_iterations_number(void) const
Returns the maximum number of iterations for training.
void set_performance_functional_pointer(PerformanceFunctional *)
const double & get_maximum_time(void) const
Returns the maximum training time.
virtual void check(void) const
Vector< double > elapsed_time_history
History of the elapsed time over the training iterations.
bool reserve_generalization_performance_history
True if the Generalization performance history vector is to be reserved, false otherwise.
std::string stopping_criterion
Stopping criterion.
const double & get_performance_goal(void) const
const bool & get_reserve_performance_history(void) const
Returns true if the performance history vector is to be reserved, and false otherwise.
double final_performance
Final performance function evaluation.
const double & get_warning_training_rate(void) const
const double & get_error_parameters_norm(void) const
size_t maximum_generalization_performance_decreases
const bool & get_reserve_generalization_performance_history(void) const
Returns true if the Generalization performance history vector is to be reserved, and false otherwise...
double minimum_parameters_increment_norm
Norm of the parameters increment vector at which training stops.
const bool & get_reserve_parameters_history(void) const
Returns true if the parameters history matrix is to be reserved, and false otherwise.
double error_training_rate
Training rate at wich the line minimization algorithm is assumed to be unable to bracket a minimum...
void set_error_parameters_norm(const double &)
const bool & get_reserve_parameters_norm_history(void) const
Returns true if the parameters norm history vector is to be reserved, and false otherwise.
Vector< double > parameters_norm_history
History of the parameters norm over the training iterations.
double final_training_rate
Final gradient descent training rate.
PerformanceFunctional * performance_functional_pointer
Pointer to a performance functional for a multilayer perceptron object.
const double & get_warning_parameters_norm(void) const
bool reserve_performance_history
True if the performance history vector is to be reserved, false otherwise.
virtual ~GradientDescent(void)
Destructor.
void set_training_rate_algorithm(const TrainingRateAlgorithm &)
size_t display_period
Number of iterations between the training showing progress.
Vector< double > final_parameters
Final neural network parameters vector.
double final_gradient_norm
Final gradient norm.
Vector< double > gradient_norm_history
History of the gradient norm over the training iterations.
void set_reserve_parameters_history(const bool &)
void set_parameters(const Vector< double > &)