|
|
|||
Warning, file /include/root/Math/MinimizerOptions.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 // @(#)root/mathcore:$Id$ 0002 // Author: L. Moneta Fri Aug 15 2008 0003 0004 /********************************************************************** 0005 * * 0006 * Copyright (c) 2008 LCG ROOT Math Team, CERN/PH-SFT * 0007 * * 0008 * * 0009 **********************************************************************/ 0010 0011 #ifndef ROOT_Math_MinimizerOptions 0012 #define ROOT_Math_MinimizerOptions 0013 0014 #include <string> 0015 0016 #include <iostream> 0017 0018 namespace ROOT { 0019 0020 0021 namespace Math { 0022 0023 0024 class IOptions; 0025 0026 //_______________________________________________________________________________ 0027 /** 0028 Minimizer options 0029 0030 @ingroup MultiMin 0031 0032 Class defining the options for the minimizer. 0033 It contains also static methods for setting the default Minimizer option values 0034 that will be used by default by all Minimizer instances. 0035 To see the current default options do: 0036 0037 ROOT::Math::MinimizerOptions::PrintDefault(); 0038 0039 @see ROOT::Math::MinimizerOptions::SetDefaultMinimizer 0040 0041 */ 0042 class MinimizerOptions { 0043 0044 public: 0045 0046 // static methods for setting and retrieving the default options 0047 0048 /// Set the default Minimizer type and corresponding algorithms. 0049 /// Here is the list of the available minimizers and their corresponding algorithms. 0050 /// For some minimizers (e.g. Fumili) there are no specific algorithms available, then there is no need to specify it. 0051 /// 0052 /// \anchor ROOTMinimizers 0053 /// ### ROOT Minimizers 0054 /// 0055 /// - Minuit Minimizer based on TMinuit, the legacy Minuit implementation. Here are the available algorithms: 0056 /// - Migrad default algorithm based on the variable metric minimizer 0057 /// - Minimize combination of Simplex and Migrad 0058 /// - Simplex minimization algorithm not using the gradient information 0059 /// - Scan brute function scan 0060 /// - Minuit2 New C++ implementation of Minuit (the recommended one) 0061 /// - Migrad (default) 0062 /// - Minimize 0063 /// - Simplex 0064 /// - Fumili2 new implementation of Fumili integrated in Minuit2 0065 /// - Fumili Minimizer using an approximation for the Hessian based on first derivatives of the model function (see TFumili). Works only for chi-squared and likelihood functions. 0066 /// - Linear Linear minimizer (fitter) working only for linear functions (see TLinearFitter and TLinearMinimizer) 0067 /// - GSLMultiMin Minimizer from GSL based on the ROOT::Math::GSLMinimizer. Available algorithms are: 0068 /// - BFGS2 (default) 0069 /// - BFGS 0070 /// - ConjugateFR 0071 /// - ConjugatePR 0072 /// - SteepestDescent 0073 /// - GSLMultiFit Minimizer based on GSL for minimizing only non linear least-squared functions (using an approximation similar to Fumili). See ROOT::Math::GSLMultiFit. 0074 /// - GSLSimAn Simulated annealing minimizer from GSL (see ROOT::Math::GSLSimAnMinimizer). It is a stochastic minimization algorithm using only function values and not the gradient. 0075 /// - Genetic Genetic minimization algorithms (see TMVA::Genetic and ROOT::Math::GeneticMinimizer) 0076 /// - RMinimizer (class ROOT::Math::RMinimizer) available when ROOT is built with `r` support 0077 /// - BFGS (default) 0078 /// - L-BFGS-S 0079 /// - Nelder-Mead 0080 /// - CG 0081 /// - and more methods, see the Details in the documentation of the function `optimix` of the [optmix R package](https://cran.r-project.org/web/packages/optimx/optimx.pdf) 0082 /// @see ROOT::Math::Minimizer 0083 static void SetDefaultMinimizer(const char *type, const char *algo = nullptr); 0084 0085 /// Set the default level for computing the parameter errors. 0086 /// For example for 1-sigma parameter errors 0087 /// - up = 1 for a chi-squared function 0088 /// - up = 0.5 for a negative log-likelihood function 0089 /// 0090 /// The value will be used also by Minos when computing the confidence interval 0091 static void SetDefaultErrorDef(double up); 0092 0093 /// Set the Minimization tolerance. 0094 /// The Default value for Minuit and Minuit2 is 0.01 0095 static void SetDefaultTolerance(double tol); 0096 0097 /// Set the default Minimizer precision. 0098 /// (used only by MInuit and Minuit2) 0099 /// It is used to specify the numerical precision used for computing the 0100 /// objective function. It should be left to the default value found by the Minimizer 0101 /// (typically double precision) 0102 static void SetDefaultPrecision(double prec); 0103 0104 /// Set the maximum number of function calls. 0105 static void SetDefaultMaxFunctionCalls(int maxcall); 0106 0107 /// Set the maximum number of iterations. 0108 /// Used by the GSL minimizers and Genetic. Not used by Minuit,Minuit2. 0109 static void SetDefaultMaxIterations(int maxiter); 0110 0111 /// Set the default strategy. 0112 /// The strategy is a parameter used only by Minuit and Minuit2. 0113 /// Possible values are: 0114 /// - `strat = 0` : rough approximation of Hessian using the gradient. Avoid computing the full Hessian matrix 0115 /// - `strat = 1` (default and recommended one) - Use Hessian approximation but compute full Hessian at the end of minimization if needed. 0116 /// - `strat = 2` Perform several full Hessian computations during the minimization. Slower and not always working better than `strat=1`. 0117 static void SetDefaultStrategy(int strat); 0118 0119 /// Set the default Print Level. 0120 /// Possible levels are from 0 (minimal printing) to 3 (maximum printing) 0121 static void SetDefaultPrintLevel(int level); 0122 0123 /// Set additional minimizer options as pair of (string,value). 0124 /// Extra option defaults can be configured for a specific algorithm and 0125 /// then if a matching with the correct option name exists it will be used 0126 /// whenever creating a new minimizer instance. 0127 /// For example for changing the default number of steps of the Genetic minimizer from 100 to 500 do 0128 /// 0129 /// auto extraOpt = ROOT::Math::MinimizerOptions::Default("Genetic") 0130 /// extraOpts.SetValue("Steps",500); 0131 /// 0132 /// and when creating the Genetic minimizer you will have the new value for the option: 0133 /// 0134 /// auto gmin = ROOT::Math::Factory::CreateMinimizer("Genetic"); 0135 /// gmin->Options().Print(); 0136 /// 0137 static void SetDefaultExtraOptions(const IOptions * extraoptions); 0138 0139 0140 static const std::string & DefaultMinimizerType(); 0141 static const std::string & DefaultMinimizerAlgo(); 0142 static double DefaultErrorDef(); 0143 static double DefaultTolerance(); 0144 static double DefaultPrecision(); 0145 static int DefaultMaxFunctionCalls(); 0146 static int DefaultMaxIterations(); 0147 static int DefaultStrategy(); 0148 static int DefaultPrintLevel(); 0149 static IOptions * DefaultExtraOptions(); 0150 0151 /// Retrieve extra options for a given minimizer name. 0152 /// If the extra options already exist in a global map of (Minimizer name, options) 0153 /// it will return a reference to that options, otherwise it will create a new one 0154 /// and return the corresponding reference 0155 static ROOT::Math::IOptions & Default(const char * name); 0156 0157 /// Find an extra options and return a nullptr if it is not existing. 0158 /// Same as above but it will not create a new one 0159 static ROOT::Math::IOptions * FindDefault(const char * name); 0160 0161 /// Print all the default options including the extra one specific for a given minimizer name. 0162 /// If no minimizer name is given, all the extra default options, which have been set and configured will be printed 0163 static void PrintDefault(const char * name = nullptr, std::ostream & os = std::cout); 0164 0165 public: 0166 0167 // constructor using the default options 0168 MinimizerOptions(); 0169 0170 // destructor 0171 ~MinimizerOptions(); 0172 0173 // copy constructor 0174 MinimizerOptions(const MinimizerOptions & opt); 0175 0176 /// assignment operators 0177 MinimizerOptions & operator=(const MinimizerOptions & opt); 0178 0179 /** non-static methods for retrieving options */ 0180 0181 /// set print level 0182 int PrintLevel() const { return fLevel; } 0183 0184 /// max number of function calls 0185 unsigned int MaxFunctionCalls() const { return fMaxCalls; } 0186 0187 /// max iterations 0188 unsigned int MaxIterations() const { return fMaxIter; } 0189 0190 /// strategy 0191 int Strategy() const { return fStrategy; } 0192 0193 /// absolute tolerance 0194 double Tolerance() const { return fTolerance; } 0195 0196 /// precision in the objective function calculation (value <=0 means left to default) 0197 double Precision() const { return fPrecision; } 0198 0199 /// error definition 0200 double ErrorDef() const { return fErrorDef; } 0201 0202 /// return extra options (NULL pointer if they are not present) 0203 const IOptions * ExtraOptions() const { return fExtraOptions; } 0204 IOptions * ExtraOptions() { return fExtraOptions; } 0205 0206 /// type of minimizer 0207 const std::string & MinimizerType() const { return fMinimType; } 0208 0209 /// type of algorithm 0210 const std::string & MinimizerAlgorithm() const { return fAlgoType; } 0211 0212 /// print all the options 0213 void Print(std::ostream & os = std::cout) const; 0214 0215 /** non-static methods for setting options */ 0216 void ResetToDefaultOptions(); 0217 0218 /// set print level 0219 void SetPrintLevel(int level) { fLevel = level; } 0220 0221 ///set maximum of function calls 0222 void SetMaxFunctionCalls(unsigned int maxfcn) { fMaxCalls = maxfcn; } 0223 0224 /// set maximum iterations (one iteration can have many function calls) 0225 void SetMaxIterations(unsigned int maxiter) { fMaxIter = maxiter; } 0226 0227 /// set the tolerance 0228 void SetTolerance(double tol) { fTolerance = tol; } 0229 0230 /// set the precision 0231 void SetPrecision(double prec) { fPrecision = prec; } 0232 0233 /// set the strategy 0234 void SetStrategy(int stra) { fStrategy = stra; } 0235 0236 /// set error def 0237 void SetErrorDef(double err) { fErrorDef = err; } 0238 0239 /// set minimizer type 0240 void SetMinimizerType(const char * type) { fMinimType = type; } 0241 0242 /// set minimizer algorithm 0243 void SetMinimizerAlgorithm(const char *type) { fAlgoType = type; } 0244 0245 /// set extra options (in this case pointer is cloned) 0246 void SetExtraOptions(const IOptions & opt); 0247 0248 0249 private: 0250 0251 int fLevel; ///< debug print level 0252 int fMaxCalls; ///< maximum number of function calls 0253 int fMaxIter; ///< maximum number of iterations 0254 int fStrategy; ///< minimizer strategy (used by Minuit) 0255 double fErrorDef; ///< error definition (=1. for getting 1 sigma error for chi2 fits) 0256 double fTolerance; ///< minimize tolerance to reach solution 0257 double fPrecision; ///< precision of the objective function evaluation (value <=0 means left to default) 0258 std::string fMinimType; ///< Minimizer type (Minuit, Minuit2, etc.. 0259 std::string fAlgoType; ///< Minimizer algorithmic specification (Migrad, Minimize, ...) 0260 0261 // extra options 0262 ROOT::Math::IOptions * fExtraOptions; // extra options 0263 0264 }; 0265 0266 } // end namespace Math 0267 0268 } // end namespace ROOT 0269 0270 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|