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, E.G.P. Bos 2003-2017
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT *
7 * *
8 **********************************************************************/
9
16#include "Minuit2/MinimumSeed.h"
22#include "Minuit2/FCNBase.h"
23#include "Minuit2/MnStrategy.h"
25#include "Minuit2/MnPrint.h"
26#include "Minuit2/MnFcn.h"
27
28namespace ROOT {
29
30namespace Minuit2 {
31
33 const MnStrategy &strategy, unsigned int maxfcn, double toler) const
34{
35 // need wrapper for difference int-ext parameters
36 MnFcn mfcn{fcn, st.Trafo()};
37 std::unique_ptr<GradientCalculator> gc;
38
39 if (!fcn.HasGradient()) {
40 // minimize from a FCNBase and a MnUserparameterState - interface used by all the previous ones
41 // based on FCNBase. Create in this case a NumericalGradient calculator
42 gc = std::make_unique<Numerical2PGradientCalculator>(mfcn, st.Trafo(), strategy);
44 // minimize from a function with gradient and a MnUserParameterState -
45 // interface based on function with gradient (external/analytical gradients)
46 // Create in this case an AnalyticalGradient calculator
47 gc = std::make_unique<ExternalInternalGradientCalculator>(fcn, st.Trafo());
48 } else {
49 gc = std::make_unique<AnalyticalGradientCalculator>(fcn, st.Trafo());
50 }
51
52 unsigned int npar = st.VariableParameters();
53 if (maxfcn == 0)
54 maxfcn = 200 + 100 * npar + 5 * npar * npar;
56 // compute seed (will use internally numerical gradient in case calculator does not implement g2 computations)
57 MinimumSeed mnseeds = SeedGenerator()(mfcn, *gc, st, strategy);
58 return Minimize(mfcn, *gc, mnseeds, strategy, maxfcn, toler);
59}
60
62 const MinimumSeed &seed, const MnStrategy &strategy,
63 unsigned int maxfcn, double toler) const
64{
65 // Interface used by all the others for the minimization using the base MinimumBuilder class
66 // According to the contained type of MinimumBuilder the right type will be used
67
68 MnPrint print("ModularFunctionMinimizer");
69
70 const MinimumBuilder &mb = Builder();
71 // std::cout << typeid(&mb).Name() << std::endl;
72 double effective_toler = toler * mfcn.Up(); // scale tolerance with Up()
73 // avoid tolerance too smalls (than limits)
74 double eps = MnMachinePrecision().Eps2();
75 if (effective_toler < eps)
76 effective_toler = eps;
77
78 // check if maxfcn is already exhausted
79 // case already reached call limit
80 if (mfcn.NumOfCalls() >= maxfcn) {
81 print.Warn("Stop before iterating - call limit already exceeded");
82
83 return FunctionMinimum(seed, std::vector<MinimumState>(1, seed.State()), mfcn.Up(),
85 }
86
87 return mb.Minimum(mfcn, gc, seed, strategy, maxfcn, effective_toler);
88}
89
90} // namespace Minuit2
91
92} // namespace ROOT
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition FCNBase.h:37
virtual GradientParameterSpace gradParameterSpace() const
Definition FCNBase.h:107
virtual bool HasGradient() const
Definition FCNBase.h:86
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
const MinimumState & State() const
Definition MinimumSeed.h:29
Wrapper class to FCNBase interface used internally by Minuit.
Definition MnFcn.h:34
double Up() const
Definition MnFcn.h:50
unsigned int NumOfCalls() const
Definition MnFcn.h:43
Sets the relative floating point (double) arithmetic precision.
double Eps2() const
eps2 returns 2*sqrt(eps)
void Warn(const Ts &... args)
Definition MnPrint.h:123
API class for defining four levels of strategies: low (0), medium (1), high (2), very high (>=3); act...
Definition MnStrategy.h:27
class which holds the external user and/or internal Minuit representation of the parameters and error...
const MnUserTransformation & Trafo() const
virtual const MinimumBuilder & Builder() const =0
virtual const MinimumSeedGenerator & SeedGenerator() const =0
virtual FunctionMinimum Minimize(const FCNBase &, const MnUserParameterState &, const MnStrategy &=MnStrategy{1}, unsigned int maxfcn=0, double toler=0.1) const