Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
MinimizerOptions.h
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Author: L. Moneta Fri Aug 15 2008
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2008 LCG ROOT Math Team, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11#ifndef ROOT_Math_MinimizerOptions
12#define ROOT_Math_MinimizerOptions
13
14#include <string>
15
16#include <iostream>
17
18namespace ROOT {
19
20
21namespace Math {
22
23
24class IOptions;
25
26//_______________________________________________________________________________
27/**
28 Minimizer options
29
30 @ingroup MultiMin
31
32 Class defining the options for the minimizer.
33 It contains also static methods for setting the default Minimizer option values
34 that will be used by default by all Minimizer instances.
35 To see the current default options do:
36
37 ROOT::Math::MinimizerOptions::PrintDefault();
38
39 @see ROOT::Math::MinimizerOptions::SetDefaultMinimizer
40
41*/
43
44public:
45
46 // static methods for setting and retrieving the default options
47
48 /// Set the default Minimizer type and corresponding algorithms.
49 /// Here is the list of the available minimizers and their corresponding algorithms.
50 /// For some minimizers (e.g. Fumili) there are no specific algorithms available, then there is no need to specify it.
51 ///
52 /// \anchor ROOTMinimizers
53 /// ### ROOT Minimizers
54 ///
55 /// - Minuit Minimizer based on TMinuit, the legacy Minuit implementation. Here are the available algorithms:
56 /// - Migrad default algorithm based on the variable metric minimizer
57 /// - Minimize combination of Simplex and Migrad
58 /// - Simplex minimization algorithm not using the gradient information
59 /// - Scan brute function scan
60 /// - Minuit2 New C++ implementation of Minuit (the recommended one)
61 /// - Migrad (default)
62 /// - Minimize
63 /// - Simplex
64 /// - Fumili2 new implementation of Fumili integrated in Minuit2
65 /// - 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.
66 /// - Linear Linear minimizer (fitter) working only for linear functions (see TLinearFitter and TLinearMinimizer)
67 /// - GSLMultiMin Minimizer from GSL based on the ROOT::Math::GSLMinimizer. Available algorithms are:
68 /// - BFGS2 (default)
69 /// - BFGS
70 /// - ConjugateFR
71 /// - ConjugatePR
72 /// - SteepestDescent
73 /// - GSLMultiFit Minimizer based on GSL for minimizing only non linear least-squared functions (using an approximation similar to Fumili). See ROOT::Math::GSLMultiFit.
74 /// - GSLSimAn Simulated annealing minimizer from GSL (see ROOT::Math::GSLSimAnMinimizer). It is a stochastic minimization algorithm using only function values and not the gradient.
75 /// - Genetic Genetic minimization algorithms (see TMVA::Genetic and ROOT::Math::GeneticMinimizer)
76 /// - RMinimizer (class ROOT::Math::RMinimizer) available when ROOT is built with `r` support
77 /// - BFGS (default)
78 /// - L-BFGS-S
79 /// - Nelder-Mead
80 /// - CG
81 /// - 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)
82 /// @see ROOT::Math::Minimizer
83 static void SetDefaultMinimizer(const char *type, const char *algo = nullptr);
84
85 /// Set the default level for computing the parameter errors.
86 /// For example for 1-sigma parameter errors
87 /// - up = 1 for a chi-squared function
88 /// - up = 0.5 for a negative log-likelihood function
89 ///
90 /// The value will be used also by Minos when computing the confidence interval
91 static void SetDefaultErrorDef(double up);
92
93 /// Set the Minimization tolerance.
94 /// The Default value for Minuit and Minuit2 is 0.01
95 static void SetDefaultTolerance(double tol);
96
97 /// Set the default Minimizer precision.
98 /// (used only by MInuit and Minuit2)
99 /// It is used to specify the numerical precision used for computing the
100 /// objective function. It should be left to the default value found by the Minimizer
101 /// (typically double precision)
102 static void SetDefaultPrecision(double prec);
103
104 /// Set the maximum number of function calls.
105 static void SetDefaultMaxFunctionCalls(int maxcall);
106
107 /// Set the maximum number of iterations.
108 /// Used by the GSL minimizers and Genetic. Not used by Minuit,Minuit2.
109 static void SetDefaultMaxIterations(int maxiter);
110
111 /// Set the default strategy.
112 /// The strategy is a parameter used only by Minuit and Minuit2.
113 /// Possible values are:
114 /// - `strat = 0` : rough approximation of Hessian using the gradient. Avoid computing the full Hessian matrix
115 /// - `strat = 1` (default and recommended one) - Use Hessian approximation but compute full Hessian at the end of minimization if needed.
116 /// - `strat = 2` Perform several full Hessian computations during the minimization. Slower and not always working better than `strat=1`.
117 static void SetDefaultStrategy(int strat);
118
119 /// Set the default Print Level.
120 /// Possible levels are from 0 (minimal printing) to 3 (maximum printing)
121 static void SetDefaultPrintLevel(int level);
122
123 /// Set additional minimizer options as pair of (string,value).
124 /// Extra option defaults can be configured for a specific algorithm and
125 /// then if a matching with the correct option name exists it will be used
126 /// whenever creating a new minimizer instance.
127 /// For example for changing the default number of steps of the Genetic minimizer from 100 to 500 do
128 ///
129 /// auto extraOpt = ROOT::Math::MinimizerOptions::Default("Genetic")
130 /// extraOpts.SetValue("Steps",500);
131 ///
132 /// and when creating the Genetic minimizer you will have the new value for the option:
133 ///
134 /// auto gmin = ROOT::Math::Factory::CreateMinimizer("Genetic");
135 /// gmin->Options().Print();
136 ///
137 static void SetDefaultExtraOptions(const IOptions * extraoptions);
138
139
140 static const std::string & DefaultMinimizerType();
141 static const std::string & DefaultMinimizerAlgo();
142 static double DefaultErrorDef();
143 static double DefaultTolerance();
144 static double DefaultPrecision();
145 static int DefaultMaxFunctionCalls();
146 static int DefaultMaxIterations();
147 static int DefaultStrategy();
148 static int DefaultPrintLevel();
149 static IOptions * DefaultExtraOptions();
150
151 /// Retrieve extra options for a given minimizer name.
152 /// If the extra options already exist in a global map of (Minimizer name, options)
153 /// it will return a reference to that options, otherwise it will create a new one
154 /// and return the corresponding reference
155 static ROOT::Math::IOptions & Default(const char * name);
156
157 /// Find an extra options and return a nullptr if it is not existing.
158 /// Same as above but it will not create a new one
159 static ROOT::Math::IOptions * FindDefault(const char * name);
160
161 /// Print all the default options including the extra one specific for a given minimizer name.
162 /// If no minimizer name is given, all the extra default options, which have been set and configured will be printed
163 static void PrintDefault(const char * name = nullptr, std::ostream & os = std::cout);
164
165public:
166
167 // constructor using the default options
169
170 // destructor
172
173 // copy constructor
175
176 /// assignment operators
178
179 /** non-static methods for retrieving options */
180
181 /// set print level
182 int PrintLevel() const { return fLevel; }
183
184 /// max number of function calls
185 unsigned int MaxFunctionCalls() const { return fMaxCalls; }
186
187 /// max iterations
188 unsigned int MaxIterations() const { return fMaxIter; }
189
190 /// strategy
191 int Strategy() const { return fStrategy; }
192
193 /// absolute tolerance
194 double Tolerance() const { return fTolerance; }
195
196 /// precision in the objective function calculation (value <=0 means left to default)
197 double Precision() const { return fPrecision; }
198
199 /// error definition
200 double ErrorDef() const { return fErrorDef; }
201
202 /// return extra options (NULL pointer if they are not present)
203 const IOptions * ExtraOptions() const { return fExtraOptions; }
205
206 /// type of minimizer
207 const std::string & MinimizerType() const { return fMinimType; }
208
209 /// type of algorithm
210 const std::string & MinimizerAlgorithm() const { return fAlgoType; }
211
212 /// print all the options
213 void Print(std::ostream & os = std::cout) const;
214
215 /** non-static methods for setting options */
217
218 /// set print level
219 void SetPrintLevel(int level) { fLevel = level; }
220
221 ///set maximum of function calls
222 void SetMaxFunctionCalls(unsigned int maxfcn) { fMaxCalls = maxfcn; }
223
224 /// set maximum iterations (one iteration can have many function calls)
225 void SetMaxIterations(unsigned int maxiter) { fMaxIter = maxiter; }
226
227 /// set the tolerance
228 void SetTolerance(double tol) { fTolerance = tol; }
229
230 /// set the precision
231 void SetPrecision(double prec) { fPrecision = prec; }
232
233 /// set the strategy
235
236 /// set error def
237 void SetErrorDef(double err) { fErrorDef = err; }
238
239 /// set minimizer type
240 void SetMinimizerType(const char * type) { fMinimType = type; }
241
242 /// set minimizer algorithm
243 void SetMinimizerAlgorithm(const char *type) { fAlgoType = type; }
244
245 /// set extra options (in this case pointer is cloned)
246 void SetExtraOptions(const IOptions & opt);
247
248
249private:
250
251 int fLevel; ///< debug print level
252 int fMaxCalls; ///< maximum number of function calls
253 int fMaxIter; ///< maximum number of iterations
254 int fStrategy; ///< minimizer strategy (used by Minuit)
255 double fErrorDef; ///< error definition (=1. for getting 1 sigma error for chi2 fits)
256 double fTolerance; ///< minimize tolerance to reach solution
257 double fPrecision; ///< precision of the objective function evaluation (value <=0 means left to default)
258 std::string fMinimType; ///< Minimizer type (Minuit, Minuit2, etc..
259 std::string fAlgoType; ///< Minimizer algorithmic specification (Migrad, Minimize, ...)
260
261 // extra options
263
264};
265
266 } // end namespace Math
267
268} // end namespace ROOT
269
270#endif
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
Generic interface for defining configuration options of a numerical algorithm.
Definition IOptions.h:28
void SetMaxFunctionCalls(unsigned int maxfcn)
set maximum of function calls
void SetStrategy(int stra)
set the strategy
MinimizerOptions & operator=(const MinimizerOptions &opt)
assignment operators
static ROOT::Math::IOptions & Default(const char *name)
Retrieve extra options for a given minimizer name.
static void SetDefaultMaxFunctionCalls(int maxcall)
Set the maximum number of function calls.
double fPrecision
precision of the objective function evaluation (value <=0 means left to default)
std::string fMinimType
Minimizer type (Minuit, Minuit2, etc..
void SetMaxIterations(unsigned int maxiter)
set maximum iterations (one iteration can have many function calls)
const IOptions * ExtraOptions() const
return extra options (NULL pointer if they are not present)
static ROOT::Math::IOptions * FindDefault(const char *name)
Find an extra options and return a nullptr if it is not existing.
double Tolerance() const
absolute tolerance
double Precision() const
precision in the objective function calculation (value <=0 means left to default)
void SetMinimizerType(const char *type)
set minimizer type
const std::string & MinimizerAlgorithm() const
type of algorithm
int fMaxIter
maximum number of iterations
double ErrorDef() const
error definition
static void SetDefaultExtraOptions(const IOptions *extraoptions)
Set additional minimizer options as pair of (string,value).
static IOptions * DefaultExtraOptions()
std::string fAlgoType
Minimizer algorithmic specification (Migrad, Minimize, ...)
static void SetDefaultMaxIterations(int maxiter)
Set the maximum number of iterations.
static void SetDefaultErrorDef(double up)
Set the default level for computing the parameter errors.
static void SetDefaultMinimizer(const char *type, const char *algo=nullptr)
Set the default Minimizer type and corresponding algorithms.
static void SetDefaultStrategy(int strat)
Set the default strategy.
static void SetDefaultPrecision(double prec)
Set the default Minimizer precision.
static const std::string & DefaultMinimizerType()
double fTolerance
minimize tolerance to reach solution
void SetExtraOptions(const IOptions &opt)
set extra options (in this case pointer is cloned)
int fStrategy
minimizer strategy (used by Minuit)
static void PrintDefault(const char *name=nullptr, std::ostream &os=std::cout)
Print all the default options including the extra one specific for a given minimizer name.
int fMaxCalls
maximum number of function calls
static const std::string & DefaultMinimizerAlgo()
double fErrorDef
error definition (=1. for getting 1 sigma error for chi2 fits)
const std::string & MinimizerType() const
type of minimizer
static void SetDefaultPrintLevel(int level)
Set the default Print Level.
unsigned int MaxIterations() const
max iterations
ROOT::Math::IOptions * fExtraOptions
void SetPrecision(double prec)
set the precision
unsigned int MaxFunctionCalls() const
max number of function calls
void ResetToDefaultOptions()
non-static methods for setting options
static void SetDefaultTolerance(double tol)
Set the Minimization tolerance.
int PrintLevel() const
non-static methods for retrieving options
void SetErrorDef(double err)
set error def
void SetPrintLevel(int level)
set print level
void Print(std::ostream &os=std::cout) const
print all the options
void SetMinimizerAlgorithm(const char *type)
set minimizer algorithm
void SetTolerance(double tol)
set the tolerance
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...