1 // OpenNN: Open Neural Networks Library 2 // www.opennn.net 3 // 4 // U N 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 UNSCALINGLAYER_H 10 #define UNSCALINGLAYER_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 "config.h" 24 #include "layer.h" 25 #include "statistics.h" 26 #include "opennn_strings.h" 27 28 29 namespace OpenNN 30 { 31 32 /// This class represents a layer of unscaling neurons. 33 34 /// 35 /// Unscaling layers are included in the definition of a neural network. 36 /// They are used to unnormalize variables so they are in the original range after computer processing. 37 38 class UnscalingLayer : public Layer 39 { 40 41 public: 42 43 // Constructors 44 45 explicit UnscalingLayer(); 46 47 explicit UnscalingLayer(const Index&); 48 49 explicit UnscalingLayer(const Tensor<Descriptives, 1>&); 50 51 // Destructor 52 53 virtual ~UnscalingLayer(); 54 55 // Enumerations 56 57 /// Enumeration of available methods for input variables, output variables and independent parameters scaling. 58 59 enum UnscalingMethod{NoUnscaling, MinimumMaximum, MeanStandardDeviation, Logarithmic}; 60 61 // Get methods 62 63 64 65 Index get_inputs_number() const; 66 Index get_neurons_number() const; 67 68 Tensor<Descriptives, 1> get_descriptives() const; 69 Tensor<type, 2> get_descriptives_matrix() const; 70 71 Tensor<type, 1> get_minimums() const; 72 Tensor<type, 1> get_maximums() const; 73 74 const Tensor<UnscalingLayer::UnscalingMethod, 1> get_unscaling_method() const; 75 76 Tensor<string, 1> write_unscaling_methods() const; 77 Tensor<string, 1> write_unscaling_method_text() const; 78 79 const bool& get_display() const; 80 81 // Set methods 82 83 void set(); 84 void set(const Index&); 85 void set(const Tensor<Descriptives, 1>&); 86 void set(const tinyxml2::XMLDocument&); 87 void set(const UnscalingLayer&); 88 89 void set_inputs_number(const Index&); 90 void set_neurons_number(const Index&); 91 92 virtual void set_default(); 93 94 // Output variables descriptives 95 96 void set_descriptives(const Tensor<Descriptives, 1>&); 97 void set_descriptives_eigen(const Tensor<type, 2>&); 98 99 void set_item_descriptives(const Index&, const Descriptives&); 100 101 void set_minimum(const Index&, const type&); 102 void set_maximum(const Index&, const type&); 103 void set_mean(const Index&, const type&); 104 void set_standard_deviation(const Index&, const type&); 105 106 void set_min_max_range(const type min, const type max); 107 108 // Outputs unscaling method 109 110 void set_unscaling_methods(const Tensor<UnscalingMethod,1>&); 111 void set_unscaling_methods(const string&); 112 void set_unscaling_methods(const Tensor<string, 1>&); 113 void set_unscaling_methods(const UnscalingLayer::UnscalingMethod&); 114 115 // Display messages 116 117 void set_display(const bool&); 118 119 // Check methods 120 121 bool is_empty() const; 122 123 Tensor<type, 2> calculate_outputs(const Tensor<type, 2>&); 124 125 void check_range(const Tensor<type, 1>&) const; 126 127 // Serialization methods 128 129 130 131 132 void from_XML(const tinyxml2::XMLDocument&); 133 134 void write_XML(tinyxml2::XMLPrinter&) const; 135 136 // Expression methods 137 138 string write_expression(const Tensor<string, 1>&, const Tensor<string, 1>&) const; 139 140 string write_expression_c() const; 141 string write_expression_python() const; 142 143 144 protected: 145 146 // MEMBERS 147 148 /// Descriptives of output variables. 149 150 Tensor<Descriptives, 1> descriptives; 151 152 /// Unscaling method for the output variables. 153 154 Tensor<UnscalingMethod, 1> unscaling_methods; 155 156 /// min and max range for unscaling 157 158 type min_range; 159 type max_range; 160 161 /// Display warning messages to screen. 162 163 bool display = true; 164 }; 165 166 } 167 168 #endif 169 170 171 // OpenNN: Open Neural Networks Library. 172 // Copyright(C) 2005-2020 Artificial Intelligence Techniques, SL. 173 // 174 // This library is free software; you can redistribute it and/or 175 // modify it under the terms of the GNU Lesser General Public 176 // License as published by the Free Software Foundation; either 177 // version 2.1 of the License, or any later version. 178 // 179 // This library is distributed in the hope that it will be useful, 180 // but WITHOUT ANY WARRANTY; without even the implied warranty of 181 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 182 // Lesser General Public License for more details. 183 184 // You should have received a copy of the GNU Lesser General Public 185 // License along with this library; if not, write to the Free Software 186 187 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 188 189