Minuit2Minimizer.h

Go to the documentation of this file.
00001 // @(#)root/minuit2:$Id$
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  *                                                                    *
00009  **********************************************************************/
00010 
00011 // Header file for class Minuit2Minimizer
00012 
00013 #ifndef ROOT_Minuit2_Minuit2Minimizer
00014 #define ROOT_Minuit2_Minuit2Minimizer
00015 
00016 #ifndef ROOT_Math_Minimizer
00017 #include "Math/Minimizer.h"
00018 #endif
00019 
00020 #ifndef ROOT_Minuit2_MnUserParameterState
00021 #include "Minuit2/MnUserParameterState.h"
00022 #endif
00023 
00024 #ifndef ROOT_Math_IFunctionfwd
00025 #include "Math/IFunctionfwd.h"
00026 #endif
00027 
00028 #ifndef ROOT_Math_IParamFunctionfwd
00029 #include "Math/IParamFunctionfwd.h"
00030 #endif
00031 
00032 
00033 
00034 
00035 
00036 namespace ROOT { 
00037 
00038    namespace Minuit2 { 
00039 
00040       class ModularFunctionMinimizer; 
00041       class FCNBase; 
00042       class FunctionMinimum;
00043 
00044       // enumeration specifying the type of Minuit2 minimizers
00045       enum EMinimizerType { 
00046          kMigrad, 
00047          kSimplex, 
00048          kCombined, 
00049          kScan,
00050          kFumili
00051       };
00052 
00053    }
00054 
00055    namespace Minuit2 { 
00056 //_____________________________________________________________________________________________________
00057 /** 
00058    Minuit2Minimizer class implementing the ROOT::Math::Minimizer interface for 
00059    Minuit2 minimization algorithm. 
00060    In ROOT it can be instantiated using the plug-in manager (plug-in "Minuit2")
00061    Using a string  (used by the plugin manager) or via an enumeration 
00062    an one can set all the possible minimization algorithms (Migrad, Simplex, Combined, Scan and Fumili).  
00063 */ 
00064 class Minuit2Minimizer : public ROOT::Math::Minimizer {
00065 
00066 public: 
00067 
00068    /** 
00069       Default constructor
00070    */ 
00071    Minuit2Minimizer (ROOT::Minuit2::EMinimizerType type = ROOT::Minuit2::kMigrad); 
00072 
00073    /** 
00074       Constructor with a char (used by PM) 
00075    */ 
00076    Minuit2Minimizer (const char *  type); 
00077 
00078    /** 
00079       Destructor (no operations)
00080    */ 
00081    virtual ~Minuit2Minimizer (); 
00082 
00083 private:
00084    // usually copying is non trivial, so we make this unaccessible
00085 
00086    /** 
00087       Copy constructor
00088    */ 
00089    Minuit2Minimizer(const Minuit2Minimizer &); 
00090 
00091    /** 
00092       Assignment operator
00093    */ 
00094    Minuit2Minimizer & operator = (const Minuit2Minimizer & rhs); 
00095 
00096 public: 
00097 
00098    // clear resources (parameters) for consecutives minimizations
00099    virtual void Clear();
00100 
00101    /// set the function to minimize
00102    virtual void SetFunction(const ROOT::Math::IMultiGenFunction & func); 
00103 
00104    /// set gradient the function to minimize
00105    virtual void SetFunction(const ROOT::Math::IMultiGradFunction & func); 
00106 
00107    /// set free variable 
00108    virtual bool SetVariable(unsigned int ivar, const std::string & name, double val, double step); 
00109 
00110    /// set lower limit variable  (override if minimizer supports them )
00111    virtual bool SetLowerLimitedVariable(unsigned int  ivar , const std::string & name , double val , double step , double lower );
00112    /// set upper limit variable (override if minimizer supports them )
00113    virtual bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper ); 
00114    /// set upper/lower limited variable (override if minimizer supports them )
00115    virtual bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double /* lower */, double /* upper */); 
00116    /// set fixed variable (override if minimizer supports them )
00117    virtual bool SetFixedVariable(unsigned int /* ivar */, const std::string & /* name */, double /* val */);  
00118    /// set variable
00119    virtual bool SetVariableValue(unsigned int ivar, double val);
00120    virtual bool SetVariableValues(const double * val);
00121 
00122    /// get name of variables (override if minimizer support storing of variable names)
00123    virtual std::string VariableName(unsigned int ivar) const;
00124 
00125    /// get index of variable given a variable given a name
00126    /// return -1 if variable is not found
00127    virtual int VariableIndex(const std::string & name) const;
00128 
00129    /** 
00130        method to perform the minimization. 
00131        Return false in case the minimization did not converge. In this case a 
00132        status code different than zero is set 
00133        (retrieved by the derived method Minimizer::Status() )" 
00134        
00135        status = 1    : Covariance was made pos defined
00136        status = 2    : Hesse is invalid
00137        status = 3    : Edm is above max 
00138        status = 4    : Reached call limit
00139        status = 5    : Any other failure 
00140    */
00141    virtual  bool Minimize(); 
00142 
00143    /// return minimum function value
00144    virtual double MinValue() const { return fState.Fval(); } 
00145 
00146    /// return expected distance reached from the minimum
00147    virtual double Edm() const { return fState.Edm(); }
00148 
00149    /// return  pointer to X values at the minimum 
00150    virtual const double *  X() const { 
00151       fValues = fState.Params(); 
00152       return (fValues.size() ) ? &fValues.front() : 0; 
00153    }
00154 
00155    /// return pointer to gradient values at the minimum 
00156    virtual const double *  MinGradient() const { return 0; } // not available in Minuit2 
00157 
00158    /// number of function calls to reach the minimum 
00159    virtual unsigned int NCalls() const { return fState.NFcn(); } 
00160 
00161    /// this is <= Function().NDim() which is the total 
00162    /// number of variables (free+ constrained ones) 
00163    virtual unsigned int NDim() const { return fDim; }   
00164 
00165    /// number of free variables (real dimension of the problem) 
00166    /// this is <= Function().NDim() which is the total 
00167    virtual unsigned int NFree() const { return fState.VariableParameters(); }  
00168 
00169    /// minimizer provides error and error matrix
00170    virtual bool ProvidesError() const { return true; } 
00171 
00172    /// return errors at the minimum 
00173    virtual const double * Errors() const; 
00174 
00175    /** 
00176        return covariance matrices elements 
00177        if the variable is fixed or const the value is zero
00178        The ordering of the variables is the same as in errors and parameter value. 
00179        This is different from the direct interface of Minuit2 or TMinuit where the 
00180        values were obtained only to variable parameters
00181    */ 
00182    virtual double CovMatrix(unsigned int i, unsigned int j) const;  
00183 
00184    /**
00185       return the status of the covariance matrix 
00186     */
00187    virtual int CovMatrixStatus() const;
00188    /**
00189       return correlation coefficient between variable i and j.
00190       If the variable is fixed or const the return value is zero
00191     */
00192    virtual double Correlation(unsigned int i, unsigned int j ) const; 
00193 
00194    /**
00195       get global correlation coefficient for the variable i. This is a number between zero and one which gives 
00196       the correlation between the i-th variable  and that linear combination of all other variables which 
00197       is most strongly correlated with i.
00198       If the variable is fixed or const the return value is zero
00199     */
00200    virtual double GlobalCC(unsigned int i) const;
00201 
00202    /**
00203       get the minos error for parameter i, return false if Minos failed
00204       A minimizaiton must be performed befre, return false if no minimization has been done
00205       In case of Minos failed the status error is updated as following 
00206       status += 10 * minosStatus where the minos status is:
00207        status = 1    : maximum number of function calls exceeded when running for lower error
00208        status = 2    : maximum number of function calls exceeded when running for upper error
00209        status = 3    : new minimum found when running for lower error
00210        status = 4    : new minimum found when running for upper error
00211        status = 5    : any other failure 
00212 
00213    */
00214    virtual bool GetMinosError(unsigned int i, double & errLow, double & errUp, int = 0); 
00215 
00216    /**
00217       scan a parameter i around the minimum. A minimization must have been done before, 
00218       return false if it is not the case
00219     */
00220    virtual bool Scan(unsigned int i, unsigned int & nstep, double * x, double * y, double xmin = 0, double xmax = 0); 
00221 
00222    /**
00223       find the contour points (xi,xj) of the function for parameter i and j around the minimum
00224       The contour will be find for value of the function = Min + ErrorUp();
00225     */
00226    virtual bool Contour(unsigned int i, unsigned int j, unsigned int & npoints, double *xi, double *xj); 
00227 
00228    
00229    /**
00230       perform a full calculation of the Hessian matrix for error calculation
00231       If a valid minimum exists the calculation is done on the minimum point otherwise is performed 
00232       in the current set values of parameters
00233       Status code of minimizer is updated according to the following convention (in case Hesse failed)
00234       status += 100*hesseStatus where hesse status is: 
00235       status = 1 : hesse failed
00236       status = 2 : matrix inversion failed
00237       status = 3 : matrix is not pos defined 
00238     */
00239    virtual bool Hesse();
00240 
00241 
00242    /// return reference to the objective function
00243    ///virtual const ROOT::Math::IGenFunction & Function() const; 
00244 
00245    /// print result of minimization
00246    virtual void PrintResults(); 
00247 
00248 protected: 
00249    
00250    // protected function for accessing the internal Minuit2 object. Needed for derived classes
00251 
00252    virtual const ROOT::Minuit2::ModularFunctionMinimizer * GetMinimizer() const { return fMinimizer; } 
00253 
00254    virtual void SetMinimizer( ROOT::Minuit2::ModularFunctionMinimizer * m)  { fMinimizer = m; } 
00255 
00256    void SetMinimizerType( ROOT::Minuit2::EMinimizerType type);
00257 
00258    virtual const  ROOT::Minuit2::FCNBase * GetFCN() const { return fMinuitFCN; } 
00259 
00260    /// examine the minimum result 
00261    bool ExamineMinimum(const ROOT::Minuit2::FunctionMinimum & min); 
00262 
00263 private: 
00264    
00265    unsigned int fDim;       // dimension of the function to be minimized 
00266    bool fUseFumili;     
00267 
00268    ROOT::Minuit2::MnUserParameterState fState;
00269    // std::vector<ROOT::Minuit2::MinosError> fMinosErrors;
00270    ROOT::Minuit2::ModularFunctionMinimizer * fMinimizer;
00271    ROOT::Minuit2::FCNBase * fMinuitFCN;
00272    ROOT::Minuit2::FunctionMinimum * fMinimum;
00273    mutable std::vector<double> fValues;
00274    mutable std::vector<double> fErrors;
00275 
00276 }; 
00277 
00278    } // end namespace Fit
00279 
00280 } // end namespace ROOT
00281 
00282 
00283 
00284 #endif /* ROOT_Minuit2_Minuit2Minimizer */

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