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