00001 /****************************************************************************************************************/ 00002 /* */ 00003 /* Flood: An Open Source Neural Networks C++ Library */ 00004 /* www.cimne.com/flood */ 00005 /* */ 00006 /* S U M S Q U A R E D E R R O 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 __SUMSQUAREDERROR_H__ 00017 #define __SUMSQUAREDERROR_H__ 00018 00019 #include "ObjectiveFunctional.h" 00020 #include "../Utilities/InputTargetDataSet.h" 00021 00022 namespace Flood 00023 { 00024 00028 00029 class SumSquaredError : public ObjectiveFunctional 00030 { 00031 00032 public: 00033 00034 // DEFAULT CONSTRUCTOR 00035 00036 explicit SumSquaredError(void); 00037 00038 // MULTILAYER PERCEPTRON CONSTRUCTOR 00039 00040 explicit SumSquaredError(MultilayerPerceptron*); 00041 00042 // INPUT-TARGET DATA SET CONSTRUCTOR 00043 00044 explicit SumSquaredError(InputTargetDataSet*); 00045 00046 // MULTILAYER PERCEPTRON AND INPUT-TARGET DATA SET CONSTRUCTOR 00047 00048 explicit SumSquaredError(MultilayerPerceptron*, InputTargetDataSet*); 00049 00050 // DESTRUCTOR 00051 00052 virtual ~SumSquaredError(void); // METHODS 00053 00054 // Get methods 00055 00058 00059 inline InputTargetDataSet* get_input_target_data_set_pointer(void) 00060 { 00061 return(input_target_data_set_pointer); 00062 } 00063 00064 // Set methods 00065 00066 void set(void); 00067 void set(MultilayerPerceptron*); 00068 void set(InputTargetDataSet*); 00069 void set(MultilayerPerceptron*, InputTargetDataSet*); 00070 00071 void set_input_target_data_set_pointer(InputTargetDataSet*); 00072 00073 // Evaluation methods 00074 00075 double calculate_objective(void); 00076 00077 Vector<double> calculate_squared_errors(void); 00078 00079 // Gradient methods 00080 00081 Vector<double> calculate_output_errors(const Vector< Vector<double> >&, const Vector<double>&); 00082 Vector< Vector<double> > calculate_hidden_errors(const Vector< Vector<double> >&, const Vector<double>&); 00083 Vector<double> calculate_hidden_layers_error_gradient(const Vector<double>&, const Vector< Vector<double> >&, const Vector< Vector<double> >&); 00084 Vector<double> calculate_output_layer_error_gradient(const Vector< Vector<double> >&, const Vector<double>&); 00085 00086 Vector<double> calculate_objective_gradient(void); 00087 00088 // Jacobian methods 00089 00090 Matrix<double> calculate_Jacobian(void); 00091 00092 Matrix<double> calculate_Jacobian_numerical_differentiation(void); 00093 00094 Matrix<double> calculate_Jacobian_forward_differences(void); 00095 Matrix<double> calculate_Jacobian_central_differences(void); 00096 00097 // Validation error methods 00098 00099 double calculate_validation_error(void); 00100 00101 private: 00102 00103 // MEMBERS 00104 00106 00107 InputTargetDataSet* input_target_data_set_pointer; 00108 }; 00109 00110 } 00111 00112 #endif 00113 00114 00115 // Flood: An Open Source Neural Networks C++ Library. 00116 // Copyright (C) 2005-2010 Roberto Lopez 00117 // 00118 // This library is free software; you can redistribute it and/or 00119 // modify it under the s of the GNU Lesser General Public 00120 // License as published by the Free Software Foundation; either 00121 // version 2.1 of the License, or any later version. 00122 // 00123 // This library is distributed in the hope that it will be useful, 00124 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00125 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00126 // Lesser General Public License for more details. 00127 00128 // You should have received a copy of the GNU Lesser General Public 00129 // License along with this library; if not, write to the Free Software 00130 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA