GradientDescent.h

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

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