OpenNN  2.2
Open Neural Networks Library
training_strategy.h
1 /****************************************************************************************************************/
2 /* */
3 /* OpenNN: Open Neural Networks Library */
4 /* www.artelnics.com/opennn */
5 /* */
6 /* T R A I N I N G S T R A T E G Y C L A S S H E A D E R */
7 /* */
8 /* Roberto Lopez */
9 /* Artelnics - Making intelligent use of data */
11 /* */
12 /****************************************************************************************************************/
13 
14 #ifndef __TRAININGSTRATEGY_H__
15 #define __TRAININGSTRATEGY_H__
16 
17 // System includes
18 
19 #include <iostream>
20 #include <fstream>
21 #include <algorithm>
22 #include <functional>
23 #include <limits>
24 #include <cmath>
25 #include <ctime>
26 
27 // OpenNN includes
28 
29 #include "performance_functional.h"
30 
31 #include "training_algorithm.h"
32 
33 #include "random_search.h"
34 #include "evolutionary_algorithm.h"
35 
36 #include "gradient_descent.h"
37 #include "conjugate_gradient.h"
38 #include "quasi_newton_method.h"
39 #include "levenberg_marquardt_algorithm.h"
40 
41 #include "newton_method.h"
42 
43 // TinyXml includes
44 
45 #include "../tinyxml2/tinyxml2.h"
46 
47 namespace OpenNN
48 {
49 
57 
59 {
60 
61 public:
62 
63  // DEFAULT CONSTRUCTOR
64 
65  explicit TrainingStrategy(void);
66 
67  // GENERAL CONSTRUCTOR
68 
70 
71  // XML CONSTRUCTOR
72 
73  explicit TrainingStrategy(const tinyxml2::XMLDocument&);
74 
75  // FILE CONSTRUCTOR
76 
77  explicit TrainingStrategy(const std::string&);
78 
79  // DESTRUCTOR
80 
81  virtual ~TrainingStrategy(void);
82 
83  // ENUMERATIONS
84 
86 
88  {
89  NO_INITIALIZATION,
90  RANDOM_SEARCH,
91  EVOLUTIONARY_ALGORITHM,
92  USER_INITIALIZATION
93  };
94 
96 
97  enum MainType
98  {
99  NO_MAIN,
100  GRADIENT_DESCENT,
101  CONJUGATE_GRADIENT,
102  QUASI_NEWTON_METHOD,
103  LEVENBERG_MARQUARDT_ALGORITHM,
104  USER_MAIN
105  };
106 
108 
110  {
111  NO_REFINEMENT,
112  NEWTON_METHOD,
113  USER_REFINEMENT
114  };
115 
116 
117  // STRUCTURES
118 
121 
122  struct Results
123  {
125 
126  explicit Results(void);
127 
129 
130  virtual ~Results(void);
131 
132  void save(const std::string&) const;
133 
135 
137 
139 
141 
143 
145 
147 
149 
151 
153 
155 
157 
159 
161 
162  };
163 
164  // METHODS
165 
166  // Checking methods
167 
168  void check_performance_functional(void) const;
169  void check_training_algorithms(void) const;
170 
171  // Initialization methods
172 
173  void initialize_random(void);
174 
175  // Get methods
176 
178 
179  bool has_performance_functional(void) const;
180 
183 
188 
190 
191  const InitializationType& get_initialization_type(void) const;
192  const MainType& get_main_type(void) const;
193  const RefinementType& get_refinement_type(void) const;
194 
195  std::string write_initialization_type(void) const;
196  std::string write_main_type(void) const;
197  std::string write_refinement_type(void) const;
198 
199  std::string write_initialization_type_text(void) const;
200  std::string write_main_type_text(void) const;
201  std::string write_refinement_type_text(void) const;
202 
203  const bool& get_display(void) const;
204 
205  // Set methods
206 
207  void set(void);
208  void set(PerformanceFunctional*);
209  virtual void set_default(void);
210 
212 
214  void set_main_type(const MainType&);
215  void set_refinement_type(const RefinementType&);
216 
217  void set_initialization_type(const std::string&);
218  void set_main_type(const std::string&);
219  void set_refinement_type(const std::string&);
220 
221  void set_display(const bool&);
222 
223  // Pointer methods
224 
225  void destruct_initialization(void);
226  void destruct_main(void);
227  void destruct_refinement(void);
228 
229  // Training methods
230 
231  // This method trains a neural network which has a performance functional associated.
232 
234 
235  // Serialization methods
236 
237  std::string to_string(void) const;
238 
239  void print(void) const;
240 
241  tinyxml2::XMLDocument* to_XML(void) const;
242  void from_XML(const tinyxml2::XMLDocument&);
243 
244  void save(const std::string&) const;
245  void load(const std::string&);
246 
247 protected:
248 
250 
252 
254 
256 
258 
260 
262 
264 
266 
268 
270 
272 
274 
276 
278 
280 
282 
284 
286 
288 
290 
292 
294 
295  bool display;
296 
297 };
298 
299 }
300 
301 #endif
302 
303 
304 // OpenNN: Open Neural Networks Library.
305 // Copyright (c) 2005-2015 Roberto Lopez.
306 //
307 // This library is free software; you can redistribute it and/or
308 // modify it under the terms of the GNU Lesser General Public
309 // License as published by the Free Software Foundation; either
310 // version 2.1 of the License, or any later version.
311 //
312 // This library is distributed in the hope that it will be useful,
313 // but WITHOUT ANY WARRANTY; without even the implied warranty of
314 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
315 // Lesser General Public License for more details.
316 
317 // You should have received a copy of the GNU Lesser General Public
318 // License along with this library; if not, write to the Free Software
319 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
320 
std::string write_main_type_text(void) const
Returns a string with the main type in text format.
void destruct_main(void)
This method deletes the main training algorithm object which composes this training strategy object...
GradientDescent::GradientDescentResults * gradient_descent_results_pointer
Pointer to a structure with the results from the gradient descent training algorithm.
std::string write_refinement_type_text(void) const
Returns a string with the refinement type in text format.
PerformanceFunctional * get_performance_functional_pointer(void) const
Returns a pointer to the performance functional object to which the training strategy is associated...
void set_display(const bool &)
void from_XML(const tinyxml2::XMLDocument &)
void load(const std::string &)
virtual ~Results(void)
Destructor.
QuasiNewtonMethod * quasi_Newton_method_pointer
Pointer to a quasi-Newton method object to be used as a main training algorithm.
EvolutionaryAlgorithm * evolutionary_algorithm_pointer
Pointer to a evolutionary training object to be used for initialization in the training strategy...
void print(void) const
Prints to the screen the string representation of the training strategy object.
InitializationType initialization_type
Type of initialization training algorithm.
bool has_performance_functional(void) const
NewtonMethod * get_Newton_method_pointer(void) const
RandomSearch * get_random_search_pointer(void) const
void set_refinement_type(const RefinementType &)
const RefinementType & get_refinement_type(void) const
Returns the type of the refinement training algorithm composing this training strategy object...
void check_training_algorithms(void) const
QuasiNewtonMethod * get_quasi_Newton_method_pointer(void) const
LevenbergMarquardtAlgorithm::LevenbergMarquardtAlgorithmResults * Levenberg_Marquardt_algorithm_results_pointer
Pointer to a structure with the results from the Levenberg-Marquardt training algorithm.
NewtonMethod::NewtonMethodResults * Newton_method_results_pointer
Pointer to a structure with results from the Newton method training algorithm.
void save(const std::string &) const
void set_performance_functional_pointer(PerformanceFunctional *)
ConjugateGradient::ConjugateGradientResults * conjugate_gradient_results_pointer
Pointer to a structure with the results from the conjugate gradient training algorithm.
NewtonMethod * Newton_method_pointer
Pointer to a Newton method object to be used for refinement in the training strategy.
std::string to_string(void) const
Returns a string representation of the training strategy.
std::string write_initialization_type(void) const
Returns a string with the type of the initialization training algorithm composing this training strat...
GradientDescent * gradient_descent_pointer
Pointer to a gradient descent object to be used as a main training algorithm.
std::string write_refinement_type(void) const
Returns a string with the type of the refinement training algorithm composing this training strategy ...
PerformanceFunctional * performance_functional_pointer
Pointer to an external performance functional object.
LevenbergMarquardtAlgorithm * get_Levenberg_Marquardt_algorithm_pointer(void) const
EvolutionaryAlgorithm::EvolutionaryAlgorithmResults * evolutionary_algorithm_results_pointer
Pointer to a structure with the results from the evolutionary training algorithm. ...
void save(const std::string &) const
ConjugateGradient * get_conjugate_gradient_pointer(void) const
void set_initialization_type(const InitializationType &)
RefinementType refinement_type
Type of refinement training algorithm.
bool display
Display messages to screen.
QuasiNewtonMethod::QuasiNewtonMethodResults * quasi_Newton_method_results_pointer
Pointer to a structure with the results from the quasi-Newton method training algorithm.
std::string write_initialization_type_text(void) const
Returns a string with the initialization type in text format.
void set_main_type(const MainType &)
void destruct_initialization(void)
This method deletes the initialization training algorithm object which composes this training strateg...
const MainType & get_main_type(void) const
Returns the type of the main training algorithm composing this training strategy object.
virtual void set_default(void)
void destruct_refinement(void)
This method deletes the refinement training algorithm object which composes this training strategy ob...
Results(void)
Default constructor.
MainType
Enumeration of all the available types of training algorithms.
void check_performance_functional(void) const
Throws an exception if the training strategy has not a performance functional associated.
ConjugateGradient * conjugate_gradient_pointer
Pointer to a conjugate gradient object to be used as a main training algorithm.
GradientDescent * get_gradient_descent_pointer(void) const
RefinementType
Enumeration of all the available types of training algorithms.
RandomSearch * random_search_pointer
Pointer to a random search object to be used for initialization in the training strategy.
const bool & get_display(void) const
tinyxml2::XMLDocument * to_XML(void) const
EvolutionaryAlgorithm * get_evolutionary_algorithm_pointer(void) const
const InitializationType & get_initialization_type(void) const
Returns the type of the initialization training algorithm composing this training strategy object...
LevenbergMarquardtAlgorithm * Levenberg_Marquardt_algorithm_pointer
Pointer to a Levenberg-Marquardt algorithm object to be used as a main training algorithm.
InitializationType
Enumeration of all the available types of training algorithms.
MainType main_type
Type of main training algorithm.
RandomSearch::RandomSearchResults * random_search_results_pointer
Pointer to a structure with the results from the random search training algorithm.
std::string write_main_type(void) const
Returns a string with the type of the main training algorithm composing this training strategy object...