Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Minuit2Minimizer.h
Go to the documentation of this file.
1// @(#)root/minuit2:$Id$
2// Author: L. Moneta Wed Oct 18 11:48:00 2006
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11// Header file for class Minuit2Minimizer
12
13#ifndef ROOT_Minuit2_Minuit2Minimizer
14#define ROOT_Minuit2_Minuit2Minimizer
15
16#include "Math/Minimizer.h"
17
19
20#include "Math/IFunctionfwd.h"
21
22#include <vector>
23#include <string>
24
25namespace ROOT {
26
27namespace Minuit2 {
28
29class ModularFunctionMinimizer;
30class FCNBase;
31class FunctionMinimum;
32class MnTraceObject;
33
34// enumeration specifying the type of Minuit2 minimizers
36
37} // namespace Minuit2
38
39namespace Minuit2 {
40//_____________________________________________________________________________________________________
41/**
42 Minuit2Minimizer class implementing the ROOT::Math::Minimizer interface for
43 Minuit2 minimization algorithm.
44 In ROOT it can be instantiated using the plug-in manager (plug-in "Minuit2")
45 Using a string (used by the plugin manager) or via an enumeration
46 an one can set all the possible minimization algorithms (Migrad, Simplex, Combined, Scan and Fumili).
47
48 Refer to the [guide](https://root.cern.ch/root/htmldoc/guides/minuit2/Minuit2.html) for an introduction how Minuit
49 works.
50
51 @ingroup Minuit
52*/
54
55public:
56 /**
57 Default constructor
58 */
60
61 /**
62 Constructor with a char (used by PM)
63 */
64 Minuit2Minimizer(const char *type);
65
66 /**
67 Destructor (no operations)
68 */
69 virtual ~Minuit2Minimizer();
70
71private:
72 // usually copying is non trivial, so we make this unaccessible
73
74 /**
75 Copy constructor
76 */
78
79 /**
80 Assignment operator
81 */
83
84public:
85 // clear resources (parameters) for consecutives minimizations
86 virtual void Clear();
87
88 /// set the function to minimize
89 virtual void SetFunction(const ROOT::Math::IMultiGenFunction &func);
90
91 /// set gradient the function to minimize
92 virtual void SetFunction(const ROOT::Math::IMultiGradFunction &func);
93
94 /// set free variable
95 virtual bool SetVariable(unsigned int ivar, const std::string &name, double val, double step);
96
97 /// set lower limit variable (override if minimizer supports them )
98 virtual bool
99 SetLowerLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double lower);
100 /// set upper limit variable (override if minimizer supports them )
101 virtual bool
102 SetUpperLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double upper);
103 /// set upper/lower limited variable (override if minimizer supports them )
104 virtual bool SetLimitedVariable(unsigned int ivar, const std::string &name, double val, double step,
105 double /* lower */, double /* upper */);
106 /// set fixed variable (override if minimizer supports them )
107 virtual bool SetFixedVariable(unsigned int /* ivar */, const std::string & /* name */, double /* val */);
108 /// set variable
109 virtual bool SetVariableValue(unsigned int ivar, double val);
110 // set variable values
111 virtual bool SetVariableValues(const double *val);
112 /// set the step size of an already existing variable
113 virtual bool SetVariableStepSize(unsigned int ivar, double step);
114 /// set the lower-limit of an already existing variable
115 virtual bool SetVariableLowerLimit(unsigned int ivar, double lower);
116 /// set the upper-limit of an already existing variable
117 virtual bool SetVariableUpperLimit(unsigned int ivar, double upper);
118 /// set the limits of an already existing variable
119 virtual bool SetVariableLimits(unsigned int ivar, double lower, double upper);
120 /// fix an existing variable
121 virtual bool FixVariable(unsigned int ivar);
122 /// release an existing variable
123 virtual bool ReleaseVariable(unsigned int ivar);
124 /// query if an existing variable is fixed (i.e. considered constant in the minimization)
125 /// note that by default all variables are not fixed
126 virtual bool IsFixedVariable(unsigned int ivar) const;
127 /// get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
128 virtual bool GetVariableSettings(unsigned int ivar, ROOT::Fit::ParameterSettings &varObj) const;
129 /// get name of variables (override if minimizer support storing of variable names)
130 virtual std::string VariableName(unsigned int ivar) const;
131 /// get index of variable given a variable given a name
132 /// return -1 if variable is not found
133 virtual int VariableIndex(const std::string &name) const;
134
135 /**
136 method to perform the minimization.
137 Return false in case the minimization did not converge. In this case a
138 status code different than zero is set
139 (retrieved by the derived method Minimizer::Status() )"
140
141 status = 1 : Covariance was made pos defined
142 status = 2 : Hesse is invalid
143 status = 3 : Edm is above max
144 status = 4 : Reached call limit
145 status = 5 : Any other failure
146 */
147 virtual bool Minimize();
148
149 /// return minimum function value
150 virtual double MinValue() const { return fState.Fval(); }
151
152 /// return expected distance reached from the minimum
153 virtual double Edm() const { return fState.Edm(); }
154
155 /// return pointer to X values at the minimum
156 virtual const double *X() const { return &fValues.front(); }
157
158 /// return pointer to gradient values at the minimum
159 virtual const double *MinGradient() const { return 0; } // not available in Minuit2
160
161 /// number of function calls to reach the minimum
162 virtual unsigned int NCalls() const { return fState.NFcn(); }
163
164 /// this is <= Function().NDim() which is the total
165 /// number of variables (free+ constrained ones)
166 virtual unsigned int NDim() const { return fDim; }
167
168 /// number of free variables (real dimension of the problem)
169 /// this is <= Function().NDim() which is the total
170 virtual unsigned int NFree() const { return fState.VariableParameters(); }
171
172 /// minimizer provides error and error matrix
173 virtual bool ProvidesError() const { return true; }
174
175 /// return errors at the minimum
176 virtual const double *Errors() const;
177
178 /**
179 return covariance matrix elements
180 if the variable is fixed or const the value is zero
181 The ordering of the variables is the same as in errors and parameter value.
182 This is different from the direct interface of Minuit2 or TMinuit where the
183 values were obtained only to variable parameters
184 */
185 virtual double CovMatrix(unsigned int i, unsigned int j) const;
186
187 /**
188 Fill the passed array with the covariance matrix elements
189 if the variable is fixed or const the value is zero.
190 The array will be filled as cov[i *ndim + j]
191 The ordering of the variables is the same as in errors and parameter value.
192 This is different from the direct interface of Minuit2 or TMinuit where the
193 values were obtained only to variable parameters
194 */
195 virtual bool GetCovMatrix(double *cov) const;
196
197 /**
198 Fill the passed array with the Hessian matrix elements
199 The Hessian matrix is the matrix of the second derivatives
200 and is the inverse of the covariance matrix
201 If the variable is fixed or const the values for that variables are zero.
202 The array will be filled as h[i *ndim + j]
203 */
204 virtual bool GetHessianMatrix(double *h) const;
205
206 /**
207 return the status of the covariance matrix
208 status = -1 : not available (inversion failed or Hesse failed)
209 status = 0 : available but not positive defined
210 status = 1 : covariance only approximate
211 status = 2 : full matrix but forced pos def
212 status = 3 : full accurate matrix
213
214 */
215 virtual int CovMatrixStatus() const;
216 /**
217 return correlation coefficient between variable i and j.
218 If the variable is fixed or const the return value is zero
219 */
220 virtual double Correlation(unsigned int i, unsigned int j) const;
221
222 /**
223 get global correlation coefficient for the variable i. This is a number between zero and one which gives
224 the correlation between the i-th variable and that linear combination of all other variables which
225 is most strongly correlated with i.
226 If the variable is fixed or const the return value is zero
227 */
228 virtual double GlobalCC(unsigned int i) const;
229
230 /**
231 get the minos error for parameter i, return false if Minos failed
232 A minimizaiton must be performed befre, return false if no minimization has been done
233 In case of Minos failed the status error is updated as following
234 status += 10 * minosStatus.
235 The Minos status of last Minos run can also be retrieved by calling MinosStatus()
236 */
237 virtual bool GetMinosError(unsigned int i, double &errLow, double &errUp, int = 0);
238
239 /**
240 MINOS status code of last Minos run
241 `status & 1 > 0` : invalid lower error
242 `status & 2 > 0` : invalid upper error
243 `status & 4 > 0` : invalid because maximum number of function calls exceeded
244 `status & 8 > 0` : a new minimum has been found
245 `status & 16 > 0` : error is truncated because parameter is at lower/upper limit
246 */
247 virtual int MinosStatus() const { return fMinosStatus; }
248
249 /**
250 scan a parameter i around the minimum. A minimization must have been done before,
251 return false if it is not the case
252 */
253 virtual bool Scan(unsigned int i, unsigned int &nstep, double *x, double *y, double xmin = 0, double xmax = 0);
254
255 /**
256 find the contour points (xi,xj) of the function for parameter i and j around the minimum
257 The contour will be find for value of the function = Min + ErrorUp();
258 */
259 virtual bool Contour(unsigned int i, unsigned int j, unsigned int &npoints, double *xi, double *xj);
260
261 /**
262 perform a full calculation of the Hessian matrix for error calculation
263 If a valid minimum exists the calculation is done on the minimum point otherwise is performed
264 in the current set values of parameters
265 Status code of minimizer is updated according to the following convention (in case Hesse failed)
266 status += 100*hesseStatus where hesse status is:
267 status = 1 : hesse failed
268 status = 2 : matrix inversion failed
269 status = 3 : matrix is not pos defined
270 */
271 virtual bool Hesse();
272
273 /// return reference to the objective function
274 /// virtual const ROOT::Math::IGenFunction & Function() const;
275
276 /// print result of minimization
277 virtual void PrintResults();
278
279 /// set an object to trace operation for each iteration
280 /// The object must be a (or inherit from) ROOT::Minuit2::MnTraceObject and implement operator() (int, const
281 /// MinimumState & state)
282 void SetTraceObject(MnTraceObject &obj);
283
284 /// set storage level = 1 : store all iteration states (default)
285 /// = 0 : store only first and last state to save memory
286 void SetStorageLevel(int level);
287
288 /// return the minimizer state (containing values, step size , etc..)
290
291protected:
292 // protected function for accessing the internal Minuit2 object. Needed for derived classes
293
295
297
299
300 virtual const ROOT::Minuit2::FCNBase *GetFCN() const { return fMinuitFCN; }
301
302 /// examine the minimum result
304
305 // internal function to compute Minos errors
306 int RunMinosError(unsigned int i, double &errLow, double &errUp, int runopt);
307
308private:
309 unsigned int fDim; // dimension of the function to be minimized
311 int fMinosStatus = -1; // Minos status code
312
314 // std::vector<ROOT::Minuit2::MinosError> fMinosErrors;
318 mutable std::vector<double> fValues;
319 mutable std::vector<double> fErrors;
320};
321
322} // namespace Minuit2
323
324} // end namespace ROOT
325
326#endif /* ROOT_Minuit2_Minuit2Minimizer */
#define h(i)
Definition RSha256.hxx:106
char name[80]
Definition TGX11.cxx:110
int type
Definition TGX11.cxx:121
float xmin
float xmax
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
Documentation for the abstract class IBaseFunctionMultiDim.
Definition IFunction.h:62
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
Definition IFunction.h:327
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2,...
Definition Minimizer.h:75
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition FCNBase.h:45
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
Minuit2Minimizer class implementing the ROOT::Math::Minimizer interface for Minuit2 minimization algo...
bool ExamineMinimum(const ROOT::Minuit2::FunctionMinimum &min)
examine the minimum result
virtual unsigned int NFree() const
number of free variables (real dimension of the problem) this is <= Function().NDim() which is the to...
const ROOT::Minuit2::MnUserParameterState & State()
return the minimizer state (containing values, step size , etc..)
void SetStorageLevel(int level)
set storage level = 1 : store all iteration states (default) = 0 : store only first and last state to...
Minuit2Minimizer & operator=(const Minuit2Minimizer &rhs)
Assignment operator.
virtual bool SetVariableUpperLimit(unsigned int ivar, double upper)
set the upper-limit of an already existing variable
virtual double GlobalCC(unsigned int i) const
get global correlation coefficient for the variable i.
virtual int VariableIndex(const std::string &name) const
get index of variable given a variable given a name return -1 if variable is not found
virtual bool SetVariable(unsigned int ivar, const std::string &name, double val, double step)
set free variable
virtual bool SetFixedVariable(unsigned int, const std::string &, double)
set fixed variable (override if minimizer supports them )
virtual void SetFunction(const ROOT::Math::IMultiGenFunction &func)
set the function to minimize
virtual const ROOT::Minuit2::FCNBase * GetFCN() const
virtual bool ProvidesError() const
minimizer provides error and error matrix
virtual bool SetLowerLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double lower)
set lower limit variable (override if minimizer supports them )
virtual bool SetLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double, double)
set upper/lower limited variable (override if minimizer supports them )
virtual bool SetVariableLimits(unsigned int ivar, double lower, double upper)
set the limits of an already existing variable
virtual bool SetVariableValues(const double *val)
set the values of all existing variables (array must be dimensioned to the size of the existing param...
virtual int CovMatrixStatus() const
return the status of the covariance matrix status = -1 : not available (inversion failed or Hesse fai...
virtual double MinValue() const
return minimum function value
virtual void Clear()
reset for consecutive minimizations - implement if needed
virtual double CovMatrix(unsigned int i, unsigned int j) const
return covariance matrix elements if the variable is fixed or const the value is zero The ordering of...
virtual ~Minuit2Minimizer()
Destructor (no operations)
virtual bool ReleaseVariable(unsigned int ivar)
release an existing variable
ROOT::Minuit2::ModularFunctionMinimizer * fMinimizer
virtual const double * MinGradient() const
return pointer to gradient values at the minimum
virtual bool Scan(unsigned int i, unsigned int &nstep, double *x, double *y, double xmin=0, double xmax=0)
scan a parameter i around the minimum.
virtual std::string VariableName(unsigned int ivar) const
get name of variables (override if minimizer support storing of variable names)
virtual unsigned int NDim() const
this is <= Function().NDim() which is the total number of variables (free+ constrained ones)
int RunMinosError(unsigned int i, double &errLow, double &errUp, int runopt)
virtual bool GetCovMatrix(double *cov) const
Fill the passed array with the covariance matrix elements if the variable is fixed or const the value...
virtual bool SetUpperLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double upper)
set upper limit variable (override if minimizer supports them )
virtual bool Minimize()
method to perform the minimization.
void SetTraceObject(MnTraceObject &obj)
set an object to trace operation for each iteration The object must be a (or inherit from) ROOT::Minu...
virtual bool SetVariableLowerLimit(unsigned int ivar, double lower)
set the lower-limit of an already existing variable
virtual const ROOT::Minuit2::ModularFunctionMinimizer * GetMinimizer() const
void SetMinimizerType(ROOT::Minuit2::EMinimizerType type)
virtual void PrintResults()
return reference to the objective function virtual const ROOT::Math::IGenFunction & Function() const;
virtual bool GetHessianMatrix(double *h) const
Fill the passed array with the Hessian matrix elements The Hessian matrix is the matrix of the second...
virtual unsigned int NCalls() const
number of function calls to reach the minimum
virtual double Edm() const
return expected distance reached from the minimum
ROOT::Minuit2::MnUserParameterState fState
virtual bool GetMinosError(unsigned int i, double &errLow, double &errUp, int=0)
get the minos error for parameter i, return false if Minos failed A minimizaiton must be performed be...
virtual const double * X() const
return pointer to X values at the minimum
virtual bool IsFixedVariable(unsigned int ivar) const
query if an existing variable is fixed (i.e.
virtual void SetMinimizer(ROOT::Minuit2::ModularFunctionMinimizer *m)
virtual const double * Errors() const
return errors at the minimum
virtual bool GetVariableSettings(unsigned int ivar, ROOT::Fit::ParameterSettings &varObj) const
get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
ROOT::Minuit2::FunctionMinimum * fMinimum
virtual bool SetVariableValue(unsigned int ivar, double val)
set variable
ROOT::Minuit2::FCNBase * fMinuitFCN
virtual bool Contour(unsigned int i, unsigned int j, unsigned int &npoints, double *xi, double *xj)
find the contour points (xi,xj) of the function for parameter i and j around the minimum The contour ...
virtual int MinosStatus() const
MINOS status code of last Minos run status & 1 > 0 : invalid lower error status & 2 > 0 : invalid upp...
virtual double Correlation(unsigned int i, unsigned int j) const
return correlation coefficient between variable i and j.
virtual bool SetVariableStepSize(unsigned int ivar, double step)
set the step size of an already existing variable
virtual bool FixVariable(unsigned int ivar)
fix an existing variable
virtual bool Hesse()
perform a full calculation of the Hessian matrix for error calculation If a valid minimum exists the ...
class which holds the external user and/or internal Minuit representation of the parameters and error...
Base common class providing the API for all the minimizer Various Minimize methods are provided varyi...
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
auto * m
Definition textangle.C:8