OpenNN  2.2
Open Neural Networks Library
newton_method.cpp
1 /****************************************************************************************************************/
2 /* */
3 /* OpenNN: Open Neural Networks Library */
4 /* www.artelnics.com/opennn */
5 /* */
6 /* N E W T O N M E T H O D C L A S S */
7 /* */
8 /* Roberto Lopez */
9 /* Artelnics - Making intelligent use of data */
11 /* */
12 /****************************************************************************************************************/
13 
14 // OpenNN includes
15 
16 #include "newton_method.h"
17 
18 namespace OpenNN
19 {
20 
21 // DEFAULT CONSTRUCTOR
22 
26 
29 {
30  set_default();
31 }
32 
33 
34 // PERFORMANCE FUNCTIONAL CONSTRUCTOR
35 
40 
41 NewtonMethod::NewtonMethod(PerformanceFunctional* new_performance_functional_pointer)
42 : TrainingAlgorithm(new_performance_functional_pointer)
43 {
44  training_rate_algorithm.set_performance_functional_pointer(new_performance_functional_pointer);
45 
46  set_default();
47 }
48 
49 
50 // XML CONSTRUCTOR
51 
55 
56 NewtonMethod::NewtonMethod(const tinyxml2::XMLDocument& document)
57  : TrainingAlgorithm(document)
58 {
59  set_default();
60 
61  from_XML(document);
62 }
63 
64 
65 // DESTRUCTOR
66 
68 
70 {
71 }
72 
73 
74 // METHODS
75 
76 // const TrainingRateAlgorithm& get_training_rate_algorithm(void) const method
77 
79 
81 {
83 }
84 
85 
86 // TrainingRateAlgorithm* get_training_rate_algorithm_pointer(void) method
87 
89 
91 {
92  return(&training_rate_algorithm);
93 }
94 
95 
96 // const double& get_warning_parameters_norm(void) const method
97 
100 
102 {
103  return(warning_parameters_norm);
104 }
105 
106 
107 // const double& get_warning_gradient_norm(void) const method
108 
111 
113 {
114  return(warning_gradient_norm);
115 }
116 
117 
118 // const double& get_warning_training_rate(void) const method
119 
122 
124 {
125  return(warning_training_rate);
126 }
127 
128 
129 // const double& get_error_parameters_norm(void) const method
130 
133 
135 {
136  return(error_parameters_norm);
137 }
138 
139 
140 // const double& get_error_gradient_norm(void) const method
141 
144 
145 const double& NewtonMethod::get_error_gradient_norm(void) const
146 {
147  return(error_gradient_norm);
148 }
149 
150 
151 // const double& get_error_training_rate(void) const method
152 
155 
156 const double& NewtonMethod::get_error_training_rate(void) const
157 {
158  return(error_training_rate);
159 }
160 
161 
162 // const double& get_minimum_parameters_increment_norm(void) const method
163 
165 
167 {
169 }
170 
171 
172 // const double& get_minimum_performance_increase(void) const method
173 
175 
177 {
179 }
180 
181 
182 // const double& get_performance_goal(void) const method
183 
186 
187 const double& NewtonMethod::get_performance_goal(void) const
188 {
189  return(performance_goal);
190 }
191 
192 
193 // const double& get_gradient_norm_goal(void) const method
194 
197 
198 const double& NewtonMethod::get_gradient_norm_goal(void) const
199 {
200  return(gradient_norm_goal);
201 }
202 
203 
204 // const size_t& get_maximum_generalization_performance_decreases(void) const method
205 
207 
209 {
211 }
212 
213 
214 // const size_t& get_maximum_iterations_number(void) const method
215 
217 
219 {
221 }
222 
223 
224 // const double& get_maximum_time(void) const method
225 
227 
228 const double& NewtonMethod::get_maximum_time(void) const
229 {
230  return(maximum_time);
231 }
232 
233 
234 // const bool& get_reserve_parameters_history(void) const method
235 
237 
239 {
241 }
242 
243 
244 // const bool& get_reserve_parameters_norm_history(void) const method
245 
247 
249 {
251 }
252 
253 
254 // const bool& get_reserve_performance_history(void) const method
255 
257 
259 {
261 }
262 
263 
264 // const bool& get_reserve_gradient_history(void) const method
265 
267 
269 {
270  return(reserve_gradient_history);
271 }
272 
273 
274 // const bool& get_reserve_gradient_norm_history(void) const method
275 
277 
279 {
281 }
282 
283 
284 // const bool& get_reserve_inverse_Hessian_history(void) const method
285 
287 
289 {
291 }
292 
293 
294 // const bool& get_reserve_training_direction_history(void) const method
295 
297 
299 {
301 }
302 
303 
304 // const bool& get_reserve_training_rate_history(void) const method
305 
307 
309 {
311 }
312 
313 
314 // const bool& get_reserve_elapsed_time_history(void) const method
315 
317 
319 {
321 }
322 
323 
324 // const bool& get_reserve_generalization_performance_history(void) const method
325 
327 
329 {
331 }
332 
333 
334 // void set_performance_functional_pointer(PerformanceFunctional*) method
335 
339 
341 {
342  performance_functional_pointer = new_performance_functional_pointer;
343 
344  training_rate_algorithm.set_performance_functional_pointer(new_performance_functional_pointer);
345 }
346 
347 
348 // void set_default(void) method
349 
351 {
352  // TRAINING PARAMETERS
353 
354  warning_parameters_norm = 1.0e6;
355  warning_gradient_norm = 1.0e6;
356  warning_training_rate = 1.0e6;
357 
358  error_parameters_norm = 1.0e9;
359  error_gradient_norm = 1.0e9;
360  error_training_rate = 1.0e9;
361 
362  // STOPPING CRITERIA
363 
365 
367  performance_goal = -1.0e99;
368  gradient_norm_goal = 0.0;
370 
372  maximum_time = 1000.0;
373 
374  // TRAINING HISTORY
375 
378 
380  reserve_gradient_history = false;
383 
387 
388  // UTILITIES
389 
390  display = true;
391  display_period = 10;
392 
393 }
394 
395 
396 // void set_warning_parameters_norm(const double&) method
397 
401 
402 void NewtonMethod::set_warning_parameters_norm(const double& new_warning_parameters_norm)
403 {
404  // Control sentence (if debug)
405 
406  #ifndef NDEBUG
407 
408  if(new_warning_parameters_norm < 0.0)
409  {
410  std::ostringstream buffer;
411 
412  buffer << "OpenNN Exception: NewtonMethod class.\n"
413  << "void set_warning_parameters_norm(const double&) method.\n"
414  << "Warning parameters norm must be equal or greater than 0.\n";
415 
416  throw std::logic_error(buffer.str());
417  }
418 
419  #endif
420 
421  // Set warning parameters norm
422 
423  warning_parameters_norm = new_warning_parameters_norm;
424 }
425 
426 
427 // void set_warning_gradient_norm(const double&) method
428 
432 
433 void NewtonMethod::set_warning_gradient_norm(const double& new_warning_gradient_norm)
434 {
435  // Control sentence (if debug)
436 
437  #ifndef NDEBUG
438 
439  if(new_warning_gradient_norm < 0.0)
440  {
441  std::ostringstream buffer;
442 
443  buffer << "OpenNN Exception: NewtonMethod class.\n"
444  << "void set_warning_gradient_norm(const double&) method.\n"
445  << "Warning gradient norm must be equal or greater than 0.\n";
446 
447  throw std::logic_error(buffer.str());
448  }
449 
450  #endif
451 
452  // Set warning gradient norm
453 
454  warning_gradient_norm = new_warning_gradient_norm;
455 }
456 
457 
458 // void set_warning_training_rate(const double&) method
459 
463 
464 void NewtonMethod::set_warning_training_rate(const double& new_warning_training_rate)
465 {
466  // Control sentence (if debug)
467 
468  #ifndef NDEBUG
469 
470  if(new_warning_training_rate < 0.0)
471  {
472  std::ostringstream buffer;
473 
474  buffer << "OpenNN Exception: NewtonMethod class.\n"
475  << "void set_warning_training_rate(const double&) method.\n"
476  << "Warning training rate must be equal or greater than 0.\n";
477 
478  throw std::logic_error(buffer.str());
479  }
480 
481  #endif
482 
483  warning_training_rate = new_warning_training_rate;
484 }
485 
486 
487 // void set_error_parameters_norm(const double&) method
488 
492 
493 void NewtonMethod::set_error_parameters_norm(const double& new_error_parameters_norm)
494 {
495  // Control sentence (if debug)
496 
497  #ifndef NDEBUG
498 
499  if(new_error_parameters_norm < 0.0)
500  {
501  std::ostringstream buffer;
502 
503  buffer << "OpenNN Exception: NewtonMethod class.\n"
504  << "void set_error_parameters_norm(const double&) method.\n"
505  << "Error parameters norm must be equal or greater than 0.\n";
506 
507  throw std::logic_error(buffer.str());
508  }
509 
510  #endif
511 
512  // Set error parameters norm
513 
514  error_parameters_norm = new_error_parameters_norm;
515 }
516 
517 
518 // void set_error_gradient_norm(const double&) method
519 
523 
524 void NewtonMethod::set_error_gradient_norm(const double& new_error_gradient_norm)
525 {
526  // Control sentence (if debug)
527 
528  #ifndef NDEBUG
529 
530  if(new_error_gradient_norm < 0.0)
531  {
532  std::ostringstream buffer;
533 
534  buffer << "OpenNN Exception: NewtonMethod class.\n"
535  << "void set_error_gradient_norm(const double&) method.\n"
536  << "Error gradient norm must be equal or greater than 0.\n";
537 
538  throw std::logic_error(buffer.str());
539  }
540 
541  #endif
542 
543  // Set error gradient norm
544 
545  error_gradient_norm = new_error_gradient_norm;
546 }
547 
548 
549 // void set_error_training_rate(const double&) method
550 
554 
555 void NewtonMethod::set_error_training_rate(const double& new_error_training_rate)
556 {
557  // Control sentence (if debug)
558 
559  #ifndef NDEBUG
560 
561  if(new_error_training_rate < 0.0)
562  {
563  std::ostringstream buffer;
564 
565  buffer << "OpenNN Exception: NewtonMethod class.\n"
566  << "void set_error_training_rate(const double&) method.\n"
567  << "Error training rate must be equal or greater than 0.\n";
568 
569  throw std::logic_error(buffer.str());
570  }
571 
572  #endif
573 
574  // Set error training rate
575 
576  error_training_rate = new_error_training_rate;
577 }
578 
579 
580 // void set_minimum_parameters_increment_norm(const double&) method
581 
584 
585 void NewtonMethod::set_minimum_parameters_increment_norm(const double& new_minimum_parameters_increment_norm)
586 {
587  // Control sentence (if debug)
588 
589  #ifndef NDEBUG
590 
591  if(new_minimum_parameters_increment_norm < 0.0)
592  {
593  std::ostringstream buffer;
594 
595  buffer << "OpenNN Exception: NewtonMethod class.\n"
596  << "void new_minimum_parameters_increment_norm(const double&) method.\n"
597  << "Minimum parameters increment norm must be equal or greater than 0.\n";
598 
599  throw std::logic_error(buffer.str());
600  }
601 
602  #endif
603 
604  // Set error training rate
605 
606  minimum_parameters_increment_norm = new_minimum_parameters_increment_norm;
607 }
608 
609 
610 // void set_minimum_performance_increase(const double&) method
611 
614 
615 void NewtonMethod::set_minimum_performance_increase(const double& new_minimum_performance_increase)
616 {
617  // Control sentence (if debug)
618 
619  #ifndef NDEBUG
620 
621  if(new_minimum_performance_increase < 0.0)
622  {
623  std::ostringstream buffer;
624 
625  buffer << "OpenNN Exception: NewtonMethod class.\n"
626  << "void set_minimum_performance_increase(const double&) method.\n"
627  << "Minimum performance improvement must be equal or greater than 0.\n";
628 
629  throw std::logic_error(buffer.str());
630  }
631 
632  #endif
633 
634  // Set minimum performance improvement
635 
636  minimum_performance_increase = new_minimum_performance_increase;
637 }
638 
639 
640 // void set_performance_goal(const double&) method
641 
645 
646 void NewtonMethod::set_performance_goal(const double& new_performance_goal)
647 {
648  performance_goal = new_performance_goal;
649 }
650 
651 
652 // void set_gradient_norm_goal(const double&) method
653 
657 
658 void NewtonMethod::set_gradient_norm_goal(const double& new_gradient_norm_goal)
659 {
660  // Control sentence (if debug)
661 
662  #ifndef NDEBUG
663 
664  if(new_gradient_norm_goal < 0.0)
665  {
666  std::ostringstream buffer;
667 
668  buffer << "OpenNN Exception: NewtonMethod class.\n"
669  << "void set_gradient_norm_goal(const double&) method.\n"
670  << "Gradient norm goal must be equal or greater than 0.\n";
671 
672  throw std::logic_error(buffer.str());
673  }
674 
675  #endif
676 
677  // Set gradient norm goal
678 
679  gradient_norm_goal = new_gradient_norm_goal;
680 }
681 
682 
683 // void set_maximum_generalization_performance_decreases(const size_t&) method
684 
687 
688 void NewtonMethod::set_maximum_generalization_performance_decreases(const size_t& new_maximum_generalization_performance_decreases)
689 {
690  maximum_generalization_performance_decreases = new_maximum_generalization_performance_decreases;
691 }
692 
693 
694 // void set_maximum_iterations_number(size_t) method
695 
698 
699 void NewtonMethod::set_maximum_iterations_number(const size_t& new_maximum_iterations_number)
700 {
701  maximum_iterations_number = new_maximum_iterations_number;
702 }
703 
704 
705 // void set_maximum_time(const double&) method
706 
709 
710 void NewtonMethod::set_maximum_time(const double& new_maximum_time)
711 {
712  // Control sentence (if debug)
713 
714  #ifndef NDEBUG
715 
716  if(new_maximum_time < 0.0)
717  {
718  std::ostringstream buffer;
719 
720  buffer << "OpenNN Exception: NewtonMethod class.\n"
721  << "void set_maximum_time(const double&) method.\n"
722  << "Maximum time must be equal or greater than 0.\n";
723 
724  throw std::logic_error(buffer.str());
725  }
726 
727  #endif
728 
729  // Set maximum time
730 
731  maximum_time = new_maximum_time;
732 }
733 
734 
735 // void set_reserve_parameters_history(bool) method
736 
739 
740 void NewtonMethod::set_reserve_parameters_history(const bool& new_reserve_parameters_history)
741 {
742  reserve_parameters_history = new_reserve_parameters_history;
743 }
744 
745 
746 // void set_reserve_parameters_norm_history(bool) method
747 
750 
751 void NewtonMethod::set_reserve_parameters_norm_history(const bool& new_reserve_parameters_norm_history)
752 {
753  reserve_parameters_norm_history = new_reserve_parameters_norm_history;
754 }
755 
756 
757 // void set_reserve_performance_history(bool) method
758 
761 
762 void NewtonMethod::set_reserve_performance_history(const bool& new_reserve_performance_history)
763 {
764  reserve_performance_history = new_reserve_performance_history;
765 }
766 
767 
768 // void set_reserve_gradient_history(bool) method
769 
772 
773 void NewtonMethod::set_reserve_gradient_history(const bool& new_reserve_gradient_history)
774 {
775  reserve_gradient_history = new_reserve_gradient_history;
776 }
777 
778 
779 // void set_reserve_gradient_norm_history(bool) method
780 
784 
785 void NewtonMethod::set_reserve_gradient_norm_history(const bool& new_reserve_gradient_norm_history)
786 {
787  reserve_gradient_norm_history = new_reserve_gradient_norm_history;
788 }
789 
790 
791 // void set_reserve_inverse_Hessian_history(bool) method
792 
796 
797 void NewtonMethod::set_reserve_inverse_Hessian_history(const bool& new_reserve_inverse_Hessian_history)
798 {
799  reserve_inverse_Hessian_history = new_reserve_inverse_Hessian_history;
800 }
801 
802 
803 // void set_reserve_training_direction_history(bool) method
804 
808 
809 void NewtonMethod::set_reserve_training_direction_history(const bool& new_reserve_training_direction_history)
810 {
811  reserve_training_direction_history = new_reserve_training_direction_history;
812 }
813 
814 
815 // void set_reserve_training_rate_history(bool) method
816 
820 
821 void NewtonMethod::set_reserve_training_rate_history(const bool& new_reserve_training_rate_history)
822 {
823  reserve_training_rate_history = new_reserve_training_rate_history;
824 }
825 
826 
827 // void set_reserve_elapsed_time_history(bool) method
828 
832 
833 void NewtonMethod::set_reserve_elapsed_time_history(const bool& new_reserve_elapsed_time_history)
834 {
835  reserve_elapsed_time_history = new_reserve_elapsed_time_history;
836 }
837 
838 
839 // void set_reserve_generalization_performance_history(bool) method
840 
844 
845 void NewtonMethod::set_reserve_generalization_performance_history(const bool& new_reserve_generalization_performance_history)
846 {
847  reserve_generalization_performance_history = new_reserve_generalization_performance_history;
848 }
849 
850 
851 // void set_display_period(size_t) method
852 
856 
857 void NewtonMethod::set_display_period(const size_t& new_display_period)
858 {
859  // Control sentence (if debug)
860 
861  #ifndef NDEBUG
862 
863  if(new_display_period <= 0)
864  {
865  std::ostringstream buffer;
866 
867  buffer << "OpenNN Exception: NewtonMethod class.\n"
868  << "void set_display_period(const double&) method.\n"
869  << "First training rate must be greater than 0.\n";
870 
871  throw std::logic_error(buffer.str());
872  }
873 
874  #endif
875 
876  display_period = new_display_period;
877 }
878 
879 
880 
881 // Vector<double> calculate_gradient_descent_training_direction(const Vector<double>&) const method
882 
885 
887 {
888  // Control sentence (if debug)
889 
890  #ifndef NDEBUG
891 
892  std::ostringstream buffer;
893 
895  {
896  buffer << "OpenNN Exception: NewtonMethod class.\n"
897  << "Vector<double> calculate_gradient_descent_training_direction(const Vector<double>&) const method.\n"
898  << "Performance functional pointer is NULL.\n";
899 
900  throw std::logic_error(buffer.str());
901  }
902 
904 
905  const size_t parameters_number = neural_network_pointer->count_parameters_number();
906 
907  const size_t gradient_size = gradient.size();
908 
909  if(gradient_size != parameters_number)
910  {
911  buffer << "OpenNN Exception: NewtonMethod class.\n"
912  << "Vector<double> calculate_gradient_descent_training_direction(const Vector<double>&) const method.\n"
913  << "Size of gradient (" << gradient_size << ") is not equal to number of parameters (" << parameters_number << ").\n";
914 
915  throw std::logic_error(buffer.str());
916  }
917 
918  #endif
919 
920  return(gradient.calculate_normalized()*(-1.0));
921 }
922 
923 
924 // Vector<double> calculate_training_direction(const Vector<double>&, const Matrix<double>&) const method
925 
929 
931 (const Vector<double>& gradient, const Matrix<double>& inverse_Hessian) const
932 {
933  return((inverse_Hessian.dot(gradient)*(-1.0)).calculate_normalized());
934 }
935 
936 
937 // void resize_training_history(const size_t&) method
938 
941 
943 {
944  // Control sentence (if debug)
945 
946  #ifndef NDEBUG
947 
948  if(Newton_method_pointer == NULL)
949  {
950  std::ostringstream buffer;
951 
952  buffer << "OpenNN Exception: NewtonMethodResults structure.\n"
953  << "void resize_training_history(const size_t&) method.\n"
954  << "NewtonMethod pointer is NULL.\n";
955 
956  throw std::logic_error(buffer.str());
957  }
958 
959  #endif
960 
962  {
963  parameters_history.resize(new_size);
964  }
965 
967  {
968  parameters_norm_history.resize(new_size);
969  }
970 
972  {
973  performance_history.resize(new_size);
974  }
975 
977  {
978  generalization_performance_history.resize(new_size);
979  }
980 
982  {
983  gradient_history.resize(new_size);
984  }
985 
987  {
988  gradient_norm_history.resize(new_size);
989  }
990 
992  {
993  inverse_Hessian_history.resize(new_size);
994  }
995 
997  {
998  training_direction_history.resize(new_size);
999  }
1000 
1002  {
1003  training_rate_history.resize(new_size);
1004  }
1005 
1007  {
1008  elapsed_time_history.resize(new_size);
1009  }
1010 }
1011 
1012 
1013 // std::string to_string(void) const method
1014 
1016 
1018 {
1019  std::ostringstream buffer;
1020 
1021  // Parameters history
1022 
1023  if(!parameters_history.empty())
1024  {
1025  if(!parameters_history[0].empty())
1026  {
1027  buffer << "% Parameters history:\n"
1028  << parameters_history << "\n";
1029  }
1030  }
1031 
1032  // Parameters norm history
1033 
1034  if(!parameters_norm_history.empty())
1035  {
1036  buffer << "% Parameters norm history:\n"
1037  << parameters_norm_history << "\n";
1038  }
1039 
1040  // performance history
1041 
1042  if(!performance_history.empty())
1043  {
1044  buffer << "% performance history:\n"
1045  << performance_history << "\n";
1046  }
1047 
1048  // Generalization performance history
1049 
1050  if(!generalization_performance_history.empty())
1051  {
1052  buffer << "% Generalization performance history:\n"
1053  << generalization_performance_history << "\n";
1054  }
1055 
1056  // Gradient history
1057 
1058  if(!gradient_history.empty())
1059  {
1060  if(!gradient_history[0].empty())
1061  {
1062  buffer << "% Gradient history:\n"
1063  << gradient_history << "\n";
1064  }
1065  }
1066 
1067  // Gradient norm history
1068 
1069  if(!gradient_norm_history.empty())
1070  {
1071  buffer << "% Gradient norm history:\n"
1072  << gradient_norm_history << "\n";
1073  }
1074 
1075  // Inverse Hessian history
1076 
1077  if(!inverse_Hessian_history.empty())
1078  {
1079  if(!inverse_Hessian_history[0].empty())
1080  {
1081  buffer << "% Inverse Hessian history:\n"
1082  << inverse_Hessian_history << "\n";
1083  }
1084  }
1085 
1086  // Training direction history
1087 
1088  if(!training_direction_history.empty())
1089  {
1090  if(!training_direction_history[0].empty())
1091  {
1092  buffer << "% Training direction history:\n"
1093  << training_direction_history << "\n";
1094  }
1095  }
1096 
1097  // Training rate history
1098 
1099  if(!training_rate_history.empty())
1100  {
1101  buffer << "% Training rate history:\n"
1102  << training_rate_history << "\n";
1103  }
1104 
1105  // Elapsed time history
1106 
1107  if(!elapsed_time_history.empty())
1108  {
1109  buffer << "% Elapsed time history:\n"
1110  << elapsed_time_history << "\n";
1111  }
1112 
1113  return(buffer.str());
1114 }
1115 
1116 
1117 // Matrix<std::string> write_final_results(const size_t& precision = 3) const method
1118 
1120 {
1121  std::ostringstream buffer;
1122 
1123  Vector<std::string> names;
1124  Vector<std::string> values;
1125 
1126  // Final parameters norm
1127 
1128  names.push_back("Final parameters norm");
1129 
1130  buffer.str("");
1131  buffer << std::setprecision(precision) << final_parameters_norm;
1132 
1133  values.push_back(buffer.str());
1134 
1135  // Final performance
1136 
1137  names.push_back("Final performance");
1138 
1139  buffer.str("");
1140  buffer << std::setprecision(precision) << final_performance;
1141 
1142  values.push_back(buffer.str());
1143 
1144  // Final generalization performance
1145 
1146  const PerformanceFunctional* performance_functional_pointer = Newton_method_pointer->get_performance_functional_pointer();
1147 
1148  if(performance_functional_pointer->has_generalization())
1149  {
1150  names.push_back("Final generalization performance");
1151 
1152  buffer.str("");
1153  buffer << std::setprecision(precision) << final_generalization_performance;
1154 
1155  values.push_back(buffer.str());
1156  }
1157 
1158  // Final gradient norm
1159 
1160  names.push_back("Final gradient norm");
1161 
1162  buffer.str("");
1163  buffer << std::setprecision(precision) << final_gradient_norm;
1164 
1165  values.push_back(buffer.str());
1166 
1167  // Final training rate
1168 
1169 // names.push_back("Final training rate");
1170 
1171 // buffer.str("");
1172 // buffer << std::setprecision(precision) << final_training_rate;
1173 
1174 // values.push_back(buffer.str());
1175 
1176  // Iterations number
1177 
1178  names.push_back("Iterations number");
1179 
1180  buffer.str("");
1181  buffer << iterations_number;
1182 
1183  values.push_back(buffer.str());
1184 
1185  // Elapsed time
1186 
1187  names.push_back("Elapsed time");
1188 
1189  buffer.str("");
1190  buffer << elapsed_time;
1191 
1192  values.push_back(buffer.str());
1193 
1194  const size_t rows_number = names.size();
1195  const size_t columns_number = 2;
1196 
1197  Matrix<std::string> final_results(rows_number, columns_number);
1198 
1199  final_results.set_column(0, names);
1200  final_results.set_column(1, values);
1201 
1202  return(final_results);
1203 }
1204 
1205 
1206 // NewtonMethodResults* perform_training(void) method
1207 
1211 
1213 {
1214  std::ostringstream buffer;
1215 
1216  buffer << "OpenNN Exception: NewtonMethod class.\n"
1217  << "NewtonMethodResults* perform_training(void) method.\n"
1218  << "This method is under development.\n";
1219 
1220  throw std::logic_error(buffer.str());
1221 
1222 /*
1223  // Control sentence (if debug)
1224 
1225  #ifndef NDEBUG
1226 
1227  check();
1228 
1229  #endif
1230 
1231  // Start training
1232 
1233  if(display)
1234  {
1235  std::cout << "Training with Newton's method...\n";
1236  }
1237 
1238  NewtonMethodResults* Newton_method_results_pointer = new NewtonMethodResults(this);
1239 
1240  // Elapsed time
1241 
1242  time_t beginning_time, current_time;
1243  time(&beginning_time);
1244  double elapsed_time;
1245 
1246  // Neural network stuff
1247 
1248  NeuralNetwork* neural_network_pointer = performance_functional_pointer->get_neural_network_pointer();
1249 
1250  const size_t parameters_number = neural_network_pointer->count_parameters_number();
1251 
1252  const Vector<double> parameters = neural_network_pointer->arrange_parameters();
1253  double parameters_norm;
1254 
1255  Vector<double> parameters_increment(parameters_number);
1256  double parameters_increment_norm;
1257 
1258  // Performance functional stuff
1259 
1260  double generalization_performance = 0.0;
1261  double old_generalization_performance = 0.0;
1262  double generalization_performance_increment = 0.0;
1263 
1264  double performance = 0.0;
1265  double old_performance = 0.0;
1266  double performance_increase = 0.0;
1267 
1268  Vector<double> gradient(parameters_number);
1269  double gradient_norm;
1270 
1271  Matrix<double> inverse_Hessian(parameters_number, parameters_number);
1272 
1273  // Training algorithm stuff
1274 
1275  Vector<double> old_gradient(parameters_number);
1276  Vector<double> training_direction(parameters_number);
1277  Vector<double> gradient_descent_training_direction(parameters_number);
1278  Vector<double> old_training_direction(parameters_number);
1279 
1280  double training_slope;
1281 
1282  //double initial_training_rate = 0.0;
1283  double training_rate = 0.0;
1284  //double old_training_rate = 0.0;
1285 
1286  Vector<double> directional_point(2);
1287  directional_point[0] = 0.0;
1288  directional_point[1] = 0.0;
1289 
1290  bool stop_training = false;
1291 
1292 
1293  // Main loop
1294 
1295  for(size_t iteration = 0; iteration <= maximum_iterations_number; iteration++)
1296  {
1297  // Multilayer perceptron
1298 
1299  parameters = neural_network_pointer->arrange_parameters();
1300 
1301  parameters_norm = parameters.calculate_norm();
1302 
1303  if(display && parameters_norm >= warning_parameters_norm)
1304  {
1305  std::cout << "OpenNN Warning: Parameters norm is " << parameters_norm << ".\n";
1306  }
1307 
1308  // Performance functional stuff
1309 
1310  if(iteration == 0)
1311  {
1312  performance = performance_functional_pointer->calculate_performance();
1313  performance_increase = 0.0;
1314  }
1315  else
1316  {
1317  performance = directional_point[1];
1318  performance_increase = old_performance - performance;
1319  }
1320 
1321  generalization_performance = performance_functional_pointer->calculate_generalization_performance();
1322 
1323  if(iteration == 0)
1324  {
1325  generalization_performance_increment = 0.0;
1326  }
1327  else
1328  {
1329  generalization_performance_increment = generalization_performance - old_generalization_performance;
1330  }
1331 
1332  gradient = performance_functional_pointer->calculate_gradient();
1333 
1334  gradient_norm = gradient.calculate_norm();
1335 
1336  if(display && gradient_norm >= warning_gradient_norm)
1337  {
1338  std::cout << "OpenNN Warning: Gradient norm is " << gradient_norm << ".\n";
1339  }
1340 
1341  inverse_Hessian = performance_functional_pointer->calculate_inverse_Hessian();
1342 
1343  // Training algorithm
1344 
1345  training_direction = calculate_training_direction(gradient, inverse_Hessian);
1346 
1347  // Calculate performance training_slope
1348 
1349  training_slope = (gradient/gradient_norm).dot(training_direction);
1350 
1351  // Check for a descent direction
1352 
1353  if(training_slope >= 0.0)
1354  {
1355  if(display)
1356  {
1357  std::cout << "Iteration " << iteration << ": Training slope is greater than zero. Reseting training direction.\n";
1358  }
1359 
1360  // Reset training direction
1361 
1362  training_direction = calculate_gradient_descent_training_direction(gradient);
1363  }
1364 
1365  if(iteration == 0)
1366  {
1367 // initial_training_rate = first_training_rate;
1368  }
1369  else
1370  {
1371 // initial_training_rate = old_training_rate;
1372  }
1373 
1374 // directional_point = calculate_directional_point(performance, training_direction, initial_training_rate);
1375 
1376  training_rate = directional_point[0];
1377 
1378  parameters_increment = training_direction*training_rate;
1379  parameters_increment_norm = parameters_increment.calculate_norm();
1380 
1381  // Elapsed time
1382 
1383  time(&current_time);
1384  elapsed_time = difftime(current_time, beginning_time);
1385 
1386  // Training history multilayer perceptron
1387 
1388  if(reserve_parameters_history)
1389  {
1390  Newton_method_results_pointer->parameters_history[iteration] = parameters;
1391  }
1392 
1393  if(reserve_parameters_norm_history)
1394  {
1395  Newton_method_results_pointer->parameters_norm_history[iteration] = parameters_norm;
1396  }
1397 
1398  // Training history performance functional
1399 
1400  if(reserve_performance_history)
1401  {
1402  Newton_method_results_pointer->performance_history[iteration] = performance;
1403  }
1404 
1405  if(reserve_generalization_performance_history)
1406  {
1407  Newton_method_results_pointer->generalization_performance_history[iteration] = generalization_performance;
1408  }
1409 
1410  if(reserve_gradient_history)
1411  {
1412  Newton_method_results_pointer->gradient_history[iteration] = gradient;
1413  }
1414 
1415  if(reserve_gradient_norm_history)
1416  {
1417  Newton_method_results_pointer->gradient_norm_history[iteration] = gradient_norm;
1418  }
1419 
1420  if(reserve_inverse_Hessian_history)
1421  {
1422  Newton_method_results_pointer->inverse_Hessian_history[iteration] = inverse_Hessian;
1423  }
1424 
1425  // Training history training algorithm
1426 
1427  if(reserve_training_direction_history)
1428  {
1429  Newton_method_results_pointer->training_direction_history[iteration] = training_direction;
1430  }
1431 
1432  if(reserve_training_rate_history)
1433  {
1434  Newton_method_results_pointer->training_rate_history[iteration] = training_rate;
1435  }
1436 
1437  if(reserve_elapsed_time_history)
1438  {
1439  Newton_method_results_pointer->elapsed_time_history[iteration] = elapsed_time;
1440  }
1441 
1442  // Stopping Criteria
1443 
1444  if(parameters_increment_norm <= minimum_parameters_increment_norm)
1445  {
1446  if(display)
1447  {
1448  std::cout << "Iteration " << iteration << ": Minimum parameters increment norm reached.\n"
1449  << "Parameters increment norm: " << parameters_increment_norm << std::endl;
1450  }
1451 
1452  stop_training = true;
1453  }
1454 
1455  else if(performance <= performance_goal)
1456  {
1457  if(display)
1458  {
1459  std::cout << "Iteration " << iteration << ": Performance goal reached.\n";
1460  }
1461 
1462  stop_training = true;
1463  }
1464 
1465  else if(iteration != 0 && performance_increase <= minimum_performance_increase)
1466  {
1467  if(display)
1468  {
1469  std::cout << "Iteration " << iteration << ": Minimum performance increase reached.\n"
1470  << "Performance improvement: " << performance_increase << std::endl;
1471  }
1472 
1473  stop_training = true;
1474  }
1475 
1476  else if(iteration != 0 && generalization_performance_increment < 0.0)
1477  {
1478  if(display)
1479  {
1480  std::cout << "Iteration " << iteration << ": Generalization performance stopped improving.\n";
1481  std::cout << "Generalization performance increment: "<< generalization_performance_increment << std::endl;
1482  }
1483 
1484  stop_training = true;
1485  }
1486 
1487  else if(gradient_norm <= gradient_norm_goal)
1488  {
1489  if(display)
1490  {
1491  std::cout << "Iteration " << iteration << ": Gradient norm goal reached.\n";
1492  }
1493 
1494  stop_training = true;
1495  }
1496 
1497  if(iteration == maximum_iterations_number)
1498  {
1499  if(display)
1500  {
1501  std::cout << "Iteration " << iteration << ": Maximum number of iterations reached.\n";
1502  }
1503 
1504  stop_training = true;
1505  }
1506 
1507  else if(elapsed_time >= maximum_time)
1508  {
1509  if(display)
1510  {
1511  std::cout << "Iteration " << iteration << ": Maximum training time reached.\n";
1512  }
1513 
1514  stop_training = true;
1515  }
1516 
1517  if(iteration != 0 && iteration % save_period == 0)
1518  {
1519  neural_network_pointer->save(neural_network_file_name);
1520  }
1521 
1522  if(stop_training)
1523  {
1524  Newton_method_results_pointer->final_parameters = parameters;
1525  Newton_method_results_pointer->final_parameters_norm = parameters_norm;
1526 
1527  Newton_method_results_pointer->final_performance = performance;
1528  Newton_method_results_pointer->final_generalization_performance = generalization_performance;
1529 
1530  Newton_method_results_pointer->final_gradient = gradient;
1531  Newton_method_results_pointer->final_gradient_norm = gradient_norm;
1532 
1533  Newton_method_results_pointer->final_training_direction = training_direction;
1534  Newton_method_results_pointer->final_training_rate = training_rate;
1535  Newton_method_results_pointer->elapsed_time = elapsed_time;
1536 
1537  if(display)
1538  {
1539  std::cout << "Parameters norm: " << parameters_norm << "\n"
1540  << "Performance: " << performance << "\n"
1541  << "Gradient norm: " << gradient_norm << "\n"
1542  << performance_functional_pointer->write_information()
1543  << "Training rate: " << training_rate << "\n"
1544  << "Elapsed time: " << elapsed_time << std::endl;
1545 
1546  if(generalization_performance != 0)
1547  {
1548  std::cout << "Generalization performance: " << generalization_performance << std::endl;
1549  }
1550  }
1551 
1552  break;
1553  }
1554  else if(display && iteration % display_period == 0)
1555  {
1556  std::cout << "Iteration " << iteration << ";\n"
1557  << "Parameters norm: " << parameters_norm << "\n"
1558  << "Performance: " << performance << "\n"
1559  << "Gradient norm: " << gradient_norm << "\n"
1560  << performance_functional_pointer->write_information()
1561  << "Training rate: " << training_rate << "\n"
1562  << "Elapsed time: " << elapsed_time << std::endl;
1563 
1564  if(generalization_performance != 0)
1565  {
1566  std::cout << "Generalization performance: " << generalization_performance << std::endl;
1567  }
1568  }
1569 
1570  // Set new parameters
1571 
1572  parameters += parameters_increment;
1573 
1574  neural_network_pointer->set_parameters(parameters);
1575 
1576  // Update stuff
1577 
1578  old_performance = performance;
1579  old_generalization_performance = generalization_performance;
1580 
1581  //old_training_rate = training_rate;
1582  }
1583 
1584  return(Newton_method_results_pointer);
1585 */
1586 }
1587 
1588 
1589 // std::string write_training_algorithm_type(void) const method
1590 
1592 {
1593  return("NEWTON_METHOD");
1594 }
1595 
1596 
1597 // Matrix<std::string> to_string_matrix(void) const method
1598 
1599 // the most representative
1600 
1602 {
1603  std::ostringstream buffer;
1604 
1605  Vector<std::string> labels;
1606  Vector<std::string> values;
1607 
1608  // Training rate method
1609 
1610  labels.push_back("Training rate method");
1611 
1612  const std::string training_rate_method = training_rate_algorithm.write_training_rate_method();
1613 
1614  values.push_back(training_rate_method);
1615 
1616  // Training rate tolerance
1617 
1618  labels.push_back("Training rate tolerance");
1619 
1620  buffer.str("");
1622 
1623  values.push_back(buffer.str());
1624 
1625  // Minimum parameters increment norm
1626 
1627  labels.push_back("Minimum parameters increment norm");
1628 
1629  buffer.str("");
1631 
1632  values.push_back(buffer.str());
1633 
1634  // Minimum performance increase
1635 
1636  labels.push_back("Minimum performance increase");
1637 
1638  buffer.str("");
1639  buffer << minimum_performance_increase;
1640 
1641  values.push_back(buffer.str());
1642 
1643  // Performance goal
1644 
1645  labels.push_back("Performance goal");
1646 
1647  buffer.str("");
1648  buffer << performance_goal;
1649 
1650  values.push_back(buffer.str());
1651 
1652  // Gradient norm goal
1653 
1654  labels.push_back("Gradient norm goal");
1655 
1656  buffer.str("");
1657  buffer << gradient_norm_goal;
1658 
1659  values.push_back(buffer.str());
1660 
1661  // Maximum generalization failures
1662 
1663  labels.push_back("Maximum generalization failures");
1664 
1665  buffer.str("");
1667 
1668  values.push_back(buffer.str());
1669 
1670  // Maximum iterations number
1671 
1672  labels.push_back("Maximum iterations number");
1673 
1674  buffer.str("");
1675  buffer << maximum_iterations_number;
1676 
1677  values.push_back(buffer.str());
1678 
1679  // Maximum time
1680 
1681  labels.push_back("Maximum time");
1682 
1683  buffer.str("");
1684  buffer << maximum_time;
1685 
1686  values.push_back(buffer.str());
1687 
1688  // Reserve parameters norm history
1689 
1690  labels.push_back("Reserve parameters norm history");
1691 
1692  buffer.str("");
1694 
1695  values.push_back(buffer.str());
1696 
1697  // Reserve performance history
1698 
1699  labels.push_back("Reserve performance history");
1700 
1701  buffer.str("");
1702  buffer << reserve_performance_history;
1703 
1704  values.push_back(buffer.str());
1705 
1706  // Reserve gradient norm history
1707 
1708  labels.push_back("Reserve gradient norm history");
1709 
1710  buffer.str("");
1712 
1713  values.push_back(buffer.str());
1714 
1715  // Reserve generalization performance history
1716 
1717  labels.push_back("Reserve generalization performance history");
1718 
1719  buffer.str("");
1721 
1722  values.push_back(buffer.str());
1723 
1724  // Reserve training direction norm history
1725 
1726 // labels.push_back("");
1727 
1728 // buffer.str("");
1729 // buffer << reserve_training_direction_norm_history;
1730 
1731  // Reserve training rate history
1732 
1733 // labels.push_back("");
1734 
1735 // buffer.str("");
1736 // buffer << reserve_training_rate_history;
1737 
1738 // values.push_back(buffer.str());
1739 
1740  // Reserve elapsed time history
1741 
1742  labels.push_back("Reserve elapsed time history");
1743 
1744  buffer.str("");
1745  buffer << reserve_elapsed_time_history;
1746 
1747  values.push_back(buffer.str());
1748 
1749  const size_t rows_number = labels.size();
1750  const size_t columns_number = 2;
1751 
1752  Matrix<std::string> string_matrix(rows_number, columns_number);
1753 
1754  string_matrix.set_column(0, labels);
1755  string_matrix.set_column(1, values);
1756 
1757  return(string_matrix);
1758 }
1759 
1760 
1761 // TyXmlElement* to_XML(void) const method
1762 
1777 
1778 tinyxml2::XMLDocument* NewtonMethod::to_XML(void) const
1779 {
1780  std::ostringstream buffer;
1781 
1782  tinyxml2::XMLDocument* document = new tinyxml2::XMLDocument;
1783 
1784  // Training algorithm
1785 
1786  tinyxml2::XMLElement* root_element = document->NewElement("NewtonMethod");
1787 
1788  document->InsertFirstChild(root_element);
1789 
1790  tinyxml2::XMLElement* element = NULL;
1791  tinyxml2::XMLText* text = NULL;
1792 
1793  // Training rate algorithm
1794  {
1795  tinyxml2::XMLElement* element = document->NewElement("TrainingRateAlgorithm");
1796  root_element->LinkEndChild(element);
1797 
1798  const tinyxml2::XMLDocument* training_rate_algorithm_document = training_rate_algorithm.to_XML();
1799 
1800  const tinyxml2::XMLElement* training_rate_algorithm_element = training_rate_algorithm_document->FirstChildElement("TrainingRateAlgorithm");
1801 
1802  DeepClone(element, training_rate_algorithm_element, document, NULL);
1803 
1804  delete training_rate_algorithm_document;
1805  }
1806 
1807  // Warning parameters norm
1808  {
1809  element = document->NewElement("WarningParametersNorm");
1810  root_element->LinkEndChild(element);
1811 
1812  buffer.str("");
1813  buffer << warning_parameters_norm;
1814 
1815  text = document->NewText(buffer.str().c_str());
1816  element->LinkEndChild(text);
1817  }
1818 
1819  // Warning gradient norm
1820  {
1821  element = document->NewElement("WarningGradientNorm");
1822  root_element->LinkEndChild(element);
1823 
1824  buffer.str("");
1825  buffer << warning_gradient_norm;
1826 
1827  text = document->NewText(buffer.str().c_str());
1828  element->LinkEndChild(text);
1829  }
1830 
1831  // Warning training rate
1832  {
1833  element = document->NewElement("WarningTrainingRate");
1834  root_element->LinkEndChild(element);
1835 
1836  buffer.str("");
1837  buffer << warning_training_rate;
1838 
1839  text = document->NewText(buffer.str().c_str());
1840  element->LinkEndChild(text);
1841  }
1842 
1843  // Error parameters norm
1844  {
1845  element = document->NewElement("ErrorParametersNorm");
1846  root_element->LinkEndChild(element);
1847 
1848  buffer.str("");
1849  buffer << error_parameters_norm;
1850 
1851  text = document->NewText(buffer.str().c_str());
1852  element->LinkEndChild(text);
1853  }
1854 
1855  // Error gradient norm
1856  {
1857  element = document->NewElement("ErrorGradientNorm");
1858  root_element->LinkEndChild(element);
1859 
1860  buffer.str("");
1861  buffer << error_gradient_norm;
1862 
1863  text = document->NewText(buffer.str().c_str());
1864  element->LinkEndChild(text);
1865  }
1866 
1867  // Error training rate
1868  {
1869  element = document->NewElement("ErrorTrainingRate");
1870  root_element->LinkEndChild(element);
1871 
1872  buffer.str("");
1873  buffer << error_training_rate;
1874 
1875  text = document->NewText(buffer.str().c_str());
1876  element->LinkEndChild(text);
1877  }
1878 
1879  // Minimum parameters increment norm
1880  {
1881  element = document->NewElement("MinimumParametersIncrementNorm");
1882  root_element->LinkEndChild(element);
1883 
1884  buffer.str("");
1886 
1887  text = document->NewText(buffer.str().c_str());
1888  element->LinkEndChild(text);
1889  }
1890 
1891  // Minimum performance increase
1892  {
1893  element = document->NewElement("MinimumPerformanceIncrease");
1894  root_element->LinkEndChild(element);
1895 
1896  buffer.str("");
1897  buffer << minimum_performance_increase;
1898 
1899  text = document->NewText(buffer.str().c_str());
1900  element->LinkEndChild(text);
1901  }
1902 
1903  // Performance goal
1904  {
1905  element = document->NewElement("PerformanceGoal");
1906  root_element->LinkEndChild(element);
1907 
1908  buffer.str("");
1909  buffer << performance_goal;
1910 
1911  text = document->NewText(buffer.str().c_str());
1912  element->LinkEndChild(text);
1913  }
1914 
1915  // Gradient norm goal
1916  {
1917  element = document->NewElement("GradientNormGoal");
1918  root_element->LinkEndChild(element);
1919 
1920  buffer.str("");
1921  buffer << gradient_norm_goal;
1922 
1923  text = document->NewText(buffer.str().c_str());
1924  element->LinkEndChild(text);
1925  }
1926 
1927  // Maximum generalization performance decreases
1928  {
1929  element = document->NewElement("MaximumGeneralizationPerformanceDecreases");
1930  root_element->LinkEndChild(element);
1931 
1932  buffer.str("");
1934 
1935  text = document->NewText(buffer.str().c_str());
1936  element->LinkEndChild(text);
1937  }
1938 
1939  // Maximum iterations number
1940  {
1941  element = document->NewElement("MaximumIterationsNumber");
1942  root_element->LinkEndChild(element);
1943 
1944  buffer.str("");
1945  buffer << maximum_iterations_number;
1946 
1947  text = document->NewText(buffer.str().c_str());
1948  element->LinkEndChild(text);
1949  }
1950 
1951  // Maximum time
1952  {
1953  element = document->NewElement("MaximumTime");
1954  root_element->LinkEndChild(element);
1955 
1956  buffer.str("");
1957  buffer << maximum_time;
1958 
1959  text = document->NewText(buffer.str().c_str());
1960  element->LinkEndChild(text);
1961  }
1962 
1963  // Reserve parameters history
1964  {
1965  element = document->NewElement("ReserveParametersHistory");
1966  root_element->LinkEndChild(element);
1967 
1968  buffer.str("");
1969  buffer << reserve_parameters_history;
1970 
1971  text = document->NewText(buffer.str().c_str());
1972  element->LinkEndChild(text);
1973  }
1974 
1975  // Reserve parameters norm history
1976  {
1977  element = document->NewElement("ReserveParametersNormHistory");
1978  root_element->LinkEndChild(element);
1979 
1980  buffer.str("");
1982 
1983  text = document->NewText(buffer.str().c_str());
1984  element->LinkEndChild(text);
1985  }
1986 
1987  // Reserve performance history
1988  {
1989  element = document->NewElement("ReservePerformanceHistory");
1990  root_element->LinkEndChild(element);
1991 
1992  buffer.str("");
1993  buffer << reserve_performance_history;
1994 
1995  text = document->NewText(buffer.str().c_str());
1996  element->LinkEndChild(text);
1997  }
1998 
1999  // Reserve gradient history
2000  {
2001  element = document->NewElement("ReserveGradientHistory");
2002  root_element->LinkEndChild(element);
2003 
2004  buffer.str("");
2005  buffer << reserve_gradient_history;
2006 
2007  text = document->NewText(buffer.str().c_str());
2008  element->LinkEndChild(text);
2009  }
2010 
2011  // Reserve gradient norm history
2012  {
2013  element = document->NewElement("ReserveGradientNormHistory");
2014  root_element->LinkEndChild(element);
2015 
2016  buffer.str("");
2018 
2019  text = document->NewText(buffer.str().c_str());
2020  element->LinkEndChild(text);
2021  }
2022 
2023  // Reserve inverse Hessian history
2024  {
2025  element = document->NewElement("ReserveInverseHessianHistory");
2026  root_element->LinkEndChild(element);
2027 
2028  buffer.str("");
2030 
2031  text = document->NewText(buffer.str().c_str());
2032  element->LinkEndChild(text);
2033  }
2034 
2035  // Reserve training direction history
2036  {
2037  element = document->NewElement("ReserveTrainingDirectionHistory");
2038  root_element->LinkEndChild(element);
2039 
2040  buffer.str("");
2042 
2043  text = document->NewText(buffer.str().c_str());
2044  element->LinkEndChild(text);
2045  }
2046 
2047  // Reserve training rate history
2048  {
2049  element = document->NewElement("ReserveTrainingRateHistory");
2050  root_element->LinkEndChild(element);
2051 
2052  buffer.str("");
2054 
2055  text = document->NewText(buffer.str().c_str());
2056  element->LinkEndChild(text);
2057  }
2058 
2059  // Reserve elapsed time history
2060  {
2061  element = document->NewElement("ReserveElapsedTimeHistory");
2062  root_element->LinkEndChild(element);
2063 
2064  buffer.str("");
2065  buffer << reserve_elapsed_time_history;
2066 
2067  text = document->NewText(buffer.str().c_str());
2068  element->LinkEndChild(text);
2069  }
2070 
2071  // Reserve generalization performance history
2072  {
2073  element = document->NewElement("ReserveGeneralizationPerformanceHistory");
2074  root_element->LinkEndChild(element);
2075 
2076  buffer.str("");
2078 
2079  text = document->NewText(buffer.str().c_str());
2080  element->LinkEndChild(text);
2081  }
2082 
2083  // Display period
2084  {
2085  element = document->NewElement("DisplayPeriod");
2086  root_element->LinkEndChild(element);
2087 
2088  buffer.str("");
2089  buffer << display_period;
2090 
2091  text = document->NewText(buffer.str().c_str());
2092  element->LinkEndChild(text);
2093  }
2094 
2095  // Save period
2096  {
2097  element = document->NewElement("SavePeriod");
2098  root_element->LinkEndChild(element);
2099 
2100  buffer.str("");
2101  buffer << save_period;
2102 
2103  text = document->NewText(buffer.str().c_str());
2104  element->LinkEndChild(text);
2105  }
2106 
2107  // Neural network file name
2108  {
2109  element = document->NewElement("NeuralNetworkFileName");
2110  root_element->LinkEndChild(element);
2111 
2112  text = document->NewText(neural_network_file_name.c_str());
2113  element->LinkEndChild(text);
2114  }
2115 
2116  // Display
2117  {
2118  element = document->NewElement("Display");
2119  root_element->LinkEndChild(element);
2120 
2121  buffer.str("");
2122  buffer << display;
2123 
2124  text = document->NewText(buffer.str().c_str());
2125  element->LinkEndChild(text);
2126  }
2127 
2128  return(document);
2129 }
2130 
2131 
2132 // void from_XML(const tinyxml2::XMLDocument&) method
2133 
2134 void NewtonMethod::from_XML(const tinyxml2::XMLDocument& document)
2135 {
2136  const tinyxml2::XMLElement* root_element = document.FirstChildElement("NewtonMethod");
2137 
2138  if(!root_element)
2139  {
2140  std::ostringstream buffer;
2141 
2142  buffer << "OpenNN Exception: NewtonMethod class.\n"
2143  << "void from_XML(const tinyxml2::XMLDocument&) method.\n"
2144  << "Newton method element is NULL.\n";
2145 
2146  throw std::logic_error(buffer.str());
2147  }
2148 
2149  // Training rate algorithm
2150  {
2151  const tinyxml2::XMLElement* training_rate_algorithm_element = root_element->FirstChildElement("TrainingRateAlgorithm");
2152 
2153  if(training_rate_algorithm_element)
2154  {
2155  tinyxml2::XMLDocument training_rate_algorithm_document;
2156 
2157  tinyxml2::XMLElement* element_clone = training_rate_algorithm_document.NewElement("TrainingRateAlgorithm");
2158  training_rate_algorithm_document.InsertFirstChild(element_clone);
2159 
2160  DeepClone(element_clone, training_rate_algorithm_element, &training_rate_algorithm_document, NULL);
2161 
2162  training_rate_algorithm.from_XML(training_rate_algorithm_document);
2163  }
2164  }
2165 
2166  // Warning parameters norm
2167  {
2168  const tinyxml2::XMLElement* element = root_element->FirstChildElement("WarningParametersNorm");
2169 
2170  if(element)
2171  {
2172  const double new_warning_parameters_norm = atof(element->GetText());
2173 
2174  try
2175  {
2176  set_warning_parameters_norm(new_warning_parameters_norm);
2177  }
2178  catch(const std::logic_error& e)
2179  {
2180  std::cout << e.what() << std::endl;
2181  }
2182  }
2183  }
2184 
2185  // Warning gradient norm
2186  {
2187  const tinyxml2::XMLElement* element = root_element->FirstChildElement("WarningGradientNorm");
2188 
2189  if(element)
2190  {
2191  const double new_warning_gradient_norm = atof(element->GetText());
2192 
2193  try
2194  {
2195  set_warning_gradient_norm(new_warning_gradient_norm);
2196  }
2197  catch(const std::logic_error& e)
2198  {
2199  std::cout << e.what() << std::endl;
2200  }
2201  }
2202  }
2203 
2204  // Warning training rate
2205  {
2206  const tinyxml2::XMLElement* element = root_element->FirstChildElement("WarningTrainingRate");
2207 
2208  if(element)
2209  {
2210  const double new_warning_training_rate = atof(element->GetText());
2211 
2212  try
2213  {
2214  set_warning_training_rate(new_warning_training_rate);
2215  }
2216  catch(const std::logic_error& e)
2217  {
2218  std::cout << e.what() << std::endl;
2219  }
2220  }
2221  }
2222 
2223  // Error parameters norm
2224  {
2225  const tinyxml2::XMLElement* element = root_element->FirstChildElement("ErrorParametersNorm");
2226 
2227  if(element)
2228  {
2229  const double new_error_parameters_norm = atof(element->GetText());
2230 
2231  try
2232  {
2233  set_error_parameters_norm(new_error_parameters_norm);
2234  }
2235  catch(const std::logic_error& e)
2236  {
2237  std::cout << e.what() << std::endl;
2238  }
2239  }
2240  }
2241 
2242  // Error gradient norm
2243  {
2244  const tinyxml2::XMLElement* element = root_element->FirstChildElement("ErrorGradientNorm");
2245 
2246  if(element)
2247  {
2248  const double new_error_gradient_norm = atof(element->GetText());
2249 
2250  try
2251  {
2252  set_error_gradient_norm(new_error_gradient_norm);
2253  }
2254  catch(const std::logic_error& e)
2255  {
2256  std::cout << e.what() << std::endl;
2257  }
2258  }
2259  }
2260 
2261  // Error training rate
2262  {
2263  const tinyxml2::XMLElement* element = root_element->FirstChildElement("ErrorTrainingRate");
2264 
2265  if(element)
2266  {
2267  const double new_error_training_rate = atof(element->GetText());
2268 
2269  try
2270  {
2271  set_error_training_rate(new_error_training_rate);
2272  }
2273  catch(const std::logic_error& e)
2274  {
2275  std::cout << e.what() << std::endl;
2276  }
2277  }
2278  }
2279 
2280  // Minimum parameters increment norm
2281  {
2282  const tinyxml2::XMLElement* element = root_element->FirstChildElement("MinimumParametersIncrementNorm");
2283 
2284  if(element)
2285  {
2286  const double new_minimum_parameters_increment_norm = atof(element->GetText());
2287 
2288  try
2289  {
2290  set_minimum_parameters_increment_norm(new_minimum_parameters_increment_norm);
2291  }
2292  catch(const std::logic_error& e)
2293  {
2294  std::cout << e.what() << std::endl;
2295  }
2296  }
2297  }
2298 
2299  // Minimum performance increase
2300  {
2301  const tinyxml2::XMLElement* element = root_element->FirstChildElement("MinimumPerformanceIncrease");
2302 
2303  if(element)
2304  {
2305  const double new_minimum_performance_increase = atof(element->GetText());
2306 
2307  try
2308  {
2309  set_minimum_performance_increase(new_minimum_performance_increase);
2310  }
2311  catch(const std::logic_error& e)
2312  {
2313  std::cout << e.what() << std::endl;
2314  }
2315  }
2316  }
2317 
2318  // Performance goal
2319  {
2320  const tinyxml2::XMLElement* element = root_element->FirstChildElement("PerformanceGoal");
2321 
2322  if(element)
2323  {
2324  const double new_performance_goal = atof(element->GetText());
2325 
2326  try
2327  {
2328  set_performance_goal(new_performance_goal);
2329  }
2330  catch(const std::logic_error& e)
2331  {
2332  std::cout << e.what() << std::endl;
2333  }
2334  }
2335  }
2336 
2337  // Gradient norm goal
2338  {
2339  const tinyxml2::XMLElement* element = root_element->FirstChildElement("GradientNormGoal");
2340 
2341  if(element)
2342  {
2343  const double new_gradient_norm_goal = atof(element->GetText());
2344 
2345  try
2346  {
2347  set_gradient_norm_goal(new_gradient_norm_goal);
2348  }
2349  catch(const std::logic_error& e)
2350  {
2351  std::cout << e.what() << std::endl;
2352  }
2353  }
2354  }
2355 
2356  // Maximum generalization performance decreases
2357  {
2358  const tinyxml2::XMLElement* element = root_element->FirstChildElement("MaximumGeneralizationPerformanceDecreases");
2359 
2360  if(element)
2361  {
2362  const size_t new_maximum_generalization_performance_decreases = atoi(element->GetText());
2363 
2364  try
2365  {
2366  set_maximum_generalization_performance_decreases(new_maximum_generalization_performance_decreases);
2367  }
2368  catch(const std::logic_error& e)
2369  {
2370  std::cout << e.what() << std::endl;
2371  }
2372  }
2373  }
2374 
2375  // Maximum iterations number
2376  {
2377  const tinyxml2::XMLElement* element = root_element->FirstChildElement("MaximumIterationsNumber");
2378 
2379  if(element)
2380  {
2381  const size_t new_maximum_iterations_number = atoi(element->GetText());
2382 
2383  try
2384  {
2385  set_maximum_iterations_number(new_maximum_iterations_number);
2386  }
2387  catch(const std::logic_error& e)
2388  {
2389  std::cout << e.what() << std::endl;
2390  }
2391  }
2392  }
2393 
2394  // Maximum time
2395  {
2396  const tinyxml2::XMLElement* element = root_element->FirstChildElement("MaximumTime");
2397 
2398  if(element)
2399  {
2400  const double new_maximum_time = atof(element->GetText());
2401 
2402  try
2403  {
2404  set_maximum_time(new_maximum_time);
2405  }
2406  catch(const std::logic_error& e)
2407  {
2408  std::cout << e.what() << std::endl;
2409  }
2410  }
2411  }
2412 
2413  // Reserve parameters history
2414  {
2415  const tinyxml2::XMLElement* element = root_element->FirstChildElement("ReserveParametersHistory");
2416 
2417  if(element)
2418  {
2419  const std::string new_reserve_parameters_history = element->GetText();
2420 
2421  try
2422  {
2423  set_reserve_parameters_history(new_reserve_parameters_history != "0");
2424  }
2425  catch(const std::logic_error& e)
2426  {
2427  std::cout << e.what() << std::endl;
2428  }
2429  }
2430  }
2431 
2432  // Reserve parameters norm history
2433  {
2434  const tinyxml2::XMLElement* element = root_element->FirstChildElement("ReserveParametersNormHistory");
2435 
2436  if(element)
2437  {
2438  const std::string new_reserve_parameters_norm_history = element->GetText();
2439 
2440  try
2441  {
2442  set_reserve_parameters_norm_history(new_reserve_parameters_norm_history != "0");
2443  }
2444  catch(const std::logic_error& e)
2445  {
2446  std::cout << e.what() << std::endl;
2447  }
2448  }
2449  }
2450 
2451  // Reserve performance history
2452  {
2453  const tinyxml2::XMLElement* element = root_element->FirstChildElement("ReservePerformanceHistory");
2454 
2455  if(element)
2456  {
2457  const std::string new_reserve_performance_history = element->GetText();
2458 
2459  try
2460  {
2461  set_reserve_performance_history(new_reserve_performance_history != "0");
2462  }
2463  catch(const std::logic_error& e)
2464  {
2465  std::cout << e.what() << std::endl;
2466  }
2467  }
2468  }
2469 
2470  // Reserve gradient history
2471  {
2472  const tinyxml2::XMLElement* element = root_element->FirstChildElement("ReserveGradientHistory");
2473 
2474  if(element)
2475  {
2476  const std::string new_reserve_gradient_history = element->GetText();
2477 
2478  try
2479  {
2480  set_reserve_gradient_history(new_reserve_gradient_history != "0");
2481  }
2482  catch(const std::logic_error& e)
2483  {
2484  std::cout << e.what() << std::endl;
2485  }
2486  }
2487  }
2488 
2489  // Reserve gradient norm history
2490  {
2491  const tinyxml2::XMLElement* reserve_gradient_norm_history_element = root_element->FirstChildElement("ReserveGradientNormHistory");
2492 
2493  if(reserve_gradient_norm_history_element)
2494  {
2495  const std::string new_reserve_gradient_norm_history = reserve_gradient_norm_history_element->GetText();
2496 
2497  try
2498  {
2499  set_reserve_gradient_norm_history(new_reserve_gradient_norm_history != "0");
2500  }
2501  catch(const std::logic_error& e)
2502  {
2503  std::cout << e.what() << std::endl;
2504  }
2505  }
2506  }
2507 
2508  // Reserve training direction history
2509  {
2510  const tinyxml2::XMLElement* reserve_training_direction_history_element = root_element->FirstChildElement("ReserveTrainingDirectionHistory");
2511 
2512  if(reserve_training_direction_history_element)
2513  {
2514  const std::string new_reserve_training_direction_history = reserve_training_direction_history_element->GetText();
2515 
2516  try
2517  {
2518  set_reserve_training_direction_history(new_reserve_training_direction_history != "0");
2519  }
2520  catch(const std::logic_error& e)
2521  {
2522  std::cout << e.what() << std::endl;
2523  }
2524  }
2525  }
2526 
2527  // Reserve training rate history
2528  {
2529  const tinyxml2::XMLElement* reserve_training_rate_history_element = root_element->FirstChildElement("ReserveTrainingRateHistory");
2530 
2531  if(reserve_training_rate_history_element)
2532  {
2533  const std::string new_reserve_training_rate_history = reserve_training_rate_history_element->GetText();
2534 
2535  try
2536  {
2537  set_reserve_training_rate_history(new_reserve_training_rate_history != "0");
2538  }
2539  catch(const std::logic_error& e)
2540  {
2541  std::cout << e.what() << std::endl;
2542  }
2543  }
2544  }
2545 
2546  // Reserve elapsed time history
2547  {
2548  const tinyxml2::XMLElement* element = root_element->FirstChildElement("ReserveElapsedTimeHistory");
2549 
2550  if(element)
2551  {
2552  const std::string new_reserve_elapsed_time_history = element->GetText();
2553 
2554  try
2555  {
2556  set_reserve_elapsed_time_history(new_reserve_elapsed_time_history != "0");
2557  }
2558  catch(const std::logic_error& e)
2559  {
2560  std::cout << e.what() << std::endl;
2561  }
2562  }
2563  }
2564 
2565  // Reserve generalization performance history
2566  {
2567  const tinyxml2::XMLElement* element = root_element->FirstChildElement("ReserveGeneralizationPerformanceHistory");
2568 
2569  if(element)
2570  {
2571  const std::string new_reserve_generalization_performance_history = element->GetText();
2572 
2573  try
2574  {
2575  set_reserve_generalization_performance_history(new_reserve_generalization_performance_history != "0");
2576  }
2577  catch(const std::logic_error& e)
2578  {
2579  std::cout << e.what() << std::endl;
2580  }
2581  }
2582  }
2583 
2584  // Display period
2585  {
2586  const tinyxml2::XMLElement* element = root_element->FirstChildElement("DisplayPeriod");
2587 
2588  if(element)
2589  {
2590  const size_t new_display_period = atoi(element->GetText());
2591 
2592  try
2593  {
2594  set_display_period(new_display_period);
2595  }
2596  catch(const std::logic_error& e)
2597  {
2598  std::cout << e.what() << std::endl;
2599  }
2600  }
2601  }
2602 
2603  // Save period
2604  {
2605  const tinyxml2::XMLElement* element = root_element->FirstChildElement("SavePeriod");
2606 
2607  if(element)
2608  {
2609  const size_t new_save_period = atoi(element->GetText());
2610 
2611  try
2612  {
2613  set_save_period(new_save_period);
2614  }
2615  catch(const std::logic_error& e)
2616  {
2617  std::cout << e.what() << std::endl;
2618  }
2619  }
2620  }
2621 
2622  // Neural network file name
2623  {
2624  const tinyxml2::XMLElement* element = root_element->FirstChildElement("NeuralNetworkFileName");
2625 
2626  if(element)
2627  {
2628  const std::string new_neural_network_file_name = element->GetText();
2629 
2630  try
2631  {
2632  set_neural_network_file_name(new_neural_network_file_name);
2633  }
2634  catch(const std::logic_error& e)
2635  {
2636  std::cout << e.what() << std::endl;
2637  }
2638  }
2639  }
2640 
2641  // Display
2642  {
2643  const tinyxml2::XMLElement* element = root_element->FirstChildElement("Display");
2644 
2645  if(element)
2646  {
2647  const std::string new_display = element->GetText();
2648 
2649  try
2650  {
2651  set_display(new_display != "0");
2652  }
2653  catch(const std::logic_error& e)
2654  {
2655  std::cout << e.what() << std::endl;
2656  }
2657  }
2658  }
2659 }
2660 
2661 
2662 // void set_reserve_all_training_history(bool) method
2663 
2664 void NewtonMethod::set_reserve_all_training_history(const bool& new_reserve_all_training_history)
2665 {
2666  reserve_parameters_history = new_reserve_all_training_history;
2667  reserve_parameters_norm_history = new_reserve_all_training_history;
2668 
2669  reserve_performance_history = new_reserve_all_training_history;
2670  reserve_gradient_history = new_reserve_all_training_history;
2671  reserve_gradient_norm_history = new_reserve_all_training_history;
2672  reserve_inverse_Hessian_history = new_reserve_all_training_history;
2673 
2674  reserve_training_direction_history = new_reserve_all_training_history;
2675  reserve_training_rate_history = new_reserve_all_training_history;
2676  reserve_elapsed_time_history = new_reserve_all_training_history;
2677 
2678  reserve_generalization_performance_history = new_reserve_all_training_history;
2679 }
2680 
2681 }
2682 
2683 
2684 // OpenNN: Open Neural Networks Library.
2685 // Copyright (c) 2005-2015 Roberto Lopez.
2686 //
2687 // This library is free software; you can redistribute it and/or
2688 // modify it under the terms of the GNU Lesser General Public
2689 // License as published by the Free Software Foundation; either
2690 // version 2.1 of the License, or any later version.
2691 //
2692 // This library is distributed in the hope that it will be useful,
2693 // but WITHOUT ANY WARRANTY; without even the implied warranty of
2694 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2695 // Lesser General Public License for more details.
2696 
2697 // You should have received a copy of the GNU Lesser General Public
2698 // License along with this library; if not, write to the Free Software
2699 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2700 
void set_error_gradient_norm(const double &)
bool reserve_parameters_history
True if the parameters history matrix is to be reserved, false otherwise.
void set_reserve_parameters_norm_history(const bool &)
const bool & get_reserve_inverse_Hessian_history(void) const
Returns true if the inverse Hessian history vector of matrices is to be reserved, and false otherwise...
size_t count_parameters_number(void) const
NewtonMethodResults * perform_training(void)
void set_minimum_parameters_increment_norm(const double &)
tinyxml2::XMLDocument * to_XML(void) const
const bool & get_reserve_elapsed_time_history(void) const
Returns true if the elapsed time history vector is to be reserved, and false otherwise.
void set_error_parameters_norm(const double &)
double warning_parameters_norm
Value for the parameters norm at which a warning message is written to the screen.
void set_reserve_generalization_performance_history(const bool &)
void set_error_training_rate(const double &)
std::string to_string(void) const
Returns a string representation of the current Newton method results structure.
const bool & get_reserve_gradient_history(void) const
Returns true if the gradient history vector of vectors is to be reserved, and false otherwise...
size_t maximum_generalization_performance_decreases
const bool & get_reserve_training_rate_history(void) const
Returns true if the training rate history vector is to be reserved, and false otherwise.
const double & get_error_training_rate(void) const
const double & get_error_parameters_norm(void) const
size_t maximum_iterations_number
Maximum number of iterations to perform_training. It is used as a stopping criterion.
void set_performance_functional_pointer(PerformanceFunctional *)
void set_display_period(const size_t &)
void set_maximum_iterations_number(const size_t &)
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_training_direction_history(const bool &)
bool display
Display messages to screen.
void set_reserve_inverse_Hessian_history(const bool &)
NeuralNetwork * get_neural_network_pointer(void) const
Returns a pointer to the neural network associated to the performance functional. ...
Matrix< std::string > to_string_matrix(void) const
const double & get_gradient_norm_goal(void) const
void set_warning_gradient_norm(const double &)
void set_reserve_elapsed_time_history(const bool &)
const bool & get_reserve_performance_history(void) const
Returns true if the performance history vector is to be reserved, and false otherwise.
Vector< Vector< double > > gradient_history
History of the performance function gradient over the training iterations.
Vector< double > calculate_gradient_descent_training_direction(const Vector< double > &) const
void set_reserve_performance_history(const bool &)
void from_XML(const tinyxml2::XMLDocument &)
std::string write_training_rate_method(void) const
Returns a string with the name of the training rate method to be used.
const bool & get_reserve_generalization_performance_history(void) const
Returns true if the Generalization performance history vector is to be reserved, and false otherwise...
tinyxml2::XMLDocument * to_XML(void) const
bool reserve_performance_history
True if the performance history vector is to be reserved, false otherwise.
void set_save_period(const size_t &)
const double & get_warning_gradient_norm(void) const
TrainingRateAlgorithm training_rate_algorithm
const double & get_performance_goal(void) const
Vector< Vector< double > > training_direction_history
History of the random search training direction over the training iterations.
Vector< double > performance_history
History of the performance function performance over the training iterations.
size_t save_period
Number of iterations between the training saving progress.
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...
Vector< double > elapsed_time_history
History of the elapsed time over the training iterations.
void set_reserve_gradient_norm_history(const bool &)
void set_maximum_time(const double &)
const double & get_error_gradient_norm(void) const
void set_performance_functional_pointer(PerformanceFunctional *)
const bool & get_reserve_parameters_norm_history(void) const
Returns true if the parameters norm history vector is to be reserved, and false otherwise.
NewtonMethod * Newton_method_pointer
Pointer to the Newton method object for which the training results are to be stored.
Definition: newton_method.h:98
bool reserve_elapsed_time_history
True if the elapsed time history vector is to be reserved, false otherwise.
std::string neural_network_file_name
Path where the neural network is saved.
std::string write_training_algorithm_type(void) const
This method writes a string with the type of training algoritm.
void set_neural_network_file_name(const std::string &)
double performance_goal
Goal value for the performance. It is used as a stopping criterion.
double error_training_rate
Training rate at wich the line minimization algorithm is assumed to be unable to bracket a minimum...
void set_default(void)
Sets the members of the training algorithm object to their default values.
Vector< double > gradient_norm_history
History of the gradient norm over the training iterations.
double error_parameters_norm
Value for the parameters norm at which the training process is assumed to fail.
bool reserve_inverse_Hessian_history
True if the inverse Hessian history vector of matrices is to be reserved, false otherwise.
void set_column(const size_t &, const Vector< T > &)
Definition: matrix.h:1774
Vector< double > calculate_training_direction(const Vector< double > &, const Matrix< double > &) const
Vector< T > calculate_normalized(void) const
Returns this vector divided by its norm.
Definition: vector.h:2530
void set_reserve_parameters_history(const bool &)
bool reserve_gradient_norm_history
True if the gradient norm history vector is to be reserved, false otherwise.
const double & get_maximum_time(void) const
Returns the maximum training time.
void set_reserve_gradient_history(const bool &)
void set_performance_goal(const double &)
void from_XML(const tinyxml2::XMLDocument &)
bool reserve_training_direction_history
True if the training direction history matrix is to be reserved, false otherwise. ...
Vector< double > training_rate_history
History of the random search training rate over the training iterations.
bool reserve_training_rate_history
True if the training rate history vector is to be reserved, false otherwise.
TrainingRateAlgorithm * get_training_rate_algorithm_pointer(void)
Returns a pointer to the training rate algorithm object inside the Newton method object.
void set_reserve_all_training_history(const bool &)
Makes the training history of all variables to be reseved or not in memory.
const double & get_training_rate_tolerance(void) const
Returns the tolerance value in line minimization.
const double & get_warning_training_rate(void) const
void set_reserve_training_rate_history(const bool &)
const bool & get_reserve_parameters_history(void) const
Returns true if the parameters history matrix is to be reserved, and false otherwise.
bool reserve_gradient_history
True if the gradient history matrix is to be reserved, false otherwise.
const size_t & get_maximum_generalization_performance_decreases(void) const
Returns the maximum number of generalization failures during the training process.
Vector< double > dot(const Vector< double > &) const
Definition: matrix.h:5772
void set_gradient_norm_goal(const double &)
double warning_gradient_norm
Value for the gradient norm at which a warning message is written to the screen.
Vector< Vector< double > > parameters_history
History of the neural network parameters over the training iterations.
const size_t & get_maximum_iterations_number(void) const
Returns the maximum number of iterations for training.
void set_warning_training_rate(const double &)
virtual ~NewtonMethod(void)
Destructor.
void set_minimum_performance_increase(const double &)
void set_maximum_generalization_performance_decreases(const size_t &)
const TrainingRateAlgorithm & get_training_rate_algorithm(void) const
Returns a constant reference to the training rate algorithm object inside the Newton method object...
Matrix< std::string > write_final_results(const size_t &precision=3) const
Returns a default (empty) string matrix with the final results from training.
void set_warning_parameters_norm(const double &)
double error_gradient_norm
Value for the gradient norm at which the training process is assumed to fail.
const bool & get_reserve_training_direction_history(void) const
Returns true if the training direction history matrix is to be reserved, and false otherwise...
Vector< double > parameters_norm_history
History of the parameters norm over the training iterations.
double gradient_norm_goal
Goal value for the norm of the objective function gradient. It is used as a stopping criterion...
bool reserve_generalization_performance_history
True if the Generalization performance history vector is to be reserved, false otherwise.
PerformanceFunctional * performance_functional_pointer
Pointer to a performance functional for a multilayer perceptron object.
Vector< Matrix< double > > inverse_Hessian_history
History of the inverse Hessian over the training iterations.
Vector< double > generalization_performance_history
History of the generalization performance over the training iterations.
size_t display_period
Number of iterations between the training showing progress.
double minimum_parameters_increment_norm
Norm of the parameters increment vector at which training stops.
double maximum_time
Maximum training time. It is used as a stopping criterion.
double warning_training_rate
Training rate value at wich a warning message is written to the screen.
const double & get_warning_parameters_norm(void) const
double minimum_performance_increase
Minimum performance improvement between two successive iterations. It is used as a stopping criterion...
const double & get_minimum_performance_increase(void) const
Returns the minimum performance improvement during training.
bool reserve_parameters_norm_history
True if the parameters norm history vector is to be reserved, false otherwise.