scaling_layer.h
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// S C A L I N G L A Y E R C L A S S H E A D E R
5//
6// Artificial Intelligence Techniques SL
7// artelnics@artelnics.com
8
9#ifndef SCALINGLAYER_H
10#define SCALINGLAYER_H
11
12// System includes
13
14#include <cmath>
15#include <cstdlib>
16#include <fstream>
17#include <iostream>
18#include <string>
19#include <sstream>
20
21// OpenNN includes
22
23#include "layer.h"
24#include "statistics.h"
25#include "scaling.h"
26#include "opennn_strings.h"
27
28namespace OpenNN
29{
30
32
36
37class ScalingLayer : public Layer
38{
39
40public:
41
42 // Constructors
43
44 explicit ScalingLayer();
45
46 explicit ScalingLayer(const Index&);
47 explicit ScalingLayer(const Tensor<Index, 1>&);
48
49 explicit ScalingLayer(const Tensor<Descriptives, 1>&);
50
51 // Destructors
52
53 virtual ~ScalingLayer();
54
55 // Get methods
56
57 Tensor<Index, 1> get_outputs_dimensions() const;
58
59 Index get_inputs_number() const;
60 Index get_neurons_number() const;
61
62 // Inputs descriptives
63
64 Tensor<Descriptives, 1> get_descriptives() const;
65 Descriptives get_descriptives(const Index&) const;
66
67 Tensor<type, 1> get_minimums() const;
68 Tensor<type, 1> get_maximums() const;
69 Tensor<type, 1> get_means() const;
70 Tensor<type, 1> get_standard_deviations() const;
71
72 // Variables scaling and unscaling
73
74 const Tensor<Scaler, 1> get_scaling_methods() const;
75
76 Tensor<string, 1> write_scalers() const;
77 Tensor<string, 1> write_scalers_text() const;
78
79 // Display messages
80
81 const bool& get_display() const;
82
83 // Set methods
84
85 void set();
86 void set(const Index&);
87 void set(const Tensor<Index, 1>&);
88 void set(const Tensor<Descriptives, 1>&);
89 void set(const Tensor<Descriptives, 1>&, const Tensor<Scaler, 1>&);
90 void set(const tinyxml2::XMLDocument&);
91
92 void set_inputs_number(const Index&);
93 void set_neurons_number(const Index&);
94
95 void set_default();
96
97 // Descriptives
98
99 void set_descriptives(const Tensor<Descriptives, 1>&);
100 void set_item_descriptives(const Index&, const Descriptives&);
101
102 void set_minimum(const Index&, const type&);
103 void set_maximum(const Index&, const type&);
104 void set_mean(const Index&, const type&);
105 void set_standard_deviation(const Index&, const type&);
106
107 void set_min_max_range(const type& min, const type& max);
108
109 // Scaling method
110
111 void set_scalers(const Tensor<Scaler, 1>&);
112 void set_scalers(const Tensor<string, 1>&);
113
114 void set_scalers(const Scaler&);
115 void set_scalers(const string&);
116
117 // Display messages
118
119 void set_display(const bool&);
120
121 // Check methods
122
123 bool is_empty() const;
124
125 void check_range(const Tensor<type, 1>&) const;
126
127 Tensor<type, 2> calculate_outputs(const Tensor<type, 2>&);
128 Tensor<type, 4> calculate_outputs(const Tensor<type, 4>&);
129
130 // Expression methods
131
132 string write_no_scaling_expression(const Tensor<string, 1>&, const Tensor<string, 1>&) const;
133
134 string write_minimum_maximum_expression(const Tensor<string, 1>&, const Tensor<string, 1>&) const;
135
136 string write_mean_standard_deviation_expression(const Tensor<string, 1>&, const Tensor<string, 1>&) const;
137
138 string write_standard_deviation_expression(const Tensor<string, 1>&, const Tensor<string, 1>&) const;
139
140 string write_expression(const Tensor<string, 1>&, const Tensor<string, 1>&) const;
141
142 string write_expression_c() const;
143
144 string write_expression_python() const;
145
146 // Serialization methods
147
148 virtual void from_XML(const tinyxml2::XMLDocument&);
149
150 void write_XML(tinyxml2::XMLPrinter&) const;
151
152protected:
153
154 Tensor<Index, 1> input_variables_dimensions;
155
157
158 Tensor<Descriptives, 1> descriptives;
159
161
162 Tensor<Scaler, 1> scalers;
163
165
167 type max_range;
168
170
171 bool display = true;
172
173};
174
175}
176
177#endif
178
179
180// OpenNN: Open Neural Networks Library.
181// Copyright(C) 2005-2021 Artificial Intelligence Techniques, SL.
182//
183// This library is free software; you can redistribute it and/or
184// modify it under the terms of the GNU Lesser General Public
185// License as published by the Free Software Foundation; either
186// version 2.1 of the License, or any later version.
187//
188// This library is distributed in the hope that it will be useful,
189// but WITHOUT ANY WARRANTY; without even the implied warranty of
190// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
191// Lesser General Public License for more details.
192
193// You should have received a copy of the GNU Lesser General Public
194// License along with this library; if not, write to the Free Software
195
196// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
197
This abstract class represents the concept of layer of neurons in OpenNN.
Definition: layer.h:53
This class represents a layer of scaling neurons.
Definition: scaling_layer.h:38
string write_expression_c() const
write_expression_c
void set_maximum(const Index &, const type &)
void set_descriptives(const Tensor< Descriptives, 1 > &)
void set_item_descriptives(const Index &, const Descriptives &)
Tensor< type, 1 > get_means() const
Returns a single matrix with the means of all scaling neurons.
void set_minimum(const Index &, const type &)
string write_mean_standard_deviation_expression(const Tensor< string, 1 > &, const Tensor< string, 1 > &) const
Tensor< string, 1 > write_scalers() const
Returns a vector of strings with the name of the method used for each scaling neuron.
const bool & get_display() const
void set_standard_deviation(const Index &, const type &)
Index get_inputs_number() const
Returns the number of inputs.
string write_standard_deviation_expression(const Tensor< string, 1 > &, const Tensor< string, 1 > &) const
string write_expression(const Tensor< string, 1 > &, const Tensor< string, 1 > &) const
Returns a string with the expression of the inputs scaling process.
virtual void from_XML(const tinyxml2::XMLDocument &)
Tensor< Scaler, 1 > scalers
Vector of scaling methods for each variable.
void check_range(const Tensor< type, 1 > &) const
bool display
Display warning messages to screen.
bool is_empty() const
Returns true if the number of scaling neurons is zero, and false otherwise.
virtual ~ScalingLayer()
Destructor.
void set()
Sets the scaling layer to be empty.
Tensor< type, 1 > get_minimums() const
Returns a single matrix with the minimums of all scaling neurons.
string write_minimum_maximum_expression(const Tensor< string, 1 > &, const Tensor< string, 1 > &) const
Tensor< type, 1 > get_maximums() const
Returns a single matrix with the maximums of all scaling neurons.
string write_no_scaling_expression(const Tensor< string, 1 > &, const Tensor< string, 1 > &) const
void set_scalers(const Tensor< Scaler, 1 > &)
Tensor< type, 2 > calculate_outputs(const Tensor< type, 2 > &)
Tensor< Descriptives, 1 > get_descriptives() const
type min_range
min and max range for minmaxscaling
const Tensor< Scaler, 1 > get_scaling_methods() const
Returns the methods used for scaling.
Tensor< Descriptives, 1 > descriptives
Descriptives of input variables.
Tensor< string, 1 > write_scalers_text() const
void set_display(const bool &)
Tensor< type, 1 > get_standard_deviations() const
Returns a single matrix with the standard deviations of all scaling neurons.
void write_XML(tinyxml2::XMLPrinter &) const
void set_mean(const Index &, const type &)
void set_min_max_range(const type &min, const type &max)
This structure contains the simplest Descriptives for a set, variable, etc. It includes :
Definition: statistics.h:40