00001 /****************************************************************************************************************/ 00002 /* */ 00003 /* Flood: An Open Source Neural Networks C++ Library */ 00004 /* www.cimne.com/flood */ 00005 /* */ 00006 /* Q U A S I - N E W T O N M E T H O D 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 __QUASINEWTONMETHOD_H__ 00017 #define __QUASINEWTONMETHOD_H__ 00018 00019 #include "TrainingAlgorithm.h" 00020 #include "../ObjectiveFunctional/ObjectiveFunctional.h" 00021 00022 namespace Flood 00023 { 00024 00027 00028 class QuasiNewtonMethod : public TrainingAlgorithm 00029 { 00030 00031 public: 00032 00033 // ENUMERATIONS 00034 00036 00037 enum InverseHessianApproximationMethod{DFP, BFGS}; 00038 00039 00040 // GENERAL CONSTRUCTOR 00041 00042 explicit QuasiNewtonMethod(ObjectiveFunctional*); 00043 00044 00045 // DEFAULT CONSTRUCTOR 00046 00047 explicit QuasiNewtonMethod(void); 00048 00049 00050 // DESTRUCTOR 00051 00052 virtual ~QuasiNewtonMethod(void); 00053 00054 00055 // METHODS 00056 00057 // Get methods 00058 00059 InverseHessianApproximationMethod get_inverse_Hessian_approximation_method(void); 00060 std::string get_inverse_Hessian_approximation_method_name(void); 00061 00062 // Set methods 00063 00064 void set_inverse_Hessian_approximation_method(const InverseHessianApproximationMethod&); 00065 void set_inverse_Hessian_approximation_method(const std::string&); 00066 00067 // Train methods 00068 00069 Vector<double> calculate_training_direction(const Vector<double>&, const Matrix<double>&); 00070 00071 Matrix<double> calculate_inverse_Hessian_approximation(const Vector<double>&, const Vector<double>&, const Vector<double>&, const Vector<double>&, const Matrix<double>&); 00072 00073 Vector<double> calculate_gradient_descent_training_direction(const Vector<double>&); 00074 00075 void train(void); 00076 00077 // Training history methods 00078 00079 void resize_training_history(int); 00080 00081 void set_reserve_all_training_history(bool); 00082 00083 std::string get_training_history_XML(bool); 00084 00085 // Utility methods 00086 00087 std::string to_XML(bool); 00088 00089 void load(const char*); 00090 00091 00092 private: 00093 00094 // FIELDS 00095 00097 00098 InverseHessianApproximationMethod inverse_Hessian_approximation_method; 00099 00100 }; 00101 00102 } 00103 00104 #endif 00105 00106 00107 // Flood: An Open Source Neural Networks C++ Library. 00108 // Copyright (C) 2005-2010 Roberto Lopez 00109 // 00110 // This library is free software; you can redistribute it and/or 00111 // modify it under the s of the GNU Lesser General Public 00112 // License as published by the Free Software Foundation; either 00113 // version 2.1 of the License, or any later version. 00114 // 00115 // This library is distributed in the hope that it will be useful, 00116 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00117 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00118 // Lesser General Public License for more details. 00119 00120 // You should have received a copy of the GNU Lesser General Public 00121 // License along with this library; if not, write to the Free Software 00122 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA