OpenNN  2.2
Open Neural Networks Library
scaling_layer.h
1 /****************************************************************************************************************/
2 /* */
3 /* OpenNN: Open Neural Networks Library */
4 /* www.artelnics.com/opennn */
5 /* */
6 /* S C A L I N G L A Y E R 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 __SCALINGLAYER_H__
15 #define __SCALINGLAYER_H__
16 
17 // System includes
18 
19 #include <cmath>
20 #include <cstdlib>
21 #include <fstream>
22 #include <iostream>
23 #include <string>
24 #include <sstream>
25 
26 // OpenNN includes
27 
28 #include "vector.h"
29 #include "matrix.h"
30 
31 // TinyXml includes
32 
33 #include "../tinyxml2/tinyxml2.h"
34 
35 namespace OpenNN
36 {
37 
41 
43 {
44 
45 public:
46 
47  // DEFAULT CONSTRUCTOR
48 
49  explicit ScalingLayer(void);
50 
51  // INPUTS NUMBER CONSTRUCTOR
52 
53  explicit ScalingLayer(const size_t&);
54 
55  // STATISTICS CONSTRUCTOR
56 
57  explicit ScalingLayer(const Vector< Statistics<double> >&);
58 
59  // COPY CONSTRUCTOR
60 
61  ScalingLayer(const ScalingLayer&);
62 
63  // DESTRUCTOR
64 
65  virtual ~ScalingLayer(void);
66 
67  // ASSIGNMENT OPERATOR
68 
70 
71  // EQUAL TO OPERATOR
72 
73  bool operator == (const ScalingLayer&) const;
74 
75  // ENUMERATIONS
76 
78 
79  enum ScalingMethod{NoScaling, MinimumMaximum, MeanStandardDeviation};
80 
81  // GET METHODS
82 
83  size_t get_scaling_neurons_number(void) const;
84 
85  // Inputs statistics
86 
88  Statistics<double> get_statistics(const size_t&) const;
89 
91 
92  Vector<double> arrange_means(void) const;
94 
95  // Variables scaling and unscaling
96 
97  const ScalingMethod& get_scaling_method(void) const;
98 
99  std::string write_scaling_method(void) const;
100  std::string write_scaling_method_text(void) const;
101 
102  // Display messages
103 
104  const bool& get_display(void) const;
105 
106  // SET METHODS
107 
108  void set(void);
109  void set(const size_t&);
110  void set(const Vector< Statistics<double> >&);
111  void set(const tinyxml2::XMLDocument&);
112  void set(const ScalingLayer&);
113 
114  virtual void set_default(void);
115 
116  // Statistics
117 
118  void set_statistics(const Vector< Statistics<double> >&);
119  void set_item_statistics(const size_t&, const Statistics<double>&);
120 
121  void set_minimum(const size_t&, const double&);
122  void set_maximum(const size_t&, const double&);
123  void set_mean(const size_t&, const double&);
124  void set_standard_deviation(const size_t&, const double&);
125 
126  // Scaling method
127 
128  void set_scaling_method(const ScalingMethod&);
129  void set_scaling_method(const std::string&);
130 
131  // Display messages
132 
133  void set_display(const bool&);
134 
135  // Pruning and growing
136 
137  void prune_scaling_neuron(const size_t&);
138 
139  // Check methods
140 
141  bool is_empty(void) const;
142 
143  // Inputs scaling function
144 
145  void initialize_random(void);
146 
147  void check_range(const Vector<double>&) const;
148 
152 
156 
160 
163 
164  // Expression methods
165 
166  std::string write_no_scaling_expression(const Vector<std::string>&, const Vector<std::string>&) const;
167 
169 
171 
172  std::string write_expression(const Vector<std::string>&, const Vector<std::string>&) const;
173 
174  // Serialization methods
175 
176  std::string to_string(void) const;
177 
178  tinyxml2::XMLDocument* to_XML(void) const;
179  virtual void from_XML(const tinyxml2::XMLDocument&);
180 
181 protected:
182 
183  // MEMBERS
184 
186 
188 
190 
192 
194 
195  bool display;
196 };
197 
198 }
199 
200 #endif
201 
202 
203 // OpenNN: Open Neural Networks Library.
204 // Copyright (c) 2005-2015 Roberto Lopez.
205 //
206 // This library is free software; you can redistribute it and/or
207 // modify it under the terms of the GNU Lesser General Public
208 // License as published by the Free Software Foundation; either
209 // version 2.1 of the License, or any later version.
210 //
211 // This library is distributed in the hope that it will be useful,
212 // but WITHOUT ANY WARRANTY; without even the implied warranty of
213 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
214 // Lesser General Public License for more details.
215 
216 // You should have received a copy of the GNU Lesser General Public
217 // License along with this library; if not, write to the Free Software
218 
219 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
220 
Vector< double > calculate_outputs(const Vector< double > &) const
void prune_scaling_neuron(const size_t &)
void set_item_statistics(const size_t &, const Statistics< double > &)
std::string write_scaling_method(void) const
Returns a string with the name of the method used for scaling.
size_t get_scaling_neurons_number(void) const
Returns the number of unscaling neurons in this layer.
Vector< double > calculate_mean_standard_deviation_derivatives(const Vector< double > &) const
const ScalingMethod & get_scaling_method(void) const
Returns the method used for scaling.
std::string write_scaling_method_text(void) const
Vector< Statistics< double > > statistics
Statistics of input variables.
void check_range(const Vector< double > &) const
ScalingMethod scaling_method
Method for scaling the input variables.
virtual void from_XML(const tinyxml2::XMLDocument &)
Vector< Statistics< double > > get_statistics(void) const
void set(void)
Sets the scaling layer to be empty.
Vector< double > calculate_minimum_maximum_derivatives(const Vector< double > &) const
void set_mean(const size_t &, const double &)
void set_statistics(const Vector< Statistics< double > > &)
bool operator==(const ScalingLayer &) const
void set_display(const bool &)
ScalingMethod
Enumeration of available methods for scaling the input variables.
Definition: scaling_layer.h:79
void set_scaling_method(const ScalingMethod &)
Vector< double > arrange_means(void) const
Returns a single matrix with the means of all scaling neurons.
Vector< double > calculate_minimum_maximum_outputs(const Vector< double > &) const
Vector< double > calculate_minimum_maximum_second_derivatives(const Vector< double > &) const
tinyxml2::XMLDocument * to_XML(void) const
const bool & get_display(void) const
void set_maximum(const size_t &, const double &)
std::string write_mean_standard_deviation_expression(const Vector< std::string > &, const Vector< std::string > &) const
Vector< double > arrange_standard_deviations(void) const
Returns a single matrix with the standard deviations of all scaling neurons.
virtual void set_default(void)
Vector< Matrix< double > > arrange_Hessian_form(const Vector< double > &) const
Arranges a "Hessian form" vector of matrices from the vector of second derivatives.
bool display
Display warning messages to screen.
std::string to_string(void) const
Returns a string representation of the current scaling layer object.
virtual ~ScalingLayer(void)
Destructor.
void initialize_random(void)
Matrix< double > arrange_Jacobian(const Vector< double > &) const
Arranges a "Jacobian" matrix from the vector of derivatives.
Vector< double > calculate_derivatives(const Vector< double > &) const
std::string write_no_scaling_expression(const Vector< std::string > &, const Vector< std::string > &) const
Vector< double > calculate_mean_standard_deviation_outputs(const Vector< double > &) const
std::string write_expression(const Vector< std::string > &, const Vector< std::string > &) const
Returns a string with the expression of the inputs scaling process.
Matrix< double > arrange_statistics(void) const
std::string write_minimum_maximum_expression(const Vector< std::string > &, const Vector< std::string > &) const
Vector< double > calculate_second_derivatives(const Vector< double > &) const
Vector< double > calculate_mean_standard_deviation_second_derivatives(const Vector< double > &) const
void set_standard_deviation(const size_t &, const double &)
void set_minimum(const size_t &, const double &)
ScalingLayer & operator=(const ScalingLayer &)
bool is_empty(void) const
Returns true if the number of scaling neurons is zero, and false otherwise.