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