Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
MnStrategy.h
Go to the documentation of this file.
1// @(#)root/minuit2:$Id$
2// Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT *
7 * *
8 **********************************************************************/
9
10#ifndef ROOT_Minuit2_MnStrategy
11#define ROOT_Minuit2_MnStrategy
12
13namespace ROOT {
14
15namespace Minuit2 {
16
17/**
18 API class for defining four levels of strategies: low (0), medium (1),
19 high (2), very high (>=3);
20 acts on: Migrad (behavioural),
21 Minos (lowers strategy by 1 for Minos-own minimization),
22 Hesse (iterations),
23 Numerical2PDerivative (iterations)
24
25 The strategy level controls the trade-off between the speed and the reliability of
26 the minimization and error calculation. A higher level spends more function
27 evaluations to refine the gradient and the Hessian.
28
29 The table below documents every tunable that the strategy governs, together with
30 its default value for each strategy level. Strategy 3 shares strategy 2's Migrad
31 iteration parameters, but skips the expensive full initial Hessian at the seed
32 stage (**ComputeInitialHessian**) and applies additional changes to the Hesse
33 calculation that aim at a more accurate Hessian and allow returning the covariance
34 matrix without forcing it to be positive-definite.
35
36 <table>
37 <tr>
38 <th rowspan="2">Name and effect</th>
39 <th rowspan="2">Type</th>
40 <th colspan="4">Value for strategy *n*</th>
41 </tr>
42 <tr>
43 <th>0</th>
44 <th>1</th>
45 <th>2</th>
46 <th>3</th>
47 </tr>
48 <tr>
49 <td>**ComputeInitialHessian**</td>
50 <td><code>bool</code></td>
51 <td rowspan="2" colspan="2">false</td> <td rowspan="2">true</td> <td rowspan="2"><span style="color:red;">false</span></td>
52 </tr>
53 <tr>
54 <td colspan="2">
55 Compute full initial Hessian for the seed state, which can be quite expensive for many parameters.
56
57 Usually, the initial approximation that leaves the off-diagonal elements at zero is good enough.
58 </td>
59 </tr>
60 <tr>
61 <td>**RefineGradientInHessian**</td>
62 <td><code>bool</code></td>
63 <td rowspan="2">false</td> <td rowspan="2" colspan="3">true</td>
64 </tr>
65 <tr>
66 <td colspan="2">
67 After the diagonal second derivatives have been computed, recompute the
68 first derivatives at the current point with the more
69 accurate **HessianGradientCalculator** (which uses up to **HessianGradientNCycles**
70 refinement cycles) instead of reusing the gradient from the last
71 minimization step.
72 </td>
73 </tr>
74 <tr>
75 <td>**GradientNCycles**</td>
76 <td><code>unsigned int</code></td>
77 <td rowspan="2">2</td> <td rowspan="2">3</td> <td rowspan="2" colspan="2">5</td>
78 </tr>
79 <tr>
80 <td colspan="2">
81 Maximum number of cycles the numerical gradient calculator spends refining
82 the finite-difference step size and the first-derivative estimate of each
83 parameter. More cycles yield a more accurate gradient at the price of more
84 function evaluations.
85
86 A cycle is stopped early once either **GradientStepTolerance** or **GradientTolerance** is met.
87 </td>
88 </tr>
89 <tr>
90 <td>**GradientStepTolerance**</td>
91 <td><code>double</code></td>
92 <td rowspan="2">0.5</td> <td rowspan="2">0.3</td> <td rowspan="2" colspan="2">0.1</td>
93 </tr>
94 <tr>
95 <td colspan="2">
96 Stop the numerical gradient refinement cycle early once the finite-difference
97 step size has stabilized.
98
99 The parameter refers to the change in step size relative to the new step size.
100
101 This is the partner of the **GradientTolerance** parameter.
102 </td>
103 </tr>
104 <tr>
105 <td>**GradientTolerance**</td>
106 <td><code>double</code></td>
107 <td rowspan="2">0.1</td> <td rowspan="2">0.05</td> <td rowspan="2" colspan="2">0.02</td>
108 </tr>
109 <tr>
110 <td colspan="2">
111 Stop the numerical gradient refinement cycle early once the first-derivative
112 estimate itself is stable.
113
114 The parameter refers to the change in the first-derivative estimate relative to
115 the new estimate.
116
117 This is the partner of the **GradientStepTolerance** parameter.
118 </td>
119 </tr>
120 <tr>
121 <td>**HessianCentralFDMixedDerivatives**</td>
122 <td><code>unsigned int</code></td>
123 <td rowspan="2" colspan="3">0</td> <td rowspan="2">1</td>
124 </tr>
125 <tr>
126 <td colspan="2">
127 Central finite difference is used for mixed partial derivatives (the off-diagonal terms of the Hessian).
128
129 This requires 3 extra function evaluations per derivative, but is
130 necessary in the case of minima where there is high curvature (in
131 the case of high stats) and the forward finite difference (default)
132 behaviour leads incorrectly to a non-positive-definite covariance
133 matrix.
134
135 The strategy level only sets the defaults: when Minuit2 is used through
136 ROOT::Minuit2::Minuit2Minimizer, the tunables listed below can also be overridden
137 individually, by name, through the "Minuit2" extra options of
138 ROOT::Math::MinimizerOptions. That is the way to pick up a single behaviour of a
139 higher strategy (most usefully **HessianCentralFDMixedDerivatives**) without
140 paying for all the others.
141
142 </td>
143 </tr>
144 <tr>
145 <td>**HessianForcePosDef**</td>
146 <td><code>unsigned int</code></td>
147 <td colspan="3" rowspan="2">1</td> <td rowspan="2"><span style="color:red;">0</span></td>
148 </tr>
149 <tr>
150 <td colspan="2">
151 Force Hessian / covariance matrix to be positive-definite.
152
153 It can be useful to return the uncorrected covariance matrix, even if it is not positive
154 definite.
155
156 One use case is to check just how far from positive-definiteness the matrix is by being able to examine the eigenvalues.
157 </td>
158 </tr>
159 <tr>
160 <td>**HessianG2Tolerance**</td>
161 <td><code>double</code></td>
162 <td rowspan="2">0.1</td> <td rowspan="2">0.05</td> <td rowspan="2">0.02</td> <td rowspan="2">zero</td>
163 </tr>
164 <tr>
165 <td colspan="2">
166 Stop the Hessian diagonal refinement cycle early if the second derivative estimate itself is stable.
167
168 The parameter refers to the change in the second derivative estimate relative to the new estimate.
169
170 This is the partner of the **HessianStepTolerance** parameter.
171
172 In some cases, it can help to set it to zero. This was found to be
173 necessary in cases where Asimov datasets were used for the
174 minimization and there were very few iterations for the approximate
175 covariance to be determined from.
176 </td>
177 </tr>
178 <tr>
179 <td>**HessianGradientNCycles**</td>
180 <td><code>unsigned int</code></td>
181 <td rowspan="2">1</td> <td rowspan="2">2</td> <td rowspan="2" colspan="2">6</td>
182 </tr>
183 <tr>
184 <td colspan="2">
185 Maximum number of refinement cycles used when the first derivatives are
186 recomputed together with the Hessian (see **RefineGradientInHessian**).
187
188 This is the analogue of **GradientNCycles**, but for the more accurate gradient
189 evaluated during the Hessian calculation.
190 </td>
191 </tr>
192 <tr>
193 <td>**HessianNCycles**</td>
194 <td><code>unsigned int</code></td>
195 <td rowspan="2">3</td> <td rowspan="2">5</td> <td rowspan="2" colspan="2">7</td>
196 </tr>
197 <tr>
198 <td colspan="2">
199 Maximum number of cycles used to compute each diagonal element of the Hessian
200 (the second derivative with respect to a single parameter). More cycles refine
201 the finite-difference step and give a more accurate second derivative.
202
203 A cycle is stopped early once either **HessianStepTolerance** or **HessianG2Tolerance** is met.
204 </td>
205 </tr>
206 <tr>
207 <td>**HessianRecomputeThreshold**</td>
208 <td><code>double</code></td>
209 <td rowspan="2">inf</td> <td rowspan="2">0.05</td> <td rowspan="2" colspan="2">-inf</td>
210 </tr>
211 <tr>
212 <td colspan="2">
213 After a Migrad minimization, a full Hesse recomputation of the error matrix is
214 triggered when the relative change of the covariance matrix in the last step
215 (`Dcovar`) exceeds this threshold.
216
217 A value of *inf* means the Hessian is never recomputed and the approximate
218 covariance accumulated during Migrad is kept, while *-inf* means it is always
219 recomputed.
220 </td>
221 </tr>
222 <tr>
223 <td>**HessianStepTolerance**</td>
224 <td><code>double</code></td>
225 <td rowspan="2">0.5</td> <td rowspan="2">0.3</td> <td rowspan="2">0.1</td> <td rowspan="2">zero</td>
226 </tr>
227 <tr>
228 <td colspan="2">
229 Stop the Hessian diagonal refinement cycle early if the estimated optimal finite-difference step size has stabilized.
230
231 The parameter refers to the change in step size relative to the new step size.
232
233 This is the partner of the **HessianG2Tolerance** parameter.
234
235 Just like with that parameter, it can make sense to set the tolerance to zero to ensure the most accurate Hessians.
236 </td>
237 </tr>
238 <tr>
239 <td>**StorageLevel**</td>
240 <td><code>int</code></td>
241 <td rowspan="2" colspan="4">1</td>
242 </tr>
243 <tr>
244 <td colspan="2">
245 How much of the minimization history is kept: 1 stores the full sequence of
246 iterations, while 0 keeps only the last iterations.
247
248 This does not affect the minimization result, only the trace that can be
249 inspected afterwards.
250 </td>
251 </tr>
252 </table>
253 */
254
256
257public:
258 // default strategy
259 MnStrategy();
260
261 // user defined strategy (0, 1, 2, >=3)
262 explicit MnStrategy(unsigned int);
263
264 unsigned int GradientNCycles() const { return fGradNCyc; }
265 double GradientStepTolerance() const { return fGradTlrStp; }
266 double GradientTolerance() const { return fGradTlr; }
267
268 unsigned int HessianNCycles() const { return fHessNCyc; }
269 double HessianStepTolerance() const { return fHessTlrStp; }
270 double HessianG2Tolerance() const { return fHessTlrG2; }
271 unsigned int HessianGradientNCycles() const { return fHessGradNCyc; }
272 unsigned int HessianCentralFDMixedDerivatives() const { return fHessCFDG2; }
273 unsigned int HessianForcePosDef() const { return fHessForcePosDef; }
274
275 int StorageLevel() const { return fStoreLevel; }
276
277 bool RefineGradientInHessian() const { return fStrategy > 0; }
278
279 bool ComputeInitialHessian() const { return fStrategy == 2; }
280
281 double HessianRecomputeThreshold() const;
282
283 void SetGradientNCycles(unsigned int n) { fGradNCyc = n; }
286
287 void SetHessianNCycles(unsigned int n) { fHessNCyc = n; }
290 void SetHessianGradientNCycles(unsigned int n) { fHessGradNCyc = n; }
291
292 // 1 = calculate central finite difference mixed derivatives (involves 3 extra evaluations per derivative)
293 // 0 = use forward finite difference (default)
295
296 // 1 = returned matrix from Hesse should be forced positive definite (default)
297 // 0 = do not force matrix positive definite
299
300 // set storage level of iteration quantities
301 // 0 = store only last iterations 1 = full storage (default)
302 void SetStorageLevel(unsigned int level) { fStoreLevel = level; }
303
304private:
305 friend class MnFunctionCross;
306 friend class MnContours;
307 MnStrategy NextLower() const;
308
309 void SetLowStrategy();
310 void SetMediumStrategy();
311 void SetHighStrategy();
312 void SetVeryHighStrategy();
313
314 unsigned int fStrategy;
315
316 unsigned int fGradNCyc;
318 double fGradTlr;
319 unsigned int fHessNCyc;
322 unsigned int fHessGradNCyc;
326};
327
328} // namespace Minuit2
329
330} // namespace ROOT
331
332#endif // ROOT_Minuit2_MnStrategy
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
API class for Contours Error analysis (2-dim errors); minimization has to be done before and Minimum ...
Definition MnContours.h:35
API class for defining four levels of strategies: low (0), medium (1), high (2), very high (>=3); act...
Definition MnStrategy.h:255
double HessianG2Tolerance() const
Definition MnStrategy.h:270
unsigned int HessianGradientNCycles() const
Definition MnStrategy.h:271
unsigned int HessianCentralFDMixedDerivatives() const
Definition MnStrategy.h:272
bool RefineGradientInHessian() const
Definition MnStrategy.h:277
double GradientStepTolerance() const
Definition MnStrategy.h:265
void SetStorageLevel(unsigned int level)
Definition MnStrategy.h:302
void SetHessianNCycles(unsigned int n)
Definition MnStrategy.h:287
unsigned int HessianForcePosDef() const
Definition MnStrategy.h:273
void SetHessianStepTolerance(double stp)
Definition MnStrategy.h:288
bool ComputeInitialHessian() const
Definition MnStrategy.h:279
double GradientTolerance() const
Definition MnStrategy.h:266
void SetGradientTolerance(double toler)
Definition MnStrategy.h:285
double HessianStepTolerance() const
Definition MnStrategy.h:269
unsigned int HessianNCycles() const
Definition MnStrategy.h:268
unsigned int GradientNCycles() const
Definition MnStrategy.h:264
void SetHessianCentralFDMixedDerivatives(unsigned int flag)
Definition MnStrategy.h:294
void SetGradientNCycles(unsigned int n)
Definition MnStrategy.h:283
void SetHessianForcePosDef(unsigned int flag)
Definition MnStrategy.h:298
void SetGradientStepTolerance(double stp)
Definition MnStrategy.h:284
void SetHessianGradientNCycles(unsigned int n)
Definition MnStrategy.h:290
void SetHessianG2Tolerance(double toler)
Definition MnStrategy.h:289
double HessianRecomputeThreshold() const
MnStrategy NextLower() const
const Int_t n
Definition legend1.C:16