Logo ROOT   6.13/01
Reference Guide
FumiliMinimizer.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 
10 #include "Minuit2/MnConfig.h"
16 #include "Minuit2/MinimumBuilder.h"
17 #include "Minuit2/MinimumSeed.h"
22 #include "Minuit2/MnUserFcn.h"
23 #include "Minuit2/FumiliFCNBase.h"
24 #include "Minuit2/FumiliFCNBase.h"
27 #include "Minuit2/MnStrategy.h"
28 #include "Minuit2/MnPrint.h"
29 
30 namespace ROOT {
31 
32  namespace Minuit2 {
33 
34 
35 // for Fumili implement Minimize here because need downcast
36 
37 
38 FunctionMinimum FumiliMinimizer::Minimize(const FCNBase& fcn, const MnUserParameterState& st, const MnStrategy& strategy, unsigned int maxfcn, double toler) const {
39  // Minimize using Fumili. Create seed and Fumili gradient calculator.
40  // The FCNBase passed must be a FumiliFCNBase type otherwise method will fail !
41 
42  MnUserFcn mfcn(fcn, st.Trafo());
43  Numerical2PGradientCalculator gc(mfcn, st.Trafo(), strategy);
44 
45  unsigned int npar = st.VariableParameters();
46  if(maxfcn == 0) maxfcn = 200 + 100*npar + 5*npar*npar;
47  //FUMILI needs much less function calls
48  maxfcn = int(0.1*maxfcn);
49 
50  MinimumSeed mnseeds = SeedGenerator()(mfcn, gc, st, strategy);
51 
52  // downcast fcn
53 
54  //std::cout << "FCN type " << typeid(&fcn).Name() << std::endl;
55 
56  FumiliFCNBase * fumiliFcn = dynamic_cast< FumiliFCNBase *>( const_cast<FCNBase *>(&fcn) );
57  if ( !fumiliFcn ) {
58  MN_ERROR_MSG("FumiliMinimizer: Error : wrong FCN type. Try to use default minimizer");
59  return FunctionMinimum(mnseeds, fcn.Up() );
60  }
61 
62 
63  FumiliGradientCalculator fgc(*fumiliFcn, st.Trafo(), npar);
64 #ifdef DEBUG
65  std::cout << "Minuit::Minimize using FumiliMinimizer" << std::endl;
66 #endif
67  return ModularFunctionMinimizer::Minimize(mfcn, fgc, mnseeds, strategy, maxfcn, toler);
68 }
69 
70 
71 
72 FunctionMinimum FumiliMinimizer::Minimize(const FCNGradientBase& fcn, const MnUserParameterState& st, const MnStrategy& strategy, unsigned int maxfcn, double toler) const {
73  // Minimize using Fumili. Case of interface is a FCNGradientBase.
74  // Normally other method is used - probably this could be removed (t.b.i.)
75 
76  // need MnUserFcn
77  MnUserFcn mfcn(fcn, st.Trafo() );
78  AnalyticalGradientCalculator gc(fcn, st.Trafo());
79 
80  unsigned int npar = st.VariableParameters();
81  if(maxfcn == 0) maxfcn = 200 + 100*npar + 5*npar*npar;
82 
83  MinimumSeed mnseeds = SeedGenerator()(mfcn, gc, st, strategy);
84 
85  // downcast fcn
86 
87  FumiliFCNBase * fumiliFcn = dynamic_cast< FumiliFCNBase *>( const_cast<FCNGradientBase *>(&fcn) );
88  if ( !fumiliFcn ) {
89  MN_ERROR_MSG("FumiliMinimizer: Error : wrong FCN type. Try to use default minimizer");
90  return FunctionMinimum(mnseeds, fcn.Up() );
91  }
92 
93 
94  FumiliGradientCalculator fgc(*fumiliFcn, st.Trafo(), npar);
95 #ifdef DEBUG
96  std::cout << "Minuit::Minimize using FumiliMinimizer" << std::endl;
97 #endif
98  return ModularFunctionMinimizer::Minimize(mfcn, fgc, mnseeds, strategy, maxfcn, toler);
99 
100 }
101 
102  } // namespace Minuit2
103 
104 } // namespace ROOT
virtual double Up() const =0
Error definition of the function.
#define MN_ERROR_MSG(str)
Definition: MnPrint.h:113
Namespace for new ROOT classes and functions.
Definition: TFoamSampler.h:19
const MinimumSeedGenerator & SeedGenerator() const
Accessor to the seed generator of the minimizer.
MinimumSeed contains the starting values for the minimization produced by the SeedGenerator.
Definition: MinimumSeed.h:31
class performing the numerical gradient calculation
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) ...
const MnUserTransformation & Trafo() const
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition: FCNBase.h:47
class which holds the external user and/or internal Minuit representation of the parameters and error...
Wrapper used by Minuit of FCN interface containing a reference to the transformation object...
Definition: MnUserFcn.h:26
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
Extension of the FCNBase for the Fumili method.
Definition: FumiliFCNBase.h:47
API class for defining three levels of strategies: low (0), medium (1), high (>=2); acts on: Migrad (...
Definition: MnStrategy.h:27
FunctionMinimum Minimize(const FCNBase &, const MnUserParameterState &, const MnStrategy &, unsigned int maxfcn=0, double toler=0.1) const