ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #ifndef ROOT_Math_Minimizer
17 #include "Math/Minimizer.h"
18 #endif
19 
20 #ifndef ROOT_Math_FitMethodFunction
21 #include "Math/FitMethodFunction.h"
22 #endif
23 
24 #ifndef ROOT_Rtypes
25 #include "Rtypes.h"
26 #endif
27 
28 class TFumili;
29 
30 
31 
32 // namespace ROOT {
33 
34 // namespace Math {
35 
36 // class BasicFitMethodFunction<ROOT::Math::IMultiGenFunction>;
37 // class BasicFitMethodFunction<ROOT::Math::IMultiGradFunction>;
38 
39 // }
40 // }
41 
42 
43 
44 /**
45  TFumiliMinimizer class: minimizer implementation based on TFumili.
46 */
48 
49 public:
50 
51  /**
52  Default constructor (an argument is needed by plug-in manager)
53  */
54  TFumiliMinimizer (int dummy=0 );
55 
56 
57  /**
58  Destructor (no operations)
59  */
61 
62 private:
63  // usually copying is non trivial, so we make this unaccessible
64 
65  /**
66  Copy constructor
67  */
69 
70  /**
71  Assignment operator
72  */
74 
75 public:
76 
77  /// set the function to minimize
78  virtual void SetFunction(const ROOT::Math::IMultiGenFunction & func);
79 
80  /// set the function to minimize
81  virtual void SetFunction(const ROOT::Math::IMultiGradFunction & func);
82 
83  /// set free variable
84  virtual bool SetVariable(unsigned int ivar, const std::string & name, double val, double step);
85 
86  /// set upper/lower limited variable (override if minimizer supports them )
87  virtual bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double /* lower */, double /* upper */);
88 
89 #ifdef LATER
90  /// set lower limit variable (override if minimizer supports them )
91  virtual bool SetLowerLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double lower );
92  /// set upper limit variable (override if minimizer supports them )
93  virtual bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper );
94 #endif
95 
96  /// set fixed variable (override if minimizer supports them )
97  virtual bool SetFixedVariable(unsigned int /* ivar */, const std::string & /* name */, double /* val */);
98 
99  /// set the value of an existing variable
100  virtual bool SetVariableValue(unsigned int ivar, double val );
101 
102  /// method to perform the minimization
103  virtual bool Minimize();
104 
105  /// return minimum function value
106  virtual double MinValue() const { return fMinVal; }
107 
108  /// return expected distance reached from the minimum
109  virtual double Edm() const { return fEdm; }
110 
111  /// return pointer to X values at the minimum
112  virtual const double * X() const { return &fParams.front(); }
113 
114  /// return pointer to gradient values at the minimum
115  virtual const double * MinGradient() const { return 0; } // not available
116 
117  /// number of function calls to reach the minimum
118  virtual unsigned int NCalls() const { return 0; }
119 
120  /// this is <= Function().NDim() which is the total
121  /// number of variables (free+ constrained ones)
122  virtual unsigned int NDim() const { return fDim; }
123 
124  /// number of free variables (real dimension of the problem)
125  /// this is <= Function().NDim() which is the total
126  virtual unsigned int NFree() const { return fNFree; }
127 
128  /// minimizer provides error and error matrix
129  virtual bool ProvidesError() const { return true; }
130 
131  /// return errors at the minimum
132  virtual const double * Errors() const { return &fErrors.front(); }
133 
134  /** return covariance matrices elements
135  if the variable is fixed the matrix is zero
136  The ordering of the variables is the same as in errors
137  */
138  virtual double CovMatrix(unsigned int i, unsigned int j) const {
139  return fCovar[i + fDim* j];
140  }
141 
142  /*
143  return covariance matrix status
144  */
145  virtual int CovMatrixStatus() const {
146  if (fCovar.size() == 0) return 0;
147  return (fStatus ==0) ? 3 : 1;
148  }
149 
150 
151 
152 
153 
154 protected:
155 
156  /// implementation of FCN for Fumili
157  static void Fcn( int &, double * , double & f, double * , int);
158  /// implementation of FCN for Fumili when user provided gradient is used
159  //static void FcnGrad( int &, double * g, double & f, double * , int);
160 
161  /// static function implementing the evaluation of the FCN (it uses static instance fgFumili)
162  static double EvaluateFCN(const double * x, double * g);
163 
164 private:
165 
166 
167  unsigned int fDim;
168  unsigned int fNFree;
169  double fMinVal;
170  double fEdm;
171  std::vector<double> fParams;
172  std::vector<double> fErrors;
173  std::vector<double> fCovar;
174 
176 
177  // need to have a static copy of the function
178  //NOTE: This is NOT thread safe.
181 
182  static TFumili * fgFumili; // static instance (used by fcn function)
183 
184  ClassDef(TFumiliMinimizer,1) //Implementation of Minimizer interface using TFumili
185 
186 };
187 
188 
189 
190 #endif /* ROOT_TFumiliMinimizer */
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:322
virtual unsigned int NCalls() const
number of function calls to reach the minimum
virtual bool ProvidesError() const
minimizer provides error and error matrix
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...
static double EvaluateFCN(const double *x, double *g)
implementation of FCN for Fumili when user provided gradient is used
virtual unsigned int NFree() const
number of free variables (real dimension of the problem) this is <= Function().NDim() which is the to...
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:163
TFumiliMinimizer class: minimizer implementation based on TFumili.
static const float upper
Definition: main.cpp:49
static ROOT::Math::FitMethodFunction * fgFunc
TFumiliMinimizer(int dummy=0)
Default constructor (an argument is needed by plug-in manager)
TFile * f
virtual const double * Errors() const
return errors at the minimum
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual const double * MinGradient() const
return pointer to gradient values at the minimum
std::vector< double > fParams
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2, Minuit, GSL, etc..) Plug-in'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:86
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
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 * X() const
return pointer to X values at the minimum
~TFumiliMinimizer()
Destructor (no operations)
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:167
FitMethodFunction class Interface for objective functions (like chi2 and likelihood used in the fit) ...
Definition: Fitter.h:57
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
virtual int CovMatrixStatus() const
return status of covariance matrix using Minuit convention {0 not calculated 1 approximated 2 made po...
#define name(a, b)
Definition: linkTestLib0.cpp:5
static ROOT::Math::FitMethodGradFunction * fgGradFunc
static TFumili * fgFumili
std::vector< double > fErrors
TFumiliMinimizer & operator=(const TFumiliMinimizer &rhs)
Assignment operator.
unsigned int fNFree
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:63
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 double MinValue() const
return minimum function value
virtual unsigned int NDim() const
this is <= Function().NDim() which is the total number of variables (free+ constrained ones) ...
static const float lower
Definition: main.cpp:48
virtual double Edm() const
return expected distance reached from the minimum