OpenNN  2.2
Open Neural Networks Library
random_search.h
1 /****************************************************************************************************************/
2 /* */
3 /* OpenNN: Open Neural Networks Library */
4 /* www.artelnics.com/opennn */
5 /* */
6 /* R A N D O M S E A R C H 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 __RANDOMSEARCH_H__
15 #define __RANDOMSEARCH_H__
16 
17 // System includes
18 
19 #include <string>
20 #include <sstream>
21 #include <iostream>
22 #include <fstream>
23 #include <algorithm>
24 #include <functional>
25 #include <cmath>
26 #include <ctime>
27 
28 // OpenNN includes
29 
30 #include "performance_functional.h"
31 
32 #include "training_algorithm.h"
33 
34 // TinyXml includes
35 
36 #include "../tinyxml2/tinyxml2.h"
37 
38 namespace OpenNN
39 {
40 
44 
46 {
47 
48 public:
49 
50  // DEFAULT CONSTRUCTOR
51 
52  explicit RandomSearch(void);
53 
54 
55  // PERFORMANCE FUNCTIONAL CONSTRUCTOR
56 
58 
59 
60  // XML CONSTRUCTOR
61 
62  explicit RandomSearch(const tinyxml2::XMLDocument&);
63 
64 
65  // DESTRUCTOR
66 
67  virtual ~RandomSearch(void);
68 
69  // STRUCTURES
70 
74 
76  {
78 
80  {
81  random_search_pointer = NULL;
82  }
83 
85 
86  RandomSearchResults(RandomSearch* new_random_search_pointer)
87  {
88  random_search_pointer = new_random_search_pointer;
89  }
90 
92 
93  virtual ~RandomSearchResults(void)
94  {
95  }
96 
98 
100 
101 
102  // TRAINING HISTORY
103 
105 
107 
109 
111 
113 
115 
117 
119 
121 
123 
125 
127 
129 
131 
133 
135 
136  // FINAL VALUES
137 
139 
141 
143 
145 
147 
149 
151 
153 
155 
157 
159 
161 
163 
164  double elapsed_time;
165 
167 
169 
170  // METHODS
171 
172  void resize_training_history(const size_t&);
173 
174  std::string to_string(void) const;
175 
176  Matrix<std::string> write_final_results(const size_t& precision = 3) const;
177  };
178 
179 
180  // METHODS
181 
182  // Get methods
183 
184  const double& get_training_rate_reduction_factor(void) const;
185  const size_t& get_training_rate_reduction_period(void) const;
186 
187  const bool& get_reserve_parameters_history(void) const;
188  const bool& get_reserve_parameters_norm_history(void) const;
189 
190  const bool& get_reserve_performance_history(void) const;
191 
192  // Training parameters
193 
194  const double& get_warning_parameters_norm(void) const;
195  const double& get_warning_training_rate(void) const;
196 
197  const double& get_error_parameters_norm(void) const;
198  const double& get_error_training_rate(void) const;
199 
200  // Stopping criteria
201 
202  const double& get_performance_goal(void) const;
203  const size_t& get_maximum_generalization_performance_decreases(void) const;
204 
205  const size_t& get_maximum_iterations_number(void) const;
206  const double& get_maximum_time(void) const;
207 
208  // Reserve training history
209 
210  const bool& get_reserve_generalization_performance_history(void) const;
211 
212  const bool& get_reserve_training_direction_history(void) const;
213  const bool& get_reserve_training_rate_history(void) const;
214  const bool& get_reserve_elapsed_time_history(void) const;
215 
216  // Set methods
217 
218  void set_default(void);
219 
220  void set_first_training_rate(const double&);
221  void set_training_rate_reduction_factor(const double&);
222  void set_training_rate_reduction_period(const size_t&);
223 
224  void set_reserve_parameters_history(const bool&);
225  void set_reserve_parameters_norm_history(const bool&);
226 
227  void set_reserve_performance_history(const bool&);
228 
229  // Training parameters
230 
231  void set_warning_parameters_norm(const double&);
232  void set_warning_training_rate(const double&);
233 
234  void set_error_parameters_norm(const double&);
235  void set_error_training_rate(const double&);
236 
237  // Stopping criteria
238 
239  void set_performance_goal(const double&);
241 
242  void set_maximum_iterations_number(const size_t&);
243  void set_maximum_time(const double&);
244 
245  // Reserve training history
246 
248 
249  void set_reserve_training_direction_history(const bool&);
251  void set_reserve_training_rate_history(const bool&);
252  void set_reserve_elapsed_time_history(const bool&);
253 
255 
256  virtual void set_reserve_all_training_history(const bool&);
257 
258  // Utilities
259 
260  void set_display_period(const size_t&);
261 
262  // Training methods
263 
265 
267 
268  std::string write_training_algorithm_type(void) const;
269 
270  // Serialization methods
271 
273 
274  tinyxml2::XMLDocument* to_XML(void) const;
275  void from_XML(const tinyxml2::XMLDocument&);
276 
277 private:
278 
279  // MEMBERS
280 
281  // TRAINING PARAMETERS
282 
284 
286 
289 
291 
293 
295 
297 
299 
301 
303 
305 
307 
309 
311 
312 
313  // STOPPING CRITERIA
314 
316 
318 
321 
323 
325 
327 
329 
330  double maximum_time;
331 
332 
333  // TRAINING HISTORY
334 
336 
338 
340 
342 
344 
346 
348 
350 
352 
354 
356 
358 
360 
362 
364 
366 };
367 
368 }
369 
370 #endif
371 
372 
373 // OpenNN: Open Neural Networks Library.
374 // Copyright (c) 2005-2015 Roberto Lopez.
375 //
376 // This library is free software; you can redistribute it and/or
377 // modify it under the terms of the GNU Lesser General Public
378 // License as published by the Free Software Foundation; either
379 // version 2.1 of the License, or any later version.
380 //
381 // This library is distributed in the hope that it will be useful,
382 // but WITHOUT ANY WARRANTY; without even the implied warranty of
383 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
384 // Lesser General Public License for more details.
385 
386 // You should have received a copy of the GNU Lesser General Public
387 // License along with this library; if not, write to the Free Software
388 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
void set_error_parameters_norm(const double &)
void set_error_training_rate(const double &)
double maximum_time
Maximum training time. It is used as a stopping criterion.
virtual ~RandomSearchResults(void)
Destructor.
Definition: random_search.h:93
void set_training_rate_reduction_factor(const double &)
void set_first_training_rate(const double &)
bool reserve_generalization_performance_history
True if the Generalization performance history vector is to be reserved, false otherwise.
size_t maximum_generalization_performance_decreases
void set_display_period(const size_t &)
const bool & get_reserve_parameters_norm_history(void) const
Returns true if the parameters norm history vector is to be reserved, and false otherwise.
RandomSearch * random_search_pointer
Pointer to the random search object for which the training results are to be stored.
Definition: random_search.h:99
bool reserve_training_rate_history
True if the training rate history vector is to be reserved, false otherwise.
const double & get_error_parameters_norm(void) const
Vector< double > parameters_norm_history
History of the parameters norm over the training iterations.
Vector< Vector< double > > parameters_history
History of the neural network parameters over the training iterations.
RandomSearchResults(RandomSearch *new_random_search_pointer)
Random search constructor.
Definition: random_search.h:86
std::string write_training_algorithm_type(void) const
This method writes a string with the type of training algoritm.
size_t maximum_iterations_number
Maximum number of iterations to perform_training. It is used as a stopping criterion.
Vector< double > generalization_performance_history
History of the generalization performance over the training iterations.
virtual void set_reserve_all_training_history(const bool &)
Makes the training history of all variables to be reseved or not in memory.
double final_parameters_norm
Final neural network parameters norm.
void set_training_rate_reduction_period(const size_t &)
bool reserve_training_direction_history
True if the training direction history matrix is to be reserved, false otherwise. ...
void set_reserve_parameters_norm_history(const bool &)
const double & get_maximum_time(void) const
Returns the maximum training time.
const double & get_warning_parameters_norm(void) const
Returns the minimum value for the norm of the parameters vector at wich a warning message is written ...
void set_reserve_elapsed_time_history(const bool &)
bool reserve_performance_history
True if the performance history vector is to be reserved, false otherwise.
Vector< Vector< double > > training_direction_history
History of the random search training direction over the training iterations.
void set_maximum_iterations_number(const size_t &)
void set_maximum_generalization_performance_decreases(const size_t &)
double final_training_rate
Final random search training rate.
Vector< double > performance_history
History of the performance function performance over the training iterations.
bool reserve_parameters_history
True if the parameters history vector of vectors is to be reserved, false otherwise.
const size_t & get_training_rate_reduction_period(void) const
Returns the reducing period for the training rate.
void set_reserve_training_rate_history(const bool &)
void from_XML(const tinyxml2::XMLDocument &)
const size_t & get_maximum_iterations_number(void) const
Returns the maximum number of iterations for training.
const double & get_performance_goal(void) const
const bool & get_reserve_performance_history(void) const
Returns true if the performance history vector is to be reserved, and false otherwise.
void set_warning_parameters_norm(const double &)
double warning_parameters_norm
Value for the parameters norm at which a warning message is written to the screen.
Vector< double > training_direction_norm_history
History of the norm of the training direction over the training iterations.
Vector< double > elapsed_time_history
History of the elapsed time over the training iterations.
size_t iterations_number
Maximum number of training iterations.
const double & get_training_rate_reduction_factor(void) const
Returns the reducing factor for the training rate.
const bool & get_reserve_training_rate_history(void) const
Returns true if the training rate history vector is to be reserved, and false otherwise.
std::string to_string(void) const
Returns a string representation of the current random search results structure.
double warning_training_rate
Training rate value at wich a warning message is written to the screen.
Vector< double > final_parameters
Final neural network parameters vector.
RandomSearchResults(void)
Default constructor.
Definition: random_search.h:79
double training_rate_reduction_factor
bool reserve_elapsed_time_history
True if the elapsed time history vector 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.
double final_generalization_performance
Final generalization performance.
RandomSearchResults * perform_training(void)
void set_reserve_parameters_history(const bool &)
const double & get_warning_training_rate(void) const
Returns the training rate value at wich a warning message is written to the screen during line minimi...
void set_warning_training_rate(const double &)
double final_performance
Final performance function evaluation.
const bool & get_reserve_training_direction_history(void) const
Returns true if the training direction history matrix is to be reserved, and false otherwise...
virtual ~RandomSearch(void)
const double & get_error_training_rate(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...
void set_reserve_performance_history(const bool &)
const size_t & get_maximum_generalization_performance_decreases(void) const
Returns the maximum number of generalization failures during the training process.
Matrix< std::string > to_string_matrix(void) const
size_t training_rate_reduction_period
Iterations interval at which the training rate is reduced.
double first_training_rate
Initial training rate following a random training direction.
Vector< double > training_rate_history
History of the random search training rate over the training iterations.
void set_reserve_training_direction_history(const bool &)
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 error_parameters_norm
Value for the parameters norm at which the training process is assumed to fail.
void set_reserve_generalization_performance_history(const bool &)
Vector< double > final_training_direction
Final random search training direction.
bool reserve_parameters_norm_history
True if the parameters norm history vector is to be reserved, false otherwise.
bool reserve_training_direction_norm_history
True if the training direction norm history vector is to be reserved, false otherwise.
double elapsed_time
Elapsed time of the training process.
double performance_goal
Goal value for the performance. It is used as a stopping criterion.
Vector< double > calculate_training_direction(void) const
Calculates a random vector to be used as training direction.
void set_reserve_training_direction_norm_history(const bool &)
void set_maximum_time(const double &)
Matrix< std::string > write_final_results(const size_t &precision=3) const
Returns a default (empty) string matrix with the final results from training.
void set_performance_goal(const double &)
double error_training_rate
Training rate at wich the line minimization algorithm is assumed to be unable to bracket a minimum...
tinyxml2::XMLDocument * to_XML(void) const