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 </td>
135 </tr>
136 <tr>
137 <td>**HessianForcePosDef**</td>
138 <td><code>unsigned int</code></td>
139 <td colspan="3" rowspan="2">1</td> <td rowspan="2"><span style="color:red;">0</span></td>
140 </tr>
141 <tr>
142 <td colspan="2">
143 Force Hessian / covariance matrix to be positive-definite.
144
145 It can be useful to return the uncorrected covariance matrix, even if it is not positive
146 definite.
147
148 One use case is to check just how far from positive-definiteness the matrix is by being able to examine the eigenvalues.
149 </td>
150 </tr>
151 <tr>
152 <td>**HessianG2Tolerance**</td>
153 <td><code>double</code></td>
154 <td rowspan="2">0.1</td> <td rowspan="2">0.05</td> <td rowspan="2">0.02</td> <td rowspan="2">zero</td>
155 </tr>
156 <tr>
157 <td colspan="2">
158 Stop the Hessian diagonal refinement cycle early if the second derivative estimate itself is stable.
159
160 The parameter refers to the change in the second derivative estimate relative to the new estimate.
161
162 This is the partner of the **HessianStepTolerance** parameter.
163
164 In some cases, it can help to set it to zero. This was found to be
165 necessary in cases where Asimov datasets were used for the
166 minimization and there were very few iterations for the approximate
167 covariance to be determined from.
168 </td>
169 </tr>
170 <tr>
171 <td>**HessianGradientNCycles**</td>
172 <td><code>unsigned int</code></td>
173 <td rowspan="2">1</td> <td rowspan="2">2</td> <td rowspan="2" colspan="2">6</td>
174 </tr>
175 <tr>
176 <td colspan="2">
177 Maximum number of refinement cycles used when the first derivatives are
178 recomputed together with the Hessian (see **RefineGradientInHessian**).
179
180 This is the analogue of **GradientNCycles**, but for the more accurate gradient
181 evaluated during the Hessian calculation.
182 </td>
183 </tr>
184 <tr>
185 <td>**HessianNCycles**</td>
186 <td><code>unsigned int</code></td>
187 <td rowspan="2">3</td> <td rowspan="2">5</td> <td rowspan="2" colspan="2">7</td>
188 </tr>
189 <tr>
190 <td colspan="2">
191 Maximum number of cycles used to compute each diagonal element of the Hessian
192 (the second derivative with respect to a single parameter). More cycles refine
193 the finite-difference step and give a more accurate second derivative.
194
195 A cycle is stopped early once either **HessianStepTolerance** or **HessianG2Tolerance** is met.
196 </td>
197 </tr>
198 <tr>
199 <td>**HessianRecomputeThreshold**</td>
200 <td><code>double</code></td>
201 <td rowspan="2">inf</td> <td rowspan="2">0.05</td> <td rowspan="2" colspan="2">-inf</td>
202 </tr>
203 <tr>
204 <td colspan="2">
205 After a Migrad minimization, a full Hesse recomputation of the error matrix is
206 triggered when the relative change of the covariance matrix in the last step
207 (`Dcovar`) exceeds this threshold.
208
209 A value of *inf* means the Hessian is never recomputed and the approximate
210 covariance accumulated during Migrad is kept, while *-inf* means it is always
211 recomputed.
212 </td>
213 </tr>
214 <tr>
215 <td>**HessianStepTolerance**</td>
216 <td><code>double</code></td>
217 <td rowspan="2">0.5</td> <td rowspan="2">0.3</td> <td rowspan="2">0.1</td> <td rowspan="2">zero</td>
218 </tr>
219 <tr>
220 <td colspan="2">
221 Stop the Hessian diagonal refinement cycle early if the estimated optimal finite-difference step size has stabilized.
222
223 The parameter refers to the change in step size relative to the new step size.
224
225 This is the partner of the **HessianG2Tolerance** parameter.
226
227 Just like with that parameter, it can make sense to set the tolerance to zero to ensure the most accurate Hessians.
228 </td>
229 </tr>
230 <tr>
231 <td>**StorageLevel**</td>
232 <td><code>int</code></td>
233 <td rowspan="2" colspan="4">1</td>
234 </tr>
235 <tr>
236 <td colspan="2">
237 How much of the minimization history is kept: 1 stores the full sequence of
238 iterations, while 0 keeps only the last iterations.
239
240 This does not affect the minimization result, only the trace that can be
241 inspected afterwards.
242 </td>
243 </tr>
244 </table>
245 */
246
248
249public:
250 // default strategy
251 MnStrategy();
252
253 // user defined strategy (0, 1, 2, >=3)
254 explicit MnStrategy(unsigned int);
255
256 unsigned int GradientNCycles() const { return fGradNCyc; }
257 double GradientStepTolerance() const { return fGradTlrStp; }
258 double GradientTolerance() const { return fGradTlr; }
259
260 unsigned int HessianNCycles() const { return fHessNCyc; }
261 double HessianStepTolerance() const { return fHessTlrStp; }
262 double HessianG2Tolerance() const { return fHessTlrG2; }
263 unsigned int HessianGradientNCycles() const { return fHessGradNCyc; }
264 unsigned int HessianCentralFDMixedDerivatives() const { return fHessCFDG2; }
265 unsigned int HessianForcePosDef() const { return fHessForcePosDef; }
266
267 int StorageLevel() const { return fStoreLevel; }
268
269 bool RefineGradientInHessian() const { return fStrategy > 0; }
270
271 bool ComputeInitialHessian() const { return fStrategy == 2; }
272
273 double HessianRecomputeThreshold() const;
274
275 void SetGradientNCycles(unsigned int n) { fGradNCyc = n; }
278
279 void SetHessianNCycles(unsigned int n) { fHessNCyc = n; }
282 void SetHessianGradientNCycles(unsigned int n) { fHessGradNCyc = n; }
283
284 // 1 = calculate central finite difference mixed derivatives (involves 3 extra evaluations per derivative)
285 // 0 = use forward finite difference (default)
287
288 // 1 = returned matrix from Hesse should be forced positive definite (default)
289 // 0 = do not force matrix positive definite
291
292 // set storage level of iteration quantities
293 // 0 = store only last iterations 1 = full storage (default)
294 void SetStorageLevel(unsigned int level) { fStoreLevel = level; }
295
296private:
297 friend class MnFunctionCross;
298 friend class MnContours;
299 MnStrategy NextLower() const;
300
301 void SetLowStrategy();
302 void SetMediumStrategy();
303 void SetHighStrategy();
304 void SetVeryHighStrategy();
305
306 unsigned int fStrategy;
307
308 unsigned int fGradNCyc;
310 double fGradTlr;
311 unsigned int fHessNCyc;
314 unsigned int fHessGradNCyc;
318};
319
320} // namespace Minuit2
321
322} // namespace ROOT
323
324#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:247
double HessianG2Tolerance() const
Definition MnStrategy.h:262
unsigned int HessianGradientNCycles() const
Definition MnStrategy.h:263
unsigned int HessianCentralFDMixedDerivatives() const
Definition MnStrategy.h:264
bool RefineGradientInHessian() const
Definition MnStrategy.h:269
double GradientStepTolerance() const
Definition MnStrategy.h:257
void SetStorageLevel(unsigned int level)
Definition MnStrategy.h:294
void SetHessianNCycles(unsigned int n)
Definition MnStrategy.h:279
unsigned int HessianForcePosDef() const
Definition MnStrategy.h:265
void SetHessianStepTolerance(double stp)
Definition MnStrategy.h:280
bool ComputeInitialHessian() const
Definition MnStrategy.h:271
double GradientTolerance() const
Definition MnStrategy.h:258
void SetGradientTolerance(double toler)
Definition MnStrategy.h:277
double HessianStepTolerance() const
Definition MnStrategy.h:261
unsigned int HessianNCycles() const
Definition MnStrategy.h:260
unsigned int GradientNCycles() const
Definition MnStrategy.h:256
void SetHessianCentralFDMixedDerivatives(unsigned int flag)
Definition MnStrategy.h:286
void SetGradientNCycles(unsigned int n)
Definition MnStrategy.h:275
void SetHessianForcePosDef(unsigned int flag)
Definition MnStrategy.h:290
void SetGradientStepTolerance(double stp)
Definition MnStrategy.h:276
void SetHessianGradientNCycles(unsigned int n)
Definition MnStrategy.h:282
void SetHessianG2Tolerance(double toler)
Definition MnStrategy.h:281
double HessianRecomputeThreshold() const
MnStrategy NextLower() const
const Int_t n
Definition legend1.C:16