levenberg_marquardt_algorithm.h
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// 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 H E A D E R
5//
6// Artificial Intelligence Techniques SL
7// artelnics@artelnics.com
8
9#ifndef LEVENBERGMARQUARDTALGORITHM_H
10#define LEVENBERGMARQUARDTALGORITHM_H
11
12// System includes
13
14#include <string>
15#include <sstream>
16#include <iostream>
17#include <fstream>
18#include <algorithm>
19#include <functional>
20#include <limits>
21#include <math.h>
22#include <time.h>
23
24// OpenNN includes
25
26#include "config.h"
27#include "tensor_utilities.h"
28#include "optimization_algorithm.h"
29
30// Eigen includes
31
32#include "../eigen/Eigen/Dense"
33
34namespace OpenNN
35{
36
37struct LevenbergMarquardtAlgorithmData;
38
40
45
46
48{
49
50public:
51
52 // Constructors
53
55
57
58 // Destructor
59
61
62 // Get methods
63
64 // Stopping criteria
65
66 const type& get_minimum_loss_decrease() const;
67 const type& get_loss_goal() const;
68
69 const Index& get_maximum_selection_failures() const;
70
71 const Index& get_maximum_epochs_number() const;
72 const type& get_maximum_time() const;
73
74 // Utilities
75
76 const type& get_damping_parameter() const;
77
78 const type& get_damping_parameter_factor() const;
79
80 const type& get_minimum_damping_parameter() const;
81 const type& get_maximum_damping_parameter() const;
82
83 // Set methods
84
85 void set_default();
86
87 void set_damping_parameter(const type&);
88
89 void set_damping_parameter_factor(const type&);
90
91 void set_minimum_damping_parameter(const type&);
92 void set_maximum_damping_parameter(const type&);
93
94 // Stopping criteria
95
96 void set_minimum_loss_decrease(const type&);
97 void set_loss_goal(const type&);
98
99 void set_maximum_selection_failures(const Index&);
100
101 void set_maximum_epochs_number(const Index&);
102 void set_maximum_time(const type&);
103
104 // Training methods
105
106 void check() const;
107
109
111 const DataSetBatch&,
115
117
118 // Serialization methods
119
120 Tensor<string, 2> to_string_matrix() const;
121
122 void from_XML(const tinyxml2::XMLDocument&);
123
124 void write_XML(tinyxml2::XMLPrinter&) const;
125
126private:
127
128 // MEMBERS
129
131
133
135
137
139
141
143
145
146 // Stopping criteria
147
149
151
153
155
158
160
162
164
166
168};
169
170
172{
174
176 {
177 }
178
179 explicit LevenbergMarquardtAlgorithmData(LevenbergMarquardtAlgorithm* new_Levenberg_Marquardt_method_pointer)
180 {
181 set(new_Levenberg_Marquardt_method_pointer);
182 }
183
184 virtual ~LevenbergMarquardtAlgorithmData() {}
185
186 void set(LevenbergMarquardtAlgorithm* new_Levenberg_Marquardt_method_pointer)
187 {
188 Levenberg_Marquardt_algorithm = new_Levenberg_Marquardt_method_pointer;
189
190 LossIndex* loss_index_pointer = Levenberg_Marquardt_algorithm->get_loss_index_pointer();
191
192 NeuralNetwork* neural_network_pointer = loss_index_pointer->get_neural_network_pointer();
193
194 const Index parameters_number = neural_network_pointer->get_parameters_number();
195
196 // Neural network data
197
198 old_parameters.resize(parameters_number);
199
200 parameters_difference.resize(parameters_number);
201
202 potential_parameters.resize(parameters_number);
203 parameters_increment.resize(parameters_number);
204 }
205
206 LevenbergMarquardtAlgorithm* Levenberg_Marquardt_algorithm = nullptr;
207
208 // Neural network data
209
210 Tensor<type, 1> old_parameters;
211 Tensor<type, 1> parameters_difference;
212
213 Tensor<type, 1> parameters_increment;
214
215 // Loss index data
216
217 type old_loss = type(0);
218
219 // Optimization algorithm data
220
221 Index epoch = 0;
222};
223
224
225}
226
227#endif
228
229
230// OpenNN: Open Neural Networks Library.
231// Copyright(C) 2005-2021 Artificial Intelligence Techniques, SL.
232//
233// This library is free software; you can redistribute it and/or
234// modify it under the terms of the GNU Lesser General Public
235// License as published by the Free Software Foundation; either
236// version 2.1 of the License, or any later version.
237//
238// This library is distributed in the hope that it will be useful,
239// but WITHOUT ANY WARRANTY; without even the implied warranty of
240// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
241// Lesser General Public License for more details.
242
243// You should have received a copy of the GNU Lesser General Public
244// License along with this library; if not, write to the Free Software
245// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Levenberg-Marquardt Algorithm will always compute the approximate Hessian matrix, which has dimension...
const type & get_minimum_damping_parameter() const
Returns the minimum damping parameter allowed in the algorithm.
const type & get_maximum_time() const
Returns the maximum training time.
void from_XML(const tinyxml2::XMLDocument &)
const Index & get_maximum_epochs_number() const
Returns the maximum number of iterations for training.
Tensor< string, 2 > to_string_matrix() const
Writes as matrix of strings the most representative atributes.
type minimum_loss_decrease
Minimum loss improvement between two successive iterations. It is used as a stopping criterion.
void update_parameters(const DataSetBatch &, NeuralNetworkForwardPropagation &, LossIndexBackPropagationLM &, LevenbergMarquardtAlgorithmData &)
LevenbergMarquardtAlgorithm::update_parameters.
string write_optimization_algorithm_type() const
Writes the optimization algorithm type.
type damping_parameter
Initial Levenberg-Marquardt parameter.
type maximum_time
Maximum training time. It is used as a stopping criterion.
type damping_parameter_factor
Damping parameter increase/decrease factor.
const type & get_damping_parameter_factor() const
Returns the damping parameter factor(beta in the User's Guide) for the hessian approximation.
type minimum_damping_parameter
Minimum Levenberg-Marquardt parameter.
type training_loss_goal
Goal value for the loss. It is used as a stopping criterion.
const type & get_maximum_damping_parameter() const
Returns the maximum damping parameter allowed in the algorithm.
Index maximum_epochs_number
Maximum number of epoch to perform_training. It is used as a stopping criterion.
void write_XML(tinyxml2::XMLPrinter &) const
const type & get_damping_parameter() const
Returns the damping parameter for the hessian approximation.
const Index & get_maximum_selection_failures() const
Returns the maximum number of selection failures during the training process.
type maximum_damping_parameter
Maximum Levenberg-Marquardt parameter.
const type & get_minimum_loss_decrease() const
Returns the minimum loss improvement during training.
This abstract class represents the concept of loss index composed of an error term and a regularizati...
Definition: loss_index.h:48
NeuralNetwork * get_neural_network_pointer() const
Returns a pointer to the neural network object associated to the error term.
Definition: loss_index.h:70
Index get_parameters_number() const
A loss index composed of several terms, this structure represent the First Order for this function.
Definition: loss_index.h:383
This structure contains the optimization algorithm results.