Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ModularFunctionMinimizer.cxx
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
15#include "Minuit2/MinimumSeed.h"
21#include "Minuit2/MnUserFcn.h"
22#include "Minuit2/FCNBase.h"
24#include "Minuit2/MnStrategy.h"
25#include "Minuit2/MnHesse.h"
28#include "Minuit2/MnPrint.h"
29
30namespace ROOT {
31
32namespace Minuit2 {
33
34// #include "Minuit2/MnUserParametersPrint.h"
35
36FunctionMinimum ModularFunctionMinimizer::Minimize(const FCNBase &fcn, const std::vector<double> &par,
37 const std::vector<double> &err, unsigned int stra,
38 unsigned int maxfcn, double toler) const
39{
40 // minimize from FCNBase and std::vector of double's for parameter values and errors (step sizes)
41 MnUserParameterState st(par, err);
42 MnStrategy strategy(stra);
43 return Minimize(fcn, st, strategy, maxfcn, toler);
44}
45
46FunctionMinimum ModularFunctionMinimizer::Minimize(const FCNGradientBase &fcn, const std::vector<double> &par,
47 const std::vector<double> &err, unsigned int stra,
48 unsigned int maxfcn, double toler) const
49{
50 // minimize from FCNGradientBase (use analytical gradient provided in FCN)
51 // and std::vector of double's for parameter values and errors (step sizes)
52 MnUserParameterState st(par, err);
53 MnStrategy strategy(stra);
54 return Minimize(fcn, st, strategy, maxfcn, toler);
55}
56
57// move nrow before cov to avoid ambiguities when using default parameters
58FunctionMinimum ModularFunctionMinimizer::Minimize(const FCNBase &fcn, const std::vector<double> &par,
59 unsigned int nrow, const std::vector<double> &cov, unsigned int stra,
60 unsigned int maxfcn, double toler) const
61{
62 // minimize from FCNBase using std::vector for parameter error and
63 // an std::vector of size n*(n+1)/2 for the covariance matrix and n (rank of cov matrix)
64
65 MnUserParameterState st(par, cov, nrow);
66 MnStrategy strategy(stra);
67 return Minimize(fcn, st, strategy, maxfcn, toler);
68}
69
70FunctionMinimum ModularFunctionMinimizer::Minimize(const FCNGradientBase &fcn, const std::vector<double> &par,
71 unsigned int nrow, const std::vector<double> &cov, unsigned int stra,
72 unsigned int maxfcn, double toler) const
73{
74 // minimize from FCNGradientBase (use analytical gradient provided in FCN)
75 // using std::vector for parameter error and
76 // an std::vector of size n*(n+1)/2 for the covariance matrix and n (rank of cov matrix)
77
78 MnUserParameterState st(par, cov, nrow);
79 MnStrategy strategy(stra);
80 return Minimize(fcn, st, strategy, maxfcn, toler);
81}
82
84 const MnStrategy &strategy, unsigned int maxfcn, double toler) const
85{
86 // minimize from FCNBase and MnUserParameters object
87
88 MnUserParameterState st(upar);
89 return Minimize(fcn, st, strategy, maxfcn, toler);
90}
91
93 const MnStrategy &strategy, unsigned int maxfcn, double toler) const
94{
95 // minimize from FCNGradientBase (use analytical gradient provided in FCN) and MnUserParameters object
96
97 MnUserParameterState st(upar);
98 return Minimize(fcn, st, strategy, maxfcn, toler);
99}
100
102 const MnUserCovariance &cov, const MnStrategy &strategy,
103 unsigned int maxfcn, double toler) const
104{
105 // minimize from FCNBase and MnUserParameters and MnUserCovariance objects
106
107 MnUserParameterState st(upar, cov);
108 return Minimize(fcn, st, strategy, maxfcn, toler);
109}
110
112 const MnUserCovariance &cov, const MnStrategy &strategy,
113 unsigned int maxfcn, double toler) const
114{
115 // minimize from FCNGradientBase (use analytical gradient provided in FCN) and
116 // MnUserParameters MnUserCovariance objects
117
118 MnUserParameterState st(upar, cov);
119 return Minimize(fcn, st, strategy, maxfcn, toler);
120}
121
123 const MnStrategy &strategy, unsigned int maxfcn, double toler) const
124{
125 // minimize from a FCNBase and a MnUserparameterState - interface used by all the previous ones
126 // based on FCNBase. Create in this case a NumericalGradient calculator
127 // Create the minuit FCN wrapper (MnUserFcn) containing the trasformation (int<->ext)
128
129 // neeed MnUsserFcn for difference int-ext parameters
130 MnUserFcn mfcn(fcn, st.Trafo());
131 Numerical2PGradientCalculator gc(mfcn, st.Trafo(), strategy);
132
133 unsigned int npar = st.VariableParameters();
134 if (maxfcn == 0)
135 maxfcn = 200 + 100 * npar + 5 * npar * npar;
136 MinimumSeed mnseeds = SeedGenerator()(mfcn, gc, st, strategy);
137
138 return Minimize(mfcn, gc, mnseeds, strategy, maxfcn, toler);
139}
140
141// use Gradient here
143 const MnStrategy &strategy, unsigned int maxfcn, double toler) const
144{
145 // minimize from a FCNGradientBase and a MnUserparameterState - interface used by all the previous ones
146 // based on FCNGradientBase.
147 // Create in this acase an AnalyticalGradient calculator
148 // Create the minuit FCN wrapper (MnUserFcn) containing the trasformation (int<->ext)
149
150 MnUserFcn mfcn(fcn, st.Trafo());
152
153 unsigned int npar = st.VariableParameters();
154 if (maxfcn == 0)
155 maxfcn = 200 + 100 * npar + 5 * npar * npar;
156
157 // use numerical gradient to compute initial derivatives for SeedGenerator
158 Numerical2PGradientCalculator numgc(mfcn, st.Trafo(), strategy);
159 MinimumSeed mnseeds = SeedGenerator()(mfcn, numgc, st, strategy);
160
161 return Minimize(mfcn, gc, mnseeds, strategy, maxfcn, toler);
162}
163
165 const MinimumSeed &seed, const MnStrategy &strategy,
166 unsigned int maxfcn, double toler) const
167{
168 // Interface used by all the others for the minimization using the base MinimumBuilder class
169 // According to the contained type of MinimumBuilder the right type will be used
170
171 MnPrint print("ModularFunctionMinimizer");
172
173 const MinimumBuilder &mb = Builder();
174 // std::cout << typeid(&mb).Name() << std::endl;
175 double effective_toler = toler * mfcn.Up(); // scale tolerance with Up()
176 // avoid tolerance too smalls (than limits)
177 double eps = MnMachinePrecision().Eps2();
178 if (effective_toler < eps)
179 effective_toler = eps;
180
181 // check if maxfcn is already exhausted
182 // case already reached call limit
183 if (mfcn.NumOfCalls() >= maxfcn) {
184 print.Warn("Stop before iterating - call limit already exceeded");
185
186 return FunctionMinimum(seed, std::vector<MinimumState>(1, seed.State()), mfcn.Up(),
188 }
189
190 return mb.Minimum(mfcn, gc, seed, strategy, maxfcn, effective_toler);
191}
192
193} // namespace Minuit2
194
195} // namespace ROOT
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition FCNBase.h:45
Extension of the FCNBase for providing the analytical Gradient of the function.
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
interface class for gradient calculators
virtual FunctionMinimum Minimum(const MnFcn &, const GradientCalculator &, const MinimumSeed &, const MnStrategy &, unsigned int, double) const =0
MinimumSeed contains the starting values for the minimization produced by the SeedGenerator.
Definition MinimumSeed.h:31
const MinimumState & State() const
Definition MinimumSeed.h:39
Wrapper class to FCNBase interface used internally by Minuit.
Definition MnFcn.h:30
double Up() const
Definition MnFcn.cxx:39
unsigned int NumOfCalls() const
Definition MnFcn.h:39
Sets the relative floating point (double) arithmetic precision.
double Eps2() const
eps2 returns 2*sqrt(eps)
void Warn(const Ts &... args)
Definition MnPrint.h:126
API class for defining three levels of strategies: low (0), medium (1), high (>=2); acts on: Migrad (...
Definition MnStrategy.h:27
Class containing the covariance matrix data represented as a vector of size n*(n+1)/2 Used to hide in...
Wrapper used by Minuit of FCN interface containing a reference to the transformation object.
Definition MnUserFcn.h:25
class which holds the external user and/or internal Minuit representation of the parameters and error...
const MnUserTransformation & Trafo() const
API class for the user interaction with the parameters; serves as input to the minimizer as well as o...
virtual const MinimumBuilder & Builder() const =0
virtual FunctionMinimum Minimize(const FCNBase &, const std::vector< double > &, const std::vector< double > &, unsigned int stra=1, unsigned int maxfcn=0, double toler=0.1) const
virtual const MinimumSeedGenerator & SeedGenerator() const =0
class performing the numerical gradient calculation
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...