ConjugateGradient.h

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*   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            */
00004 /*                                                                            */
00005 /*   Roberto Lopez                                                            */
00006 /*   International Center for Numerical Methods in Engineering (CIMNE)        */
00007 /*   Technical University of Catalonia (UPC)                                  */
00008 /*   Barcelona, Spain                                                         */
00009 /*   E-mail: rlopez@cimne.upc.edu                                             */
00010 /*                                                                            */
00011 /******************************************************************************/
00012 
00013 #ifndef __CONJUGATEGRADIENT_H__
00014 #define __CONJUGATEGRADIENT_H__
00015 
00016 #include "OptimizationAlgorithm.h"
00017 #include "../ObjectiveFunction/ObjectiveFunction.h"
00018 
00019 namespace Purple
00020 {
00021 
00022 /// This concrete class represents a conjugate gradient optimization algorithm
00023 /// for an objective function.
00024 ///
00025 /// @see ObjectiveFunction.
00026 /// @see OptimizationAlgorithm.
00027 
00028 class ConjugateGradient : public OptimizationAlgorithm
00029 {
00030 
00031 public:
00032 
00033    // ENUMERATIONS
00034 
00035    /// Enumeration of the available optimization operators for the 
00036    /// search direction.
00037 
00038    enum SearchDirectionMethod{PolakRibiere, FletcherReeves};
00039 
00040    /// Enumeration of the available optimization operators for the optimal
00041    /// step sizes.
00042 
00043    enum OptimalStepSizeMethod{GoldenSection, BrentMethod};
00044 
00045 private: 
00046 
00047    // FIELDS
00048 
00049    /// Initial argument
00050 
00051    Vector<double> initialArgument;
00052 
00053    /// Objective function gradient norm goal.
00054    /// It is used as a stopping criterion.
00055 
00056    double gradientNormGoal;
00057 
00058    /// Maximum number of iterations.
00059    /// It is used as an optimization stopping criterion.
00060 
00061    int maximumNumberOfIterations;
00062 
00063    /// Number of iterations between the optimization showing progress.
00064 
00065    int showPeriod;
00066 
00067    /// Initial step size in line minimization.
00068 
00069    double firstStepSize;
00070 
00071    /// Tolerance in optimal step size.
00072 
00073    double optimalStepSizeTolerance;
00074 
00075    /// Step size at wich a warning message is written to the screen during line
00076    /// minimization.
00077 
00078    double warningStepSize;
00079 
00080    /// Evaluation history.
00081 
00082    Vector<double> evaluationHistory;
00083 
00084    /// Norm of objective function gradient history.
00085 
00086    Vector<double> gradientNormHistory;
00087 
00088    // METHODS
00089 
00090    // Search direction methods
00091 
00092    double getPolakRibiereParameter(Vector<double>, Vector<double>);
00093    double getFletcherReevesParameter(Vector<double>, Vector<double>);
00094 
00095    Vector<double>
00096    getFletcherReevesSearchDirection(Vector<double>, Vector<double>, Vector<double>);
00097 
00098    Vector<double>
00099    getPolakRibiereSearchDirection(Vector<double>, Vector<double>, Vector<double>);
00100 
00101    // Optimal step size methods
00102 
00103    double getGoldenSectionOptimalStepSize
00104    (double, double, Vector<double>, Vector<double>);
00105    
00106    double getBrentMethodOptimalStepSize
00107    (double, double, Vector<double>, Vector<double>);
00108 
00109    // Search direction optimization operators enumeration.
00110 
00111    SearchDirectionMethod searchDirectionMethod;
00112 
00113    // Optimal step size optimization operators enumeration.
00114 
00115    OptimalStepSizeMethod optimalStepSizeMethod;
00116 
00117    // Utility methods
00118 
00119    double getMinimum(Vector<double>);
00120    double getMaximum(Vector<double>);
00121 
00122 
00123 public:
00124 
00125    // GENERAL CONSTRUCTOR
00126 
00127    ConjugateGradient(ObjectiveFunction*);
00128 
00129 
00130    // DEFAULT CONSTRUCTOR
00131 
00132    ConjugateGradient(void); 
00133 
00134 
00135    // DESTRUCTOR
00136 
00137    virtual ~ConjugateGradient(void);
00138 
00139 
00140    // METHODS
00141 
00142    // Get methods
00143 
00144    SearchDirectionMethod getSearchDirectionMethod(void);
00145    OptimalStepSizeMethod getOptimalStepSizeMethod(void);
00146    Vector<double> getInitialArgument(void);
00147    double getGradientNormGoal(void);
00148    int getMaximumNumberOfIterations(void);
00149    int getShowPeriod(void);
00150    double getFirstStepSize(void);
00151    double getOptimalStepSizeTolerance(void);
00152    double getWarningStepSize(void);
00153 
00154    // Set methods
00155 
00156    void setSearchDirectionMethod(SearchDirectionMethod);
00157    void setOptimalStepSizeMethod(OptimalStepSizeMethod);
00158    void setFirstStepSize(double);
00159    void setOptimalStepSizeTolerance(double);
00160    void setInitialArgument(Vector<double>);
00161    void setGradientNormGoal(double);
00162    void setMaximumNumberOfIterations(int);
00163    void setShowPeriod(int);
00164    void setWarningStepSize(double);
00165 
00166    // Optimization methods
00167 
00168    Vector<double> getMinimalArgument(void);
00169 
00170    // Utility methods
00171 
00172    void print(void);    
00173 
00174    void load(char*);
00175    void save(char*);
00176 
00177    void saveOptimizationHistory(char*);
00178 };
00179 
00180 }
00181 
00182 #endif
00183 
00184 
00185 // Purple: An Open Source Numerical Optimization C++ Library.
00186 // Copyright (C) 2005 Roberto Lopez 
00187 //
00188 // This library is free software; you can redistribute it and/or
00189 // modify it under the terms of the GNU Lesser General Public
00190 // License as published by the Free Software Foundation; either
00191 // version 2.1 of the License, or any later version.
00192 //
00193 // This library is distributed in the hope that it will be useful,
00194 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00195 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00196 // Lesser General Public License for more details.
00197 
00198 // You should have received a copy of the GNU Lesser General Public
00199 // License along with this library; if not, write to the Free Software
00200 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

Generated on Wed Jun 21 13:10:37 2006 for Purple by  doxygen 1.4.7