ROOT  6.06/09
Reference Guide
BasicMinimizer.h
Go to the documentation of this file.
1 // @(#)root/mathmore:$Id$
2 // Author: L. Moneta Oct 2012
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 
11 
12 // Header file for class BasicMinimizer
13 
14 #ifndef ROOT_Math_BasicMinimizer
15 #define ROOT_Math_BasicMinimizer
16 
17 #ifndef ROOT_Math_Minimizer
18 #include "Math/Minimizer.h"
19 #endif
20 
21 
22 #ifndef ROOT_Math_IFunctionfwd
23 #include "Math/IFunctionfwd.h"
24 #endif
25 
26 #ifndef ROOT_Math_IParamFunctionfwd
27 #include "Math/IParamFunctionfwd.h"
28 #endif
29 
30 #ifndef ROOT_Math_MinimTransformVariable
32 #endif
33 
34 
35 #include <vector>
36 #include <map>
37 #include <string>
38 
39 
40 
41 namespace ROOT {
42 
43 namespace Math {
44 
45  class MinimTransformFunction;
46 
47 
48 
49 //_______________________________________________________________________________
50 /**
51  Base Minimizer class, which defines the basic funcionality of various minimizer
52  implementations (apart from Minuit and Minuit2)
53  It provides support for storing parameter values, step size,
54  parameter transofrmation etc.. in case real minimizer impelmentations do not provide
55  such functionality.
56  This is an internal class and should not be used directly by the user
57 
58  @ingroup MultiMin
59 */
60 
61 
63 
64 public:
65 
66  /**
67  Default constructor
68  */
69  BasicMinimizer ( );
70 
71 
72  /**
73  Destructor
74  */
75  virtual ~BasicMinimizer ();
76 
77 private:
78  // usually copying is non trivial, so we make this unaccessible
79 
80  /**
81  Copy constructor
82  */
84 
85  /**
86  Assignment operator
87  */
89  if (this == &rhs) return *this; // time saving self-test
90  return *this;
91  }
92 
93 public:
94 
95  /// set the function to minimize
96  virtual void SetFunction(const ROOT::Math::IMultiGenFunction & func);
97 
98  /// set gradient the function to minimize
99  virtual void SetFunction(const ROOT::Math::IMultiGradFunction & func);
100 
101  /// set free variable
102  virtual bool SetVariable(unsigned int ivar, const std::string & name, double val, double step);
103 
104 
105  /// set lower limit variable (override if minimizer supports them )
106  virtual bool SetLowerLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double lower );
107  /// set upper limit variable (override if minimizer supports them )
108  virtual bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper );
109  /// set upper/lower limited variable (override if minimizer supports them )
110  virtual bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double /* lower */, double /* upper */);
111  /// set fixed variable (override if minimizer supports them )
112  virtual bool SetFixedVariable(unsigned int /* ivar */, const std::string & /* name */, double /* val */);
113  /// set the value of an existing variable
114  virtual bool SetVariableValue(unsigned int ivar, double val );
115  /// set the values of all existing variables (array must be dimensioned to the size of existing parameters)
116  virtual bool SetVariableValues(const double * x);
117  /// set the step size of an already existing variable
118  virtual bool SetVariableStepSize(unsigned int ivar, double step );
119  /// set the lower-limit of an already existing variable
120  virtual bool SetVariableLowerLimit(unsigned int ivar, double lower);
121  /// set the upper-limit of an already existing variable
122  virtual bool SetVariableUpperLimit(unsigned int ivar, double upper);
123  /// set the limits of an already existing variable
124  virtual bool SetVariableLimits(unsigned int ivar, double lower, double upper);
125  /// fix an existing variable
126  virtual bool FixVariable(unsigned int ivar);
127  /// release an existing variable
128  virtual bool ReleaseVariable(unsigned int ivar);
129  /// query if an existing variable is fixed (i.e. considered constant in the minimization)
130  /// note that by default all variables are not fixed
131  virtual bool IsFixedVariable(unsigned int ivar) const;
132  /// get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
133  virtual bool GetVariableSettings(unsigned int ivar, ROOT::Fit::ParameterSettings & varObj) const;
134  /// get name of variables (override if minimizer support storing of variable names)
135  virtual std::string VariableName(unsigned int ivar) const;
136  /// get index of variable given a variable given a name
137  /// return -1 if variable is not found
138  virtual int VariableIndex(const std::string & name) const;
139 
140  /// method to perform the minimization
141  virtual bool Minimize();
142 
143  /// return minimum function value
144  virtual double MinValue() const { return fMinVal; }
145 
146  /// return pointer to X values at the minimum
147  virtual const double * X() const { return &fValues.front(); }
148 
149  /// number of dimensions
150  virtual unsigned int NDim() const { return fDim; }
151 
152  /// number of free variables (real dimension of the problem)
153  virtual unsigned int NFree() const;
154 
155  /// total number of parameter defined
156  virtual unsigned int NPar() const { return fValues.size(); }
157 
158  /// return pointer to used objective function
160 
161  /// return pointer to used gradient object function (NULL if gradient is not supported)
163 
164  /// return transformation function (NULL if not having a transformation)
166 
167  /// print result of minimization
168  void PrintResult() const;
169 
170  /// accessor methods
171  virtual const double * StepSizes() const { return &fSteps.front(); }
172 
173 protected:
174 
175  bool CheckDimension() const;
176 
177  bool CheckObjFunction() const;
178 
179  MinimTransformFunction * CreateTransformation(std::vector<double> & startValues, const ROOT::Math::IMultiGradFunction * func = 0);
180 
181  void SetFinalValues(const double * x);
182 
183  void SetMinValue(double val) { fMinVal = val; }
184 
185 private:
186 
187  // dimension of the function to be minimized
188  unsigned int fDim;
189 
191 
192  double fMinVal;
193  std::vector<double> fValues;
194  std::vector<double> fSteps;
195  std::vector<std::string> fNames;
196  std::vector<ROOT::Math::EMinimVariableType> fVarTypes; // vector specifyng the type of variables
197  std::map< unsigned int, std::pair<double, double> > fBounds; // map specifying the bound using as key the parameter index
198 
199 };
200 
201  } // end namespace Fit
202 
203 } // end namespace ROOT
204 
205 
206 
207 #endif /* ROOT_Math_BasicMinimizer */
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
Definition: IFunction.h:322
virtual bool SetVariableUpperLimit(unsigned int ivar, double upper)
set the upper-limit of an already existing variable
std::vector< ROOT::Math::EMinimVariableType > fVarTypes
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
virtual bool SetVariableStepSize(unsigned int ivar, double step)
set the step size of an already existing variable
virtual bool SetFixedVariable(unsigned int, const std::string &, double)
set fixed variable (override if minimizer supports them )
virtual int VariableIndex(const std::string &name) const
get index of variable given a variable given a name return -1 if variable is not found ...
virtual bool SetUpperLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double upper)
set upper limit variable (override if minimizer supports them )
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
virtual bool SetVariableValues(const double *x)
set the values of all existing variables (array must be dimensioned to the size of existing parameter...
BasicMinimizer(const BasicMinimizer &)
Copy constructor.
void PrintResult() const
print result of minimization
MinimTransformFunction class to perform a transformations on the variables to deal with fixed or limi...
virtual bool SetVariableLowerLimit(unsigned int ivar, double lower)
set the lower-limit of an already existing variable
Base Minimizer class, which defines the basic funcionality of various minimizer implementations (apar...
MinimTransformFunction * CreateTransformation(std::vector< double > &startValues, const ROOT::Math::IMultiGradFunction *func=0)
virtual bool SetVariableLimits(unsigned int ivar, double lower, double upper)
set the limits of an already existing variable
virtual bool SetVariable(unsigned int ivar, const std::string &name, double val, double step)
set free variable
virtual bool SetLowerLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double lower)
set lower limit variable (override if minimizer supports them )
const ROOT::Math::IMultiGenFunction * fObjFunc
static const float upper
Definition: main.cpp:49
virtual bool GetVariableSettings(unsigned int ivar, ROOT::Fit::ParameterSettings &varObj) const
get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
Double_t x[n]
Definition: legend1.C:17
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
void SetMinValue(double val)
std::vector< double > fValues
std::map< unsigned int, std::pair< double, double > > fBounds
std::vector< double > fSteps
virtual unsigned int NDim() const
number of dimensions
virtual bool Minimize()
method to perform the minimization
void SetFinalValues(const double *x)
const ROOT::Math::MinimTransformFunction * TransformFunction() const
return transformation function (NULL if not having a transformation)
virtual double MinValue() const
return minimum function value
virtual std::string VariableName(unsigned int ivar) const
get name of variables (override if minimizer support storing of variable names)
virtual const double * X() const
return pointer to X values at the minimum
virtual bool FixVariable(unsigned int ivar)
fix an existing variable
virtual void SetFunction(const ROOT::Math::IMultiGenFunction &func)
set the function to minimize
const ROOT::Math::IMultiGradFunction * GradObjFunction() const
return pointer to used gradient object function (NULL if gradient is not supported) ...
virtual unsigned int NPar() const
total number of parameter defined
const ROOT::Math::IMultiGenFunction * ObjFunction() const
return pointer to used objective function
virtual unsigned int NFree() const
number of free variables (real dimension of the problem)
double func(double *x, double *p)
Definition: stressTF1.cxx:213
Namespace for new Math classes and functions.
#define name(a, b)
Definition: linkTestLib0.cpp:5
BasicMinimizer & operator=(const BasicMinimizer &rhs)
Assignment operator.
virtual bool ReleaseVariable(unsigned int ivar)
release an existing variable
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 )
virtual bool IsFixedVariable(unsigned int ivar) const
query if an existing variable is fixed (i.e.
std::vector< std::string > fNames
BasicMinimizer()
Default constructor.
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 const float lower
Definition: main.cpp:48
virtual const double * StepSizes() const
accessor methods
virtual ~BasicMinimizer()
Destructor.