GSLMinimizer.h

Go to the documentation of this file.
00001 // @(#)root/mathmore:$Id: GSLMinimizer.h 37448 2010-12-09 20:20:56Z moneta $
00002 // Author: L. Moneta Wed Oct 18 11:48:00 2006
00003 
00004  /**********************************************************************
00005   *                                                                    *
00006   * Copyright (c) 2006  LCG ROOT Math Team, CERN/PH-SFT                *
00007   *                                                                    *
00008   * This library is free software; you can redistribute it and/or      *
00009   * modify it under the terms of the GNU General Public License        *
00010   * as published by the Free Software Foundation; either version 2     *
00011   * of the License, or (at your option) any later version.             *
00012   *                                                                    *
00013   * This library is distributed in the hope that it will be useful,    *
00014   * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
00015   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
00016   * General Public License for more details.                           *
00017   *                                                                    *
00018   * You should have received a copy of the GNU General Public License  *
00019   * along with this library (see file COPYING); if not, write          *
00020   * to the Free Software Foundation, Inc., 59 Temple Place, Suite      *
00021   * 330, Boston, MA 02111-1307 USA, or contact the author.             *
00022   *                                                                    *
00023   **********************************************************************/
00024 
00025 
00026 // Header file for class GSLMinimizer
00027 
00028 #ifndef ROOT_Math_GSLMinimizer
00029 #define ROOT_Math_GSLMinimizer
00030 
00031 #ifndef ROOT_Math_Minimizer
00032 #include "Math/Minimizer.h"
00033 #endif
00034 
00035 
00036 #ifndef ROOT_Math_IFunctionfwd
00037 #include "Math/IFunctionfwd.h"
00038 #endif
00039 
00040 #ifndef ROOT_Math_IParamFunctionfwd
00041 #include "Math/IParamFunctionfwd.h"
00042 #endif
00043 
00044 #ifndef ROOT_Math_MinimizerVariable
00045 #include "Math/MinimizerVariable.h"
00046 #endif
00047 
00048 
00049 #include <vector>
00050 #include <map>
00051 #include <string> 
00052 
00053 
00054 
00055 namespace ROOT { 
00056 
00057 namespace Math { 
00058 
00059 
00060    /**
00061       enumeration specifying the types of GSL minimizers
00062       @ingroup MultiMin
00063    */
00064    enum EGSLMinimizerType { 
00065       kConjugateFR, 
00066       kConjugatePR, 
00067       kVectorBFGS, 
00068       kVectorBFGS2, 
00069       kSteepestDescent
00070    };
00071 
00072 
00073    class GSLMultiMinimizer; 
00074 
00075    class MinimTransformFunction;
00076 
00077 
00078 //_____________________________________________________________________________________
00079 /** 
00080    GSLMinimizer class. 
00081    Implementation of the ROOT::Math::Minimizer interface using the GSL multi-dimensional 
00082    minimization algorithms.
00083 
00084    See <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Multidimensional-Minimization.html">GSL doc</A> 
00085    from more info on the GSL minimization algorithms. 
00086 
00087    The class implements the ROOT::Math::Minimizer interface and can be instantiated using the 
00088    ROOT plugin manager (plugin name is "GSLMultiMin"). The varius minimization algorithms 
00089    (conjugatefr, conjugatepr, bfgs, etc..) can be passed as enumerations and also as a string. 
00090    The default algorithm is conjugatefr (Fletcher-Reeves conjugate gradient algorithm).  
00091 
00092    @ingroup MultiMin
00093 */ 
00094 class GSLMinimizer : public ROOT::Math::Minimizer {
00095 
00096 public: 
00097 
00098    /** 
00099       Default constructor
00100    */ 
00101    GSLMinimizer (ROOT::Math::EGSLMinimizerType type = ROOT::Math::kConjugateFR  ); 
00102 
00103    /**
00104       Constructor with a string giving name of algorithm 
00105     */
00106    GSLMinimizer (const char *  type  ); 
00107 
00108    /** 
00109       Destructor 
00110    */ 
00111    virtual ~GSLMinimizer (); 
00112 
00113 private:
00114    // usually copying is non trivial, so we make this unaccessible
00115 
00116    /** 
00117       Copy constructor
00118    */ 
00119    GSLMinimizer(const GSLMinimizer &) : Minimizer() {}
00120 
00121    /** 
00122       Assignment operator
00123    */ 
00124    GSLMinimizer & operator = (const GSLMinimizer & rhs) { 
00125       if (this == &rhs) return *this;  // time saving self-test
00126       return *this;
00127    }
00128 
00129 public: 
00130 
00131    /// set the function to minimize
00132    virtual void SetFunction(const ROOT::Math::IMultiGenFunction & func); 
00133 
00134    /// set gradient the function to minimize
00135    virtual void SetFunction(const ROOT::Math::IMultiGradFunction & func); 
00136 
00137    /// set free variable 
00138    virtual bool SetVariable(unsigned int ivar, const std::string & name, double val, double step); 
00139 
00140 
00141    /// set lower limit variable  (override if minimizer supports them )
00142    virtual bool SetLowerLimitedVariable(unsigned int  ivar , const std::string & name , double val , double step , double lower );
00143    /// set upper limit variable (override if minimizer supports them )
00144    virtual bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper ); 
00145    /// set upper/lower limited variable (override if minimizer supports them )
00146    virtual bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double /* lower */, double /* upper */); 
00147    /// set fixed variable (override if minimizer supports them )
00148    virtual bool SetFixedVariable(unsigned int /* ivar */, const std::string & /* name */, double /* val */);  
00149    /// set the value of an existing variable 
00150    virtual bool SetVariableValue(unsigned int ivar, double val );
00151    /// set the values of all existing variables (array must be dimensioned to the size of existing parameters)
00152    virtual bool SetVariableValues(const double * x);
00153 
00154    /// method to perform the minimization
00155    virtual  bool Minimize(); 
00156 
00157    /// return minimum function value
00158    virtual double MinValue() const { return fMinVal; } 
00159 
00160    /// return expected distance reached from the minimum
00161    virtual double Edm() const { return 0; } // not impl. }
00162 
00163    /// return  pointer to X values at the minimum 
00164    virtual const double *  X() const { return &fValues.front(); } 
00165 
00166    /// return pointer to gradient values at the minimum 
00167    virtual const double *  MinGradient() const; 
00168 
00169    /// number of function calls to reach the minimum 
00170    virtual unsigned int NCalls() const;  
00171 
00172    /// this is <= Function().NDim() which is the total 
00173    /// number of variables (free+ constrained ones) 
00174    virtual unsigned int NDim() const { return fValues.size(); }   
00175 
00176    /// number of free variables (real dimension of the problem) 
00177    /// this is <= Function().NDim() which is the total number of free parameters
00178    virtual unsigned int NFree() const { return fObjFunc->NDim(); }  
00179 
00180    /// minimizer provides error and error matrix
00181    virtual bool ProvidesError() const { return false; } 
00182 
00183    /// return errors at the minimum 
00184    virtual const double * Errors() const { 
00185       return 0;
00186    }
00187 
00188    /** return covariance matrices elements 
00189        if the variable is fixed the matrix is zero
00190        The ordering of the variables is the same as in errors
00191    */ 
00192    virtual double CovMatrix(unsigned int , unsigned int ) const { return 0; }
00193 
00194 
00195    // method of only GSL  minimizer (not inherited from interface)
00196  
00197    /// return pointer to used objective gradient function 
00198    const ROOT::Math::IMultiGradFunction * ObjFunction() const { return fObjFunc; }
00199 
00200    /// return transformation function (NULL if not having a transformation) 
00201    const ROOT::Math::MinimTransformFunction * TransformFunction() const; 
00202 
00203 
00204 protected: 
00205 
00206 private: 
00207    
00208    // dimension of the function to be minimized 
00209    unsigned int fDim; 
00210 
00211    ROOT::Math::GSLMultiMinimizer * fGSLMultiMin; 
00212    const ROOT::Math::IMultiGradFunction * fObjFunc; 
00213    
00214    double fMinVal; 
00215    double fLSTolerance;  // Line Search Tolerance
00216    std::vector<double> fValues;
00217    //mutable std::vector<double> fErrors;
00218    std::vector<double> fSteps;
00219    std::vector<std::string> fNames;
00220    std::vector<ROOT::Math::EMinimVariableType> fVarTypes;  // vector specifyng the type of variables
00221    std::map< unsigned int, std::pair<double, double> > fBounds; // map specifying the bound using as key the parameter index
00222 
00223 }; 
00224 
00225    } // end namespace Fit
00226 
00227 } // end namespace ROOT
00228 
00229 
00230 
00231 #endif /* ROOT_Math_GSLMinimizer */

Generated on Tue Jul 5 14:25:25 2011 for ROOT_528-00b_version by  doxygen 1.5.1