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