Logo ROOT  
Reference Guide
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*/
41
42public:
43
44 // static methods for setting and retrieving the default options
45
46 /// Set the default Minimizer type and corresponding algorithms.
47 /// Here is the list of the available minimizers and their corresponding algorithms.
48 /// For some minimizers (e.g. Fumili) there are no specific algorithms available, then there is no need to specify it.
49 ///
50 /// \anchor ROOTMinimizers
51 /// ### ROOT Minimizers
52 ///
53 /// - Minuit Minimizer based on TMinuit, the legacy Minuit implementation. Here are the available algorithms:
54 /// - Migrad default algorithm based on the variable metric minimizer
55 /// - Minimize combination of Simplex and Migrad
56 /// - Simplex minimization algorithm not using the gradient information
57 /// - Scan brute function scan
58 /// - Minuit2 New C++ implementation of Minuit (the recommended one)
59 /// - Migrad (default)
60 /// - Minimize
61 /// - Simplex
62 /// - Fumili2 new implementation of Fumili integrated in Minuit2
63 /// - 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.
64 /// - Linear Linear minimizer (fitter) working only for linear functions (see TLinearFitter and TLinearMinimizer)
65 /// - GSLMultiMin Minimizer from GSL based on the ROOT::Math::GSLMinimizer. Available algorithms are:
66 /// - BFGS2 (default)
67 /// - BFGS
68 /// - ConjugateFR
69 /// - ConjugatePR
70 /// - SteepestDescent
71 /// - GSLMultiFit Minimizer based on GSL for minimizing only non linear least-squared functions (using an approximation similar to Fumili). See ROOT::Math::GSLMultiFit.
72 /// - GSLSimAn Simulated annealing minimizer from GSL (see ROOT::Math::GSLSimAnMinimizer). It is a stochastic minimization algorithm using only function values and not the gradient.
73 /// - Genetic Genetic minimization algorithms (see TMVA::Genetic)
74 ///
75 static void SetDefaultMinimizer(const char * type, const char * algo = 0);
76
77 /// Set the default level for computing the parameter errors.
78 /// For example for 1-sigma parameter errors
79 /// - up = 1 for a chi-squared function
80 /// - up = 0.5 for a negative log-likelihood function
81 ///
82 /// The value will be used also by Minos when computing the confidence interval
83 static void SetDefaultErrorDef( double up);
84
85 /// Set the Minimization tolerance.
86 /// The Default value for Minuit and Minuit2 is 0.01
87 static void SetDefaultTolerance(double tol);
88
89 /// Set the default Minimizer precision.
90 /// (used only by MInuit and Minuit2)
91 /// It is used to specify the numerical precision used for computing the
92 /// objective function. It should be left to the default value found by the Minimizer
93 /// (typically double precision)
94 static void SetDefaultPrecision(double prec);
95
96 /// Set the maximum number of function calls.
97 static void SetDefaultMaxFunctionCalls(int maxcall);
98
99 /// Set the maximum number of iterations.
100 /// Used by the GSL minimizers and Genetic. Not used by Minuit,Minuit2.
101 static void SetDefaultMaxIterations(int maxiter);
102
103 /// Set the default strategy.
104 /// The strategy is a parameter used only by Minuit and Minuit2.
105 /// Possible values are:
106 /// - `strat = 0` : rough approximation of Hessian using the gradient. Avoid computing the full Hessian matrix
107 /// - `strat = 1` (default and recommended one) - Use Hessian approximation but compute full Hessian at the end of minimization if needed.
108 /// - `strat = 2` Perform several full Hessian computations during the minimization. Slower and not always working better than `strat=1`.
109 static void SetDefaultStrategy(int strat);
110
111 /// Set the default Print Level.
112 /// Possible levels are from 0 (minimal printing) to 3 (maximum printing)
113 static void SetDefaultPrintLevel(int level);
114
115 /// Set additional minimizer options as pair of (string,value).
116 /// Extra option defaults can be configured for a specific algorithm and
117 /// then if a matching with the correct option name exists it will be used
118 /// whenever creating a new minimizer instance.
119 /// For example for changing the default number of steps of the Genetic minimizer from 100 to 500 do
120 ///
121 /// auto extraOpt = ROOT::Math::MinimizerOptions::Default("Genetic")
122 /// extraOpts.SetValue("Steps",500);
123 ///
124 /// and when creating the Genetic minimizer you will have the new value for the option:
125 ///
126 /// auto gmin = ROOT::Math::Factory::CreateMinimizer("Genetic");
127 /// gmin->Options().Print();
128 ///
129 static void SetDefaultExtraOptions(const IOptions * extraoptions);
130
131
132 static const std::string & DefaultMinimizerType();
133 static const std::string & DefaultMinimizerAlgo();
134 static double DefaultErrorDef();
135 static double DefaultTolerance();
136 static double DefaultPrecision();
137 static int DefaultMaxFunctionCalls();
138 static int DefaultMaxIterations();
139 static int DefaultStrategy();
140 static int DefaultPrintLevel();
141 static IOptions * DefaultExtraOptions();
142
143 /// Retrieve extra options for a given minimizer name.
144 /// If the extra options already exist in a global map of (Minimizer name, options)
145 /// it will return a reference to that options, otherwise it will create a new one
146 /// and return the corresponding reference
147 static ROOT::Math::IOptions & Default(const char * name);
148
149 /// Find an extra options and return a nullptr if it is not existing.
150 /// Same as above but it will not create a new one
151 static ROOT::Math::IOptions * FindDefault(const char * name);
152
153 /// Print all the default options including the extra one specific for a given minimizer name.
154 /// If no minimizer name is given, all the extra default options, which have been set and configured will be printed
155 static void PrintDefault(const char * name = nullptr, std::ostream & os = std::cout);
156
157public:
158
159 // constructor using the default options
161
162 // destructor
164
165 // copy constructor
167
168 /// assignment operators
170
171 /** non-static methods for retrieving options */
172
173 /// set print level
174 int PrintLevel() const { return fLevel; }
175
176 /// max number of function calls
177 unsigned int MaxFunctionCalls() const { return fMaxCalls; }
178
179 /// max iterations
180 unsigned int MaxIterations() const { return fMaxIter; }
181
182 /// strategy
183 int Strategy() const { return fStrategy; }
184
185 /// absolute tolerance
186 double Tolerance() const { return fTolerance; }
187
188 /// precision in the objective function calculation (value <=0 means left to default)
189 double Precision() const { return fPrecision; }
190
191 /// error definition
192 double ErrorDef() const { return fErrorDef; }
193
194 /// return extra options (NULL pointer if they are not present)
195 const IOptions * ExtraOptions() const { return fExtraOptions; }
196
197 /// type of minimizer
198 const std::string & MinimizerType() const { return fMinimType; }
199
200 /// type of algorithm
201 const std::string & MinimizerAlgorithm() const { return fAlgoType; }
202
203 /// print all the options
204 void Print(std::ostream & os = std::cout) const;
205
206 /** non-static methods for setting options */
208
209 /// set print level
210 void SetPrintLevel(int level) { fLevel = level; }
211
212 ///set maximum of function calls
213 void SetMaxFunctionCalls(unsigned int maxfcn) { fMaxCalls = maxfcn; }
214
215 /// set maximum iterations (one iteration can have many function calls)
216 void SetMaxIterations(unsigned int maxiter) { fMaxIter = maxiter; }
217
218 /// set the tolerance
219 void SetTolerance(double tol) { fTolerance = tol; }
220
221 /// set the precision
222 void SetPrecision(double prec) { fPrecision = prec; }
223
224 /// set the strategy
225 void SetStrategy(int stra) { fStrategy = stra; }
226
227 /// set error def
228 void SetErrorDef(double err) { fErrorDef = err; }
229
230 /// set minimizer type
231 void SetMinimizerType(const char * type) { fMinimType = type; }
232
233 /// set minimizer algorithm
234 void SetMinimizerAlgorithm(const char *type) { fAlgoType = type; }
235
236 /// set extra options (in this case pointer is cloned)
237 void SetExtraOptions(const IOptions & opt);
238
239
240private:
241
242 int fLevel; ///< debug print level
243 int fMaxCalls; ///< maximum number of function calls
244 int fMaxIter; ///< maximum number of iterations
245 int fStrategy; ///< minimizer strategy (used by Minuit)
246 double fErrorDef; ///< error definition (=1. for getting 1 sigma error for chi2 fits)
247 double fTolerance; ///< minimize tolerance to reach solution
248 double fPrecision; ///< precision of the objective function evaluation (value <=0 means left to default)
249 std::string fMinimType; ///< Minimizer type (Minuit, Minuit2, etc..
250 std::string fAlgoType; ///< Minimizer algorithmic specification (Migrad, Minimize, ...)
251
252 // extra options
254
255};
256
257 } // end namespace Math
258
259} // end namespace ROOT
260
261#endif
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:31
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 void SetDefaultMinimizer(const char *type, const char *algo=0)
Set the default Minimizer type and corresponding algorithms.
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)
int Strategy() const
strategy
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 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)
int fLevel
debug print level
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.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.