OpenNN  2.2
Open Neural Networks Library
training_algorithm.h
1 /****************************************************************************************************************/
2 /* */
3 /* OpenNN: Open Neural Networks Library */
4 /* www.artelnics.com/opennn */
5 /* */
6 /* T R A I N I N G A L G O R I T H M 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 __TRAININGALGORITHM_H__
15 #define __TRAININGALGORITHM_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 // TinyXml includes
32 
33 #include "../tinyxml2/tinyxml2.h"
34 
35 namespace OpenNN
36 {
37 
40 
42 {
43 
44 public:
45 
46  // DEFAULT CONSTRUCTOR
47 
48  explicit TrainingAlgorithm(void);
49 
50  // GENERAL CONSTRUCTOR
51 
53 
54  // XML CONSTRUCTOR
55 
56  explicit TrainingAlgorithm(const tinyxml2::XMLDocument&);
57 
58  // DESTRUCTOR
59 
60  virtual ~TrainingAlgorithm(void);
61 
62  // ASSIGNMENT OPERATOR
63 
65 
66  // EQUAL TO OPERATOR
67 
68  virtual bool operator == (const TrainingAlgorithm&) const;
69 
70 
71  // STRUCTURES
72 
76 
78  {
79  explicit TrainingAlgorithmResults(void)
80  {
81 
82  }
83 
84  virtual ~TrainingAlgorithmResults(void)
85  {
86 
87  }
88 
90 
91  virtual std::string to_string(void) const
92  {
93  std::string str;
94 
95  return(str);
96  }
97 
99 
100  virtual Matrix<std::string> write_final_results(const size_t&) const
101  {
102  Matrix<std::string> final_results;
103 
104  return(final_results);
105  }
106  };
107 
108 
109  // METHODS
110 
111  // Get methods
112 
114 
115  bool has_performance_functional(void) const;
116 
117  // Utilities
118 
119  const bool& get_display(void) const;
120 
121  const size_t& get_display_period(void) const;
122 
123  const size_t& get_save_period(void) const;
124 
125  const std::string& get_neural_network_file_name(void) const;
126 
127  // Set methods
128 
129  void set(void);
130  void set(PerformanceFunctional*);
131  virtual void set_default(void);
132 
134 
135  void set_display(const bool&);
136 
137  void set_display_period(const size_t&);
138 
139  void set_save_period(const size_t&);
140  void set_neural_network_file_name(const std::string&);
141 
142  // Training methods
143 
144  virtual void check(void) const;
145 
147 
148  virtual TrainingAlgorithmResults* perform_training(void) = 0;
149 
150  virtual std::string write_training_algorithm_type(void) const;
151 
152  // Serialization methods
153 
154  virtual std::string to_string(void) const;
155  void print(void) const;
156 
157  virtual Matrix<std::string> to_string_matrix(void) const;
158 
159  virtual tinyxml2::XMLDocument* to_XML(void) const;
160  virtual void from_XML(const tinyxml2::XMLDocument&);
161 
162  void save(const std::string&) const;
163  void load(const std::string&);
164 
165  virtual void initialize_random(void);
166 
167 protected:
168 
169  // FIELDS
170 
172 
174 
175  // UTILITIES
176 
178 
180 
182 
183  size_t save_period;
184 
186 
188 
190 
191  bool display;
192 };
193 
194 }
195 
196 #endif
197 
198 
199 // OpenNN: Open Neural Networks Library.
200 // Copyright (c) 2005-2015 Roberto Lopez.
201 //
202 // This library is free software; you can redistribute it and/or
203 // modify it under the terms of the GNU Lesser General Public
204 // License as published by the Free Software Foundation; either
205 // version 2.1 of the License, or any later version.
206 //
207 // This library is distributed in the hope that it will be useful,
208 // but WITHOUT ANY WARRANTY; without even the implied warranty of
209 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
210 // Lesser General Public License for more details.
211 
212 // You should have received a copy of the GNU Lesser General Public
213 // License along with this library; if not, write to the Free Software
214 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
215 
virtual Matrix< std::string > write_final_results(const size_t &) const
Returns a default (empty) string matrix with the final results from training.
void set_display_period(const size_t &)
virtual void set_default(void)
Sets the members of the training algorithm object to their default values.
void save(const std::string &) const
const size_t & get_save_period(void) const
Returns the number of iterations between the training saving progress.
bool display
Display messages to screen.
PerformanceFunctional * get_performance_functional_pointer(void) const
bool has_performance_functional(void) const
void print(void) const
Prints to the screen the XML-type representation of the training algorithm object.
void set_save_period(const size_t &)
size_t save_period
Number of iterations between the training saving progress.
virtual tinyxml2::XMLDocument * to_XML(void) const
virtual TrainingAlgorithmResults * perform_training(void)=0
Trains a neural network which has a performance functional associated.
std::string neural_network_file_name
Path where the neural network is saved.
void set_neural_network_file_name(const std::string &)
virtual std::string write_training_algorithm_type(void) const
This method writes a string with the type of training algoritm.
virtual Matrix< std::string > to_string_matrix(void) const
virtual TrainingAlgorithm & operator=(const TrainingAlgorithm &)
virtual bool operator==(const TrainingAlgorithm &) const
virtual std::string to_string(void) const
Returns a string representation of the results structure.
virtual void check(void) const
virtual std::string to_string(void) const
Returns a default string representation of a training algorithm.
const bool & get_display(void) const
virtual void initialize_random(void)
const size_t & get_display_period(void) const
Returns the number of iterations between the training showing progress.
virtual void from_XML(const tinyxml2::XMLDocument &)
PerformanceFunctional * performance_functional_pointer
Pointer to a performance functional for a multilayer perceptron object.
virtual void set_performance_functional_pointer(PerformanceFunctional *)
virtual ~TrainingAlgorithm(void)
Destructor.
size_t display_period
Number of iterations between the training showing progress.
void load(const std::string &)
const std::string & get_neural_network_file_name(void) const
Returns the file name where the neural network will be saved.