Logo ROOT  
Reference Guide
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 
14 #include "Minuit2/MinimumBuilder.h"
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"
26 #include "Minuit2/MnLineSearch.h"
28 #include "Minuit2/MnPrint.h"
29 
30 namespace ROOT {
31 
32 namespace Minuit2 {
33 
34 // #include "Minuit2/MnUserParametersPrint.h"
35 
36 FunctionMinimum 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 
46 FunctionMinimum 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
58 FunctionMinimum 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 
70 FunctionMinimum 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());
151  AnalyticalGradientCalculator gc(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
ROOT::Minuit2::MnMachinePrecision::Eps2
double Eps2() const
eps2 returns 2*sqrt(eps)
Definition: MnMachinePrecision.h:41
ROOT::Minuit2::MnFcn
Wrapper class to FCNBase interface used internally by Minuit.
Definition: MnFcn.h:30
ROOT::Minuit2::ModularFunctionMinimizer::SeedGenerator
virtual const MinimumSeedGenerator & SeedGenerator() const =0
ROOT::Minuit2::MnFcn::NumOfCalls
unsigned int NumOfCalls() const
Definition: MnFcn.h:39
MnStrategy.h
MnUserTransformation.h
FunctionMinimum.h
MinimumSeed.h
ROOT::Minuit2::FCNBase
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition: FCNBase.h:45
ModularFunctionMinimizer.h
MnUserParameterState.h
ROOT::Minuit2::MnUserCovariance
Class containing the covariance matrix data represented as a vector of size n*(n+1)/2 Used to hide in...
Definition: MnUserCovariance.h:26
ROOT::Minuit2::MnUserParameterState::VariableParameters
unsigned int VariableParameters() const
Definition: MnUserParameterState.cxx:506
MnUserParameters.h
Numerical2PGradientCalculator.h
ROOT::Minuit2::Numerical2PGradientCalculator
class performing the numerical gradient calculation
Definition: Numerical2PGradientCalculator.h:32
ROOT::Minuit2::MnPrint::Warn
void Warn(const Ts &... args)
Definition: MnPrint.h:126
MnParabolaPoint.h
ROOT::Minuit2::MnFcn::Up
double Up() const
Definition: MnFcn.cxx:39
ROOT::Minuit2::ModularFunctionMinimizer::Builder
virtual const MinimumBuilder & Builder() const =0
ROOT::Minuit2::MnUserParameters
API class for the user interaction with the parameters; serves as input to the minimizer as well as o...
Definition: MnUserParameters.h:36
FCNGradientBase.h
ROOT::Minuit2::MnUserParameterState::Trafo
const MnUserTransformation & Trafo() const
Definition: MnUserParameterState.h:104
ROOT::Minuit2::MnMachinePrecision
Sets the relative floating point (double) arithmetic precision.
Definition: MnMachinePrecision.h:32
MnUserCovariance.h
MnHesse.h
ROOT::Minuit2::MnUserFcn
Wrapper used by Minuit of FCN interface containing a reference to the transformation object.
Definition: MnUserFcn.h:25
AnalyticalGradientCalculator.h
ROOT::Minuit2::FunctionMinimum
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
Definition: FunctionMinimum.h:33
ROOT::Minuit2::AnalyticalGradientCalculator
Definition: AnalyticalGradientCalculator.h:22
ROOT::Minuit2::FCNGradientBase
Extension of the FCNBase for providing the analytical Gradient of the function.
Definition: FCNGradientBase.h:34
ROOT::Minuit2::MnUserParameterState
class which holds the external user and/or internal Minuit representation of the parameters and error...
Definition: MnUserParameterState.h:33
ROOT::Minuit2::MnStrategy
API class for defining three levels of strategies: low (0), medium (1), high (>=2); acts on: Migrad (...
Definition: MnStrategy.h:27
MnLineSearch.h
MinimumSeedGenerator.h
MnUserFcn.h
MinimumBuilder.h
FCNBase.h
MnPrint.h
ROOT::Minuit2::GradientCalculator
interface class for gradient calculators
Definition: GradientCalculator.h:23
ROOT::Minuit2::MinimumBuilder::Minimum
virtual FunctionMinimum Minimum(const MnFcn &, const GradientCalculator &, const MinimumSeed &, const MnStrategy &, unsigned int, double) const =0
ROOT::Minuit2::BasicFunctionMinimum::MnReachedCallLimit
Definition: BasicFunctionMinimum.h:36
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
ROOT::Minuit2::MinimumBuilder
Definition: MinimumBuilder.h:27
ROOT::Minuit2::MinimumSeed
MinimumSeed contains the starting values for the minimization produced by the SeedGenerator.
Definition: MinimumSeed.h:31
ROOT::Minuit2::MinimumSeed::State
const MinimumState & State() const
Definition: MinimumSeed.h:39
ROOT::Minuit2::MnPrint
Definition: MnPrint.h:73
ROOT::Minuit2::ModularFunctionMinimizer::Minimize
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
Definition: ModularFunctionMinimizer.cxx:36