00001 /****************************************************************************************************************/ 00002 /* */ 00003 /* OpenNN: Open Neural Networks Library */ 00004 /* www.opennn.cimne.com */ 00005 /* */ 00006 /* S C A L I N G L A Y E R C L A S S H E A D E R */ 00007 /* */ 00008 /* Roberto Lopez */ 00009 /* International Center for Numerical Methods in Engineering (CIMNE) */ 00010 /* Technical University of Catalonia (UPC) */ 00011 /* Barcelona, Spain */ 00012 /* E-mail: rlopez@cimne.upc.edu */ 00013 /* */ 00014 /****************************************************************************************************************/ 00015 00016 #ifndef __SCALINGLAYER_H__ 00017 #define __SCALINGLAYER_H__ 00018 00019 // System includes 00020 00021 #include <string> 00022 00023 // OpenNN includes 00024 00025 #include "../utilities/vector.h" 00026 #include "../utilities/matrix.h" 00027 00028 // TinyXml includes 00029 00030 #include "../../parsers/tinyxml/tinyxml.h" 00031 00032 namespace OpenNN 00033 { 00034 00038 00039 class ScalingLayer 00040 { 00041 00042 public: 00043 00044 // DEFAULT CONSTRUCTOR 00045 00046 explicit ScalingLayer(void); 00047 00048 // INPUTS NUMBER CONSTRUCTOR 00049 00050 explicit ScalingLayer(const unsigned int&); 00051 00052 // STATISTICS CONSTRUCTOR 00053 00054 explicit ScalingLayer(const Vector< Vector<double> >&); 00055 00056 // COPY CONSTRUCTOR 00057 00058 ScalingLayer(const ScalingLayer&); 00059 00060 // DESTRUCTOR 00061 00062 virtual ~ScalingLayer(void); 00063 00064 // ASSIGNMENT OPERATOR 00065 00066 ScalingLayer& operator = (const ScalingLayer&); 00067 00068 // EQUAL TO OPERATOR 00069 00070 bool operator == (const ScalingLayer&) const; 00071 00072 // ENUMERATIONS 00073 00075 00076 enum ScalingMethod{MinimumMaximum, MeanStandardDeviation}; 00077 00078 // GET METHODS 00079 00080 unsigned int count_scaling_neurons_number(void) const; 00081 00082 // Inputs statistics 00083 00084 const Vector<double>& get_minimums(void) const; 00085 double get_minimum(const unsigned int&) const; 00086 00087 const Vector<double>& get_maximums(void) const; 00088 double get_maximum(const unsigned int&) const; 00089 00090 const Vector<double>& get_means(void) const; 00091 double get_mean(const unsigned int&) const; 00092 00093 const Vector<double>& get_standard_deviations(void) const; 00094 double get_standard_deviation(const unsigned int&) const; 00095 00096 Vector< Vector<double>* > get_minimums_maximums(void); 00097 Vector< Vector<double>* > get_means_standard_deviations(void); 00098 Vector< Vector<double>* > get_statistics(void); 00099 00100 // Variables scaling and unscaling 00101 00102 const ScalingMethod& get_scaling_method(void) const; 00103 00104 std::string write_scaling_method(void) const; 00105 00106 // Display messages 00107 00108 const bool& get_display(void) const; 00109 00110 // SET METHODS 00111 00112 void set(void); 00113 void set(const unsigned int&); 00114 void set(const Vector< Vector<double> >&); 00115 void set(TiXmlElement*); 00116 void set(const ScalingLayer&); 00117 00118 virtual void set_default(void); 00119 00120 // Input variables statistics 00121 00122 void set_minimums(const Vector<double>&); 00123 void set_minimum(const unsigned int&, const double&); 00124 00125 void set_maximums(const Vector<double>&); 00126 void set_maximum(const unsigned int&, const double&); 00127 00128 void set_means(const Vector<double>&); 00129 void set_mean(const unsigned int&, const double&); 00130 00131 void set_standard_deviations(const Vector<double>&); 00132 void set_standard_deviation(const unsigned int&, const double&); 00133 00134 // Inputs statistics 00135 00136 void set_minimums_maximums(const Vector< Vector<double> >&); 00137 void set_means_standard_deviations(const Vector< Vector<double> >&); 00138 00139 void set_statistics(const Vector< Vector<double> >&); 00140 00141 // Scaling method 00142 00143 void set_scaling_method(const ScalingMethod&); 00144 void set_scaling_method(const std::string&); 00145 00146 // Display messages 00147 00148 void set_display(const bool&); 00149 00150 // Check methods 00151 00152 bool is_empty(void) const; 00153 00154 // Inputs scaling function 00155 00156 void initialize_random(void); 00157 00158 void check_range(const Vector<double>&) const; 00159 00160 Vector<double> calculate_outputs(const Vector<double>&) const; 00161 Vector<double> calculate_derivative(const Vector<double>&) const; 00162 Vector<double> calculate_second_derivative(const Vector<double>&) const; 00163 00164 Vector<double> calculate_minimum_maximum_output(const Vector<double>&) const; 00165 Vector<double> calculate_minimum_maximum_derivative(const Vector<double>&) const; 00166 Vector<double> calculate_minimum_maximum_second_derivative(const Vector<double>&) const; 00167 00168 Vector<double> calculate_mean_standard_deviation_output(const Vector<double>&) const; 00169 Vector<double> calculate_mean_standard_deviation_derivative(const Vector<double>&) const; 00170 Vector<double> calculate_mean_standard_deviation_second_derivative(const Vector<double>&) const; 00171 00172 Matrix<double> arrange_Jacobian(const Vector<double>&) const; 00173 Vector< Matrix<double> > arrange_Hessian_form(const Vector<double>&) const; 00174 00175 // Expression methods 00176 00177 std::string write_minimum_maximum_expression(const Vector<std::string>&, const Vector<std::string>&) const; 00178 00179 std::string write_mean_standard_deviation_expression(const Vector<std::string>&, const Vector<std::string>&) const; 00180 00181 std::string write_expression(const Vector<std::string>&, const Vector<std::string>&) const; 00182 00183 // Serialization methods 00184 00185 std::string to_string(void) const; 00186 00187 TiXmlElement* to_XML(void) const; 00188 virtual void from_XML(TiXmlElement*); 00189 00190 protected: 00191 00192 // MEMBERS 00193 00195 00196 Vector<double> minimums; 00197 00199 00200 Vector<double> maximums; 00201 00203 00204 Vector<double> means; 00205 00207 00208 Vector<double> standard_deviations; 00209 00211 00212 ScalingMethod scaling_method; 00213 00215 00216 bool display; 00217 }; 00218 00219 } 00220 00221 #endif 00222 00223 00224 // OpenNN: Open Neural Networks Library. 00225 // Copyright (C) 2005-2012 Roberto Lopez 00226 // 00227 // This library is free software; you can redistribute it and/or 00228 // modify it under the terms of the GNU Lesser General Public 00229 // License as published by the Free Software Foundation; either 00230 // version 2.1 of the License, or any later version. 00231 // 00232 // This library is distributed in the hope that it will be useful, 00233 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00234 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00235 // Lesser General Public License for more details. 00236 00237 // You should have received a copy of the GNU Lesser General Public 00238 // License along with this library; if not, write to the Free Software 00239 00240 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00241