Logo ROOT   6.10/09
Reference Guide
TFumiliMinimizer.h
Go to the documentation of this file.
1 // @(#)root/fumili:$Id$
2 // Author: L. Moneta Wed Oct 25 16:28:55 2006
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Header file for class TFumiliMinimizer
12 
13 #ifndef ROOT_TFumiliMinimizer
14 #define ROOT_TFumiliMinimizer
15 
16 #include "Math/Minimizer.h"
17 
18 #include "Math/FitMethodFunction.h"
19 
20 #include "Rtypes.h"
21 
22 class TFumili;
23 
24 
25 
26 // namespace ROOT {
27 
28 // namespace Math {
29 
30 // class BasicFitMethodFunction<ROOT::Math::IMultiGenFunction>;
31 // class BasicFitMethodFunction<ROOT::Math::IMultiGradFunction>;
32 
33 // }
34 // }
35 
36 
37 
38 /**
39  TFumiliMinimizer class: minimizer implementation based on TFumili.
40 */
42 
43 public:
44 
45  /**
46  Default constructor (an argument is needed by plug-in manager)
47  */
48  TFumiliMinimizer (int dummy=0 );
49 
50 
51  /**
52  Destructor (no operations)
53  */
55 
56 private:
57  // usually copying is non trivial, so we make this unaccessible
58 
59  /**
60  Copy constructor
61  */
63 
64  /**
65  Assignment operator
66  */
68 
69 public:
70 
71  /// set the function to minimize
72  virtual void SetFunction(const ROOT::Math::IMultiGenFunction & func);
73 
74  /// set the function to minimize
75  virtual void SetFunction(const ROOT::Math::IMultiGradFunction & func);
76 
77  /// set free variable
78  virtual bool SetVariable(unsigned int ivar, const std::string & name, double val, double step);
79 
80  /// set upper/lower limited variable (override if minimizer supports them )
81  virtual bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double /* lower */, double /* upper */);
82 
83 #ifdef LATER
84  /// set lower limit variable (override if minimizer supports them )
85  virtual bool SetLowerLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double lower );
86  /// set upper limit variable (override if minimizer supports them )
87  virtual bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper );
88 #endif
89 
90  /// set fixed variable (override if minimizer supports them )
91  virtual bool SetFixedVariable(unsigned int /* ivar */, const std::string & /* name */, double /* val */);
92 
93  /// set the value of an existing variable
94  virtual bool SetVariableValue(unsigned int ivar, double val );
95 
96  /// method to perform the minimization
97  virtual bool Minimize();
98 
99  /// return minimum function value
100  virtual double MinValue() const { return fMinVal; }
101 
102  /// return expected distance reached from the minimum
103  virtual double Edm() const { return fEdm; }
104 
105  /// return pointer to X values at the minimum
106  virtual const double * X() const { return &fParams.front(); }
107 
108  /// return pointer to gradient values at the minimum
109  virtual const double * MinGradient() const { return 0; } // not available
110 
111  /// number of function calls to reach the minimum
112  virtual unsigned int NCalls() const { return 0; }
113 
114  /// this is <= Function().NDim() which is the total
115  /// number of variables (free+ constrained ones)
116  virtual unsigned int NDim() const { return fDim; }
117 
118  /// number of free variables (real dimension of the problem)
119  /// this is <= Function().NDim() which is the total
120  virtual unsigned int NFree() const { return fNFree; }
121 
122  /// minimizer provides error and error matrix
123  virtual bool ProvidesError() const { return true; }
124 
125  /// return errors at the minimum
126  virtual const double * Errors() const { return &fErrors.front(); }
127 
128  /** return covariance matrices elements
129  if the variable is fixed the matrix is zero
130  The ordering of the variables is the same as in errors
131  */
132  virtual double CovMatrix(unsigned int i, unsigned int j) const {
133  return fCovar[i + fDim* j];
134  }
135 
136  /*
137  return covariance matrix status
138  */
139  virtual int CovMatrixStatus() const {
140  if (fCovar.size() == 0) return 0;
141  return (fStatus ==0) ? 3 : 1;
142  }
143 
144 
145 
146 
147 
148 protected:
149 
150  /// implementation of FCN for Fumili
151  static void Fcn( int &, double * , double & f, double * , int);
152  /// implementation of FCN for Fumili when user provided gradient is used
153  //static void FcnGrad( int &, double * g, double & f, double * , int);
154 
155  /// static function implementing the evaluation of the FCN (it uses static instance fgFumili)
156  static double EvaluateFCN(const double * x, double * g);
157 
158 private:
159 
160 
161  unsigned int fDim;
162  unsigned int fNFree;
163  double fMinVal;
164  double fEdm;
165  std::vector<double> fParams;
166  std::vector<double> fErrors;
167  std::vector<double> fCovar;
168 
170 
171  // need to have a static copy of the function
172  //NOTE: This is NOT thread safe.
175 
176  static TFumili * fgFumili; // static instance (used by fcn function)
177 
178  ClassDef(TFumiliMinimizer,1) //Implementation of Minimizer interface using TFumili
179 
180 };
181 
182 
183 
184 #endif /* ROOT_TFumiliMinimizer */
virtual double CovMatrix(unsigned int i, unsigned int j) const
return covariance matrices elements if the variable is fixed the matrix is zero The ordering of the v...
virtual bool SetVariable(unsigned int ivar, const std::string &name, double val, double step)
set free variable
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
Definition: IFunction.h:330
virtual double MinValue() const
return minimum function value
virtual double Edm() const
return expected distance reached from the minimum
virtual unsigned int NDim() const
this is <= Function().NDim() which is the total number of variables (free+ constrained ones) ...
static double EvaluateFCN(const double *x, double *g)
implementation of FCN for Fumili when user provided gradient is used
virtual bool SetLowerLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double lower)
set a new lower limit variable (override if minimizer supports them )
Definition: Minimizer.h:155
TFumiliMinimizer class: minimizer implementation based on TFumili.
static ROOT::Math::FitMethodFunction * fgFunc
TFumiliMinimizer(int dummy=0)
Default constructor (an argument is needed by plug-in manager)
virtual bool ProvidesError() const
minimizer provides error and error matrix
Double_t x[n]
Definition: legend1.C:17
virtual const double * Errors() const
return errors at the minimum
#define ClassDef(name, id)
Definition: Rtypes.h:297
std::vector< double > fParams
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2, Minuit, GSL, etc..) Plug-in&#39;s exist in ROOT to be able to instantiate the derived classes like ROOT::Math::GSLMinimizer or ROOT::Math::Minuit2Minimizer via the plug-in manager.
Definition: Minimizer.h:78
virtual bool SetFixedVariable(unsigned int, const std::string &, double)
set fixed variable (override if minimizer supports them )
virtual bool Minimize()
method to perform the minimization
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:62
virtual bool SetLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double, double)
set upper/lower limited variable (override if minimizer supports them )
std::vector< double > fCovar
virtual const double * MinGradient() const
return pointer to gradient values at the minimum
~TFumiliMinimizer()
Destructor (no operations)
virtual unsigned int NCalls() const
number of function calls to reach the minimum
virtual bool SetUpperLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double upper)
set a new upper limit variable (override if minimizer supports them )
Definition: Minimizer.h:159
double f(double x)
FitMethodFunction class Interface for objective functions (like chi2 and likelihood used in the fit) ...
Definition: Fitter.h:40
virtual void SetFunction(const ROOT::Math::IMultiGenFunction &func)
set the function to minimize
static RooMathCoreReg dummy
double func(double *x, double *p)
Definition: stressTF1.cxx:213
static ROOT::Math::FitMethodGradFunction * fgGradFunc
static TFumili * fgFumili
std::vector< double > fErrors
TFumiliMinimizer & operator=(const TFumiliMinimizer &rhs)
Assignment operator.
unsigned int fNFree
virtual const double * X() const
return pointer to X values at the minimum
virtual int CovMatrixStatus() const
return status of covariance matrix using Minuit convention {0 not calculated 1 approximated 2 made po...
virtual bool SetVariableValue(unsigned int ivar, double val)
set the value of an existing variable
static void Fcn(int &, double *, double &f, double *, int)
implementation of FCN for Fumili
virtual unsigned int NFree() const
number of free variables (real dimension of the problem) this is <= Function().NDim() which is the to...