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);
43 } else if (fcn.gradParameterSpace() == GradientParameterSpace::Internal) {
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)
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
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void gc
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition FCNBase.h:49
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
interface class for gradient calculators
const MinimumState & State() const
Definition MinimumSeed.h:29
Wrapper class to FCNBase interface used internally by Minuit.
Definition MnFcn.h:34
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...
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
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...