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/MnUserFcn.h"
23#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
35 const MnStrategy &strategy, unsigned int maxfcn, double toler) const
36{
37 if (!fcn.HasGradient()) {
38 // minimize from a FCNBase and a MnUserparameterState - interface used by all the previous ones
39 // based on FCNBase. Create in this case a NumericalGradient calculator
40 // Create the minuit FCN wrapper (MnUserFcn) containing the transformation (int<->ext)
41
42 // need MnUserFcn for difference int-ext parameters
43 MnUserFcn mfcn(fcn, st.Trafo());
44 Numerical2PGradientCalculator gc(mfcn, st.Trafo(), strategy);
45
46 unsigned int npar = st.VariableParameters();
47 if (maxfcn == 0)
48 maxfcn = 200 + 100 * npar + 5 * npar * npar;
49 MinimumSeed mnseeds = SeedGenerator()(mfcn, gc, st, strategy);
50
51 return Minimize(mfcn, gc, mnseeds, strategy, maxfcn, toler);
52 }
53 // minimize from a function with gradient and a MnUserParameterState -
54 // interface based on function with gradient (external/analytical gradients)
55 // Create in this case an AnalyticalGradient calculator
56 // Create the minuit FCN wrapper (MnUserFcn) containing the transformation (int<->ext)
57
58 MnUserFcn mfcn(fcn, st.Trafo());
59 std::unique_ptr<AnalyticalGradientCalculator> gc;
61 // std::cout << "-- ModularFunctionMinimizer::Minimize: Internal parameter space" << std::endl;
62 gc = std::unique_ptr<AnalyticalGradientCalculator>(new ExternalInternalGradientCalculator(fcn, st.Trafo()));
63 } else {
64 // std::cout << "-- ModularFunctionMinimizer::Minimize: External parameter space" << std::endl;
65 gc = std::make_unique<AnalyticalGradientCalculator>(fcn, st.Trafo());
66 }
67
68 unsigned int npar = st.VariableParameters();
69 if (maxfcn == 0)
70 maxfcn = 200 + 100 * npar + 5 * npar * npar;
71
72 // compute seed (will use internally numerical gradient in case calculator does not implement g2 computations)
73 MinimumSeed mnseeds = SeedGenerator()(mfcn, *gc, st, strategy);
74 return Minimize(mfcn, *gc, mnseeds, strategy, maxfcn, toler);
75}
76
78 const MinimumSeed &seed, const MnStrategy &strategy,
79 unsigned int maxfcn, double toler) const
80{
81 // Interface used by all the others for the minimization using the base MinimumBuilder class
82 // According to the contained type of MinimumBuilder the right type will be used
83
84 MnPrint print("ModularFunctionMinimizer");
85
86 const MinimumBuilder &mb = Builder();
87 // std::cout << typeid(&mb).Name() << std::endl;
88 double effective_toler = toler * mfcn.Up(); // scale tolerance with Up()
89 // avoid tolerance too smalls (than limits)
90 double eps = MnMachinePrecision().Eps2();
91 if (effective_toler < eps)
92 effective_toler = eps;
93
94 // check if maxfcn is already exhausted
95 // case already reached call limit
96 if (mfcn.NumOfCalls() >= maxfcn) {
97 print.Warn("Stop before iterating - call limit already exceeded");
98
99 return FunctionMinimum(seed, std::vector<MinimumState>(1, seed.State()), mfcn.Up(),
101 }
102
103 return mb.Minimum(mfcn, gc, seed, strategy, maxfcn, effective_toler);
104}
105
106} // namespace Minuit2
107
108} // namespace ROOT
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void gc
Similar to the AnalyticalGradientCalculator, the ExternalInternalGradientCalculator supplies Minuit w...
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition FCNBase.h:51
virtual GradientParameterSpace gradParameterSpace() const
Definition FCNBase.h:122
virtual bool HasGradient() const
Definition FCNBase.h:113
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:28
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:135
API class for defining four levels of strategies: low (0), medium (1), high (2), very high (>=3); act...
Definition MnStrategy.h:27
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
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
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...