GSLSimAnMinimizer.h

Go to the documentation of this file.
00001 // @(#)root/mathmore:$Id: GSLSimAnMinimizer.h 32583 2010-03-12 09:57:42Z moneta $
00002 // Author: L. Moneta Wed Dec 20 17:16:32 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 // Header file for class GSLSimAnMinimizer
00026 
00027 #ifndef ROOT_Math_GSLSimAnMinimizer
00028 #define ROOT_Math_GSLSimAnMinimizer
00029 
00030 
00031 
00032 #ifndef ROOT_Math_Minimizer
00033 #include "Math/Minimizer.h"
00034 #endif
00035 
00036 
00037 #ifndef ROOT_Math_IFunctionfwd
00038 #include "Math/IFunctionfwd.h"
00039 #endif
00040 
00041 #ifndef ROOT_Math_IParamFunctionfwd
00042 #include "Math/IParamFunctionfwd.h"
00043 #endif
00044 
00045 
00046 
00047 #ifndef ROOT_Math_GSLSimAnnealing
00048 #include "Math/GSLSimAnnealing.h"
00049 #endif
00050 
00051 #ifndef ROOT_Math_MinimizerVariable
00052 #include "Math/MinimizerVariable.h"
00053 #endif
00054 
00055 #include <vector>
00056 #include <map>
00057 
00058 
00059 
00060 namespace ROOT { 
00061 
00062    namespace Math { 
00063 
00064       class  MinimTransformFunction;
00065 
00066 
00067 //_____________________________________________________________________________________
00068 /** 
00069    GSLSimAnMinimizer class for minimization using simulated annealing
00070    using the algorithm from 
00071    <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Simulated-Annealing.html">
00072    GSL</A>.
00073    It implements the ROOT::Minimizer interface and 
00074    a plug-in (name "GSLSimAn") exists to instantiate this class via the plug-in manager
00075 
00076    @ingroup MultiMin
00077 */ 
00078 class GSLSimAnMinimizer : public  ROOT::Math::Minimizer {
00079 
00080 public: 
00081 
00082    /** 
00083       Default constructor
00084    */ 
00085    GSLSimAnMinimizer (int type = 0); 
00086 
00087    /** 
00088       Destructor (no operations)
00089    */ 
00090    ~GSLSimAnMinimizer ();  
00091 
00092 private:
00093    // usually copying is non trivial, so we make this unaccessible
00094 
00095    /** 
00096       Copy constructor
00097    */ 
00098    GSLSimAnMinimizer(const GSLSimAnMinimizer &) : ROOT::Math::Minimizer() {} 
00099 
00100    /** 
00101       Assignment operator
00102    */ 
00103    GSLSimAnMinimizer & operator = (const GSLSimAnMinimizer & rhs)  {
00104       if (this == &rhs) return *this;  // time saving self-test
00105       return *this;
00106    }
00107 
00108 public: 
00109 
00110    /// set the function to minimize
00111    virtual void SetFunction(const ROOT::Math::IMultiGenFunction & func); 
00112 
00113    /// set gradient the function to minimize
00114    virtual void SetFunction(const ROOT::Math::IMultiGradFunction & func); 
00115 
00116    /// set free variable 
00117    virtual bool SetVariable(unsigned int ivar, const std::string & name, double val, double step); 
00118 
00119    /// set fixed variable (override if minimizer supports them )
00120    virtual bool SetFixedVariable(unsigned int /* ivar */, const std::string & /* name */, double /* val */);  
00121 
00122    /// set lower limit variable  (override if minimizer supports them )
00123    virtual bool SetLowerLimitedVariable(unsigned int  ivar , const std::string & name , double val , double step , double lower );
00124    /// set upper limit variable (override if minimizer supports them )
00125    virtual bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper ); 
00126    /// set upper/lower limited variable (override if minimizer supports them )
00127    virtual bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double /* lower */, double /* upper */); 
00128 
00129    /// set the value of an existing variable 
00130    virtual bool SetVariableValue(unsigned int ivar, double val );
00131    /// set the values of all existing variables (array must be dimensioned to the size of the existing parameters)
00132    virtual bool SetVariableValues(const double * x);
00133 
00134 
00135    /// method to perform the minimization
00136    virtual  bool Minimize(); 
00137 
00138    /// return minimum function value
00139    virtual double MinValue() const { return fMinVal; } 
00140 
00141    /// return expected distance reached from the minimum
00142    virtual double Edm() const { return 0; } // not impl. }
00143 
00144    /// return  pointer to X values at the minimum 
00145    virtual const double *  X() const { return &fValues.front(); } 
00146 
00147    /// return pointer to gradient values at the minimum 
00148    virtual const double *  MinGradient() const { return 0; } // not impl.  
00149 
00150    /// number of function calls to reach the minimum 
00151    virtual unsigned int NCalls() const { return 0; } // not yet ipl.  
00152 
00153    /// this is <= Function().NDim() which is the total 
00154    /// number of variables (free+ constrained ones) 
00155    virtual unsigned int NDim() const { return fDim; }   
00156 
00157    /// number of free variables (real dimension of the problem) 
00158    /// this is <= Function().NDim() which is the total 
00159    virtual unsigned int NFree() const { return fDim; }  
00160 
00161    /// minimizer provides error and error matrix
00162    virtual bool ProvidesError() const { return false; } 
00163 
00164    /// return errors at the minimum 
00165    virtual const double * Errors() const { return 0; }
00166 
00167    /** return covariance matrices elements 
00168        if the variable is fixed the matrix is zero
00169        The ordering of the variables is the same as in errors
00170    */ 
00171    virtual double CovMatrix(unsigned int , unsigned int ) const { return 0; }
00172 
00173 
00174    /// return reference to the objective function
00175    ///virtual const ROOT::Math::IGenFunction & Function() const; 
00176 
00177 
00178 protected: 
00179 
00180 private: 
00181    
00182    unsigned int fDim;     // dimension of the function to be minimized 
00183    bool fOwnFunc;        // flag to indicate if objective function is managed 
00184 
00185    ROOT::Math::GSLSimAnnealing  fSolver; 
00186    const ROOT::Math::IMultiGenFunction * fObjFunc; 
00187    
00188    double fMinVal;                    // minimum values 
00189 
00190    mutable std::vector<double> fValues;
00191 
00192    std::vector<double> fSteps;
00193    std::vector<std::string> fNames;
00194    std::vector<ROOT::Math::EMinimVariableType> fVarTypes;  // vector specifyng the type of variables
00195    std::map< unsigned int, std::pair<double, double> > fBounds; // map specifying the bound using as key the parameter index
00196 
00197 }; 
00198 
00199    } // end namespace Math
00200 
00201 } // end namespace ROOT
00202 
00203 
00204 #endif /* ROOT_Math_GSLSimAnMinimizer */

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