00001 /****************************************************************************************************************/ 00002 /* */ 00003 /* OpenNN: Open Neural Networks Library */ 00004 /* www.opennn.cimne.com */ 00005 /* */ 00006 /* 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 */ 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 __UNSCALINGLAYER_H__ 00017 #define __UNSCALINGLAYER_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 00033 namespace OpenNN 00034 { 00035 00039 00040 class UnscalingLayer 00041 { 00042 00043 public: 00044 00045 // DEFAULT CONSTRUCTOR 00046 00047 explicit UnscalingLayer(void); 00048 00049 // UNSCALING NEURONS NUMBER CONSTRUCTOR 00050 00051 explicit UnscalingLayer(const unsigned int&); 00052 00053 // STATISTICS CONSTRUCTOR 00054 00055 explicit UnscalingLayer(const Vector< Vector<double> >&); 00056 00057 // XML CONSTRUCTOR 00058 00059 explicit UnscalingLayer(TiXmlElement*); 00060 00061 // COPY CONSTRUCTOR 00062 00063 UnscalingLayer(const UnscalingLayer&); 00064 00065 // DESTRUCTOR 00066 00067 virtual ~UnscalingLayer(void); 00068 00069 // ASSIGNMENT OPERATOR 00070 00071 UnscalingLayer& operator = (const UnscalingLayer&); 00072 00073 // EQUAL TO OPERATOR 00074 00075 bool operator == (const UnscalingLayer&) const; 00076 00077 // ENUMERATIONS 00078 00080 00081 enum UnscalingMethod{MinimumMaximum, MeanStandardDeviation}; 00082 00083 // GET METHODS 00084 00085 // Outputs number 00086 00087 unsigned int count_unscaling_neurons_number(void) const; 00088 00089 // Output variables statistics 00090 00091 const Vector<double>& get_minimums(void) const; 00092 const double& get_minimum(const unsigned int&) const; 00093 00094 const Vector<double>& get_maximums(void) const; 00095 const double& get_maximum(const unsigned int&) const; 00096 00097 const Vector<double>& get_means(void) const; 00098 const double& get_mean(const unsigned int&) const; 00099 00100 const Vector<double>& get_standard_deviations(void) const; 00101 const double& get_standard_deviation(const unsigned int&) const; 00102 00103 Vector< Vector<double>* > get_minimums_maximums(void); 00104 Vector< Vector<double>* > get_means_standard_deviations(void); 00105 00106 Vector< Vector<double>* > get_statistics(void); 00107 00108 // Outputs unscaling method 00109 00110 const UnscalingMethod& get_unscaling_method(void) const; 00111 00112 std::string write_unscaling_method(void) const; 00113 00114 // Display messages 00115 00116 const bool& get_display(void) const; 00117 00118 // SET METHODS 00119 00120 void set(void); 00121 void set(const unsigned int&); 00122 void set(const Vector< Vector<double> >&); 00123 void set(TiXmlElement*); 00124 void set(const UnscalingLayer&); 00125 00126 virtual void set_default(void); 00127 00128 // Output variables statistics 00129 00130 void set_minimums(const Vector<double>&); 00131 void set_minimum(const unsigned int&, const double&); 00132 00133 void set_maximums(const Vector<double>&); 00134 void set_maximum(const unsigned int&, const double&); 00135 00136 void set_means(const Vector<double>&); 00137 void set_mean(const unsigned int&, const double&); 00138 00139 void set_standard_deviations(const Vector<double>&); 00140 void set_standard_deviation(const unsigned int&, const double&); 00141 00142 void set_minimums_maximums(const Vector< Vector<double> >&); 00143 void set_means_standard_deviations(const Vector< Vector<double> >&); 00144 00145 void set_statistics(const Vector< Vector<double> >&); 00146 00147 // Outputs unscaling method 00148 00149 void set_unscaling_method(const UnscalingMethod&); 00150 void set_unscaling_method(const std::string&); 00151 00152 // Display messages 00153 00154 void set_display(const bool&); 00155 00156 bool is_empty(void) const; 00157 00158 // UnscalingLayer and unscaling 00159 00160 void initialize_random(void); 00161 00162 Vector<double> calculate_outputs(const Vector<double>&) const; 00163 Vector<double> calculate_derivative(const Vector<double>&) const; 00164 Vector<double> calculate_second_derivative(const Vector<double>&) const; 00165 00166 Vector<double> calculate_minimum_maximum_output(const Vector<double>&) const; 00167 Vector<double> calculate_minimum_maximum_derivative(const Vector<double>&) const; 00168 Vector<double> calculate_minimum_maximum_second_derivative(const Vector<double>&) const; 00169 00170 Vector<double> calculate_mean_standard_deviation_output(const Vector<double>&) const; 00171 Vector<double> calculate_mean_standard_deviation_derivative(const Vector<double>&) const; 00172 Vector<double> calculate_mean_standard_deviation_second_derivative(const Vector<double>&) const; 00173 00174 Matrix<double> arrange_Jacobian(const Vector<double>&) const; 00175 Vector< Matrix<double> > arrange_Hessian_form(const Vector<double>&) const; 00176 00177 void check_range(const Vector<double>&) const; 00178 00179 // Serialization methods 00180 00181 std::string to_string(void) const; 00182 00183 virtual TiXmlElement* to_XML(void) const; 00184 virtual void from_XML(TiXmlElement*); 00185 00186 // Expression methods 00187 00188 std::string write_minimum_maximum_expression(const Vector<std::string>&, const Vector<std::string>&) const; 00189 std::string write_mean_stadard_deviation_expression(const Vector<std::string>&, const Vector<std::string>&) const; 00190 00191 std::string write_expression(const Vector<std::string>&, const Vector<std::string>&) const; 00192 00193 protected: 00194 00195 // MEMBERS 00196 00198 00199 Vector<double> minimums; 00200 00202 00203 Vector<double> maximums; 00204 00206 00207 Vector<double> means; 00208 00210 00211 Vector<double> standard_deviations; 00212 00214 00215 UnscalingMethod unscaling_method; 00216 00218 00219 bool display; 00220 }; 00221 00222 } 00223 00224 #endif 00225 00226 00227 // OpenNN: Open Neural Networks Library. 00228 // Copyright (C) 2005-2012 Roberto Lopez 00229 // 00230 // This library is free software; you can redistribute it and/or 00231 // modify it under the terms of the GNU Lesser General Public 00232 // License as published by the Free Software Foundation; either 00233 // version 2.1 of the License, or any later version. 00234 // 00235 // This library is distributed in the hope that it will be useful, 00236 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00237 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00238 // Lesser General Public License for more details. 00239 00240 // You should have received a copy of the GNU Lesser General Public 00241 // License along with this library; if not, write to the Free Software 00242 00243 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00244