Logo ROOT  
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 
54 class BasicMinimizer : public ROOT::Math::Minimizer {
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
151  const ROOT::Math::IMultiGenFunction * ObjFunction() const { return fObjFunc; }
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 */
ROOT::Math::BasicMinimizer::fValues
std::vector< double > fValues
Definition: BasicMinimizer.h:195
ROOT::Math::BasicMinimizer::SetMinValue
void SetMinValue(double val)
Definition: BasicMinimizer.h:185
Minimizer.h
ROOT::Math::BasicMinimizer::VariableName
virtual std::string VariableName(unsigned int ivar) const
get name of variables (override if minimizer support storing of variable names)
Definition: BasicMinimizer.cxx:237
ROOT::Math::BasicMinimizer::fBounds
std::map< unsigned int, std::pair< double, double > > fBounds
Definition: BasicMinimizer.h:199
ROOT::Math::BasicMinimizer::CheckObjFunction
bool CheckObjFunction() const
Definition: BasicMinimizer.cxx:273
ROOT::Math::BasicMinimizer::IsFixedVariable
virtual bool IsFixedVariable(unsigned int ivar) const
query if an existing variable is fixed (i.e.
Definition: BasicMinimizer.cxx:216
ROOT::Math::BasicMinimizer::NPar
virtual unsigned int NPar() const
total number of parameter defined
Definition: BasicMinimizer.h:158
ROOT::Math::BasicMinimizer::SetFunction
virtual void SetFunction(const ROOT::Math::IMultiGenFunction &func)
set the function to minimize
Definition: BasicMinimizer.cxx:250
ROOT::Math::BasicMinimizer::FixVariable
virtual bool FixVariable(unsigned int ivar)
fix an existing variable
Definition: BasicMinimizer.cxx:192
ROOT::Math::BasicMinimizer::fSteps
std::vector< double > fSteps
Definition: BasicMinimizer.h:196
ROOT::Math::BasicMinimizer::fMinVal
double fMinVal
Definition: BasicMinimizer.h:194
ROOT::Math::BasicMinimizer::NFree
virtual unsigned int NFree() const
number of free variables (real dimension of the problem)
Definition: BasicMinimizer.cxx:366
IFunctionfwd.h
ROOT::Math::BasicMinimizer::GradObjFunction
const ROOT::Math::IMultiGradFunction * GradObjFunction() const
return pointer to used gradient object function (NULL if gradient is not supported)
Definition: BasicMinimizer.cxx:358
ROOT::Math::BasicMinimizer::fNames
std::vector< std::string > fNames
Definition: BasicMinimizer.h:197
ROOT::Math::MinimTransformFunction
MinimTransformFunction class to perform a transformations on the variables to deal with fixed or limi...
Definition: MinimTransformFunction.h:49
ROOT::Math::BasicMinimizer::ReleaseVariable
virtual bool ReleaseVariable(unsigned int ivar)
release an existing variable
Definition: BasicMinimizer.cxx:199
x
Double_t x[n]
Definition: legend1.C:17
ROOT::Math::IGradientFunctionMultiDimTempl
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
Definition: IFunction.h:326
ROOT::Math::BasicMinimizer
Base Minimizer class, which defines the basic funcionality of various minimizer implementations (apar...
Definition: BasicMinimizer.h:64
ROOT::Math::BasicMinimizer::MinValue
virtual double MinValue() const
return minimum function value
Definition: BasicMinimizer.h:146
ROOT::Math::BasicMinimizer::SetUpperLimitedVariable
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 )
Definition: BasicMinimizer.cxx:107
ROOT::Math::BasicMinimizer::SetVariableStepSize
virtual bool SetVariableStepSize(unsigned int ivar, double step)
set the step size of an already existing variable
Definition: BasicMinimizer.cxx:150
ROOT::Math::BasicMinimizer::CheckDimension
bool CheckDimension() const
Definition: BasicMinimizer.cxx:264
ROOT::Math::BasicMinimizer::SetVariable
virtual bool SetVariable(unsigned int ivar, const std::string &name, double val, double step)
set free variable
Definition: BasicMinimizer.cxx:73
ROOT::Math::BasicMinimizer::BasicMinimizer
BasicMinimizer()
Default constructor.
Definition: BasicMinimizer.cxx:53
ROOT::Math::BasicMinimizer::fDim
unsigned int fDim
Definition: BasicMinimizer.h:190
ROOT::Math::BasicMinimizer::GetVariableSettings
virtual bool GetVariableSettings(unsigned int ivar, ROOT::Fit::ParameterSettings &varObj) const
get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
Definition: BasicMinimizer.cxx:221
ROOT::Math::BasicMinimizer::SetFinalValues
void SetFinalValues(const double *x)
Definition: BasicMinimizer.cxx:332
ROOT::Math::BasicMinimizer::SetVariableUpperLimit
virtual bool SetVariableUpperLimit(unsigned int ivar, double upper)
set the upper-limit of an already existing variable
Definition: BasicMinimizer.cxx:163
ROOT::Math::BasicMinimizer::operator=
BasicMinimizer & operator=(const BasicMinimizer &rhs)
Assignment operator.
Definition: BasicMinimizer.h:90
ROOT::Math::BasicMinimizer::StepSizes
virtual const double * StepSizes() const
accessor methods
Definition: BasicMinimizer.h:173
ROOT::Math::BasicMinimizer::fObjFunc
const ROOT::Math::IMultiGenFunction * fObjFunc
Definition: BasicMinimizer.h:192
ROOT::Math::BasicMinimizer::X
virtual const double * X() const
return pointer to X values at the minimum
Definition: BasicMinimizer.h:149
IParamFunctionfwd.h
ROOT::Math::BasicMinimizer::SetVariableValues
virtual bool SetVariableValues(const double *x)
set the values of all existing variables (array must be dimensioned to the size of existing parameter...
Definition: BasicMinimizer.cxx:143
ROOT::Fit::ParameterSettings
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
Definition: ParameterSettings.h:46
ROOT::Math::BasicMinimizer::SetVariableLowerLimit
virtual bool SetVariableLowerLimit(unsigned int ivar, double lower)
set the lower-limit of an already existing variable
Definition: BasicMinimizer.cxx:157
ROOT::Math::BasicMinimizer::SetVariableLimits
virtual bool SetVariableLimits(unsigned int ivar, double lower, double upper)
set the limits of an already existing variable
Definition: BasicMinimizer.cxx:169
ROOT::Math::BasicMinimizer::fVarTypes
std::vector< ROOT::Math::EMinimVariableType > fVarTypes
Definition: BasicMinimizer.h:198
ROOT::Math::BasicMinimizer::SetFixedVariable
virtual bool SetFixedVariable(unsigned int, const std::string &, double)
set fixed variable (override if minimizer supports them )
Definition: BasicMinimizer.cxx:126
ROOT::Math::Minimizer
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2,...
Definition: Minimizer.h:80
ROOT::Math::BasicMinimizer::NDim
virtual unsigned int NDim() const
number of dimensions
Definition: BasicMinimizer.h:152
name
char name[80]
Definition: TGX11.cxx:110
ROOT::Math::BasicMinimizer::SetLimitedVariable
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 )
Definition: BasicMinimizer.cxx:117
ROOT::Math::BasicMinimizer::CreateTransformation
MinimTransformFunction * CreateTransformation(std::vector< double > &startValues, const ROOT::Math::IMultiGradFunction *func=0)
Definition: BasicMinimizer.cxx:282
ROOT::Math::BasicMinimizer::SetVariableValue
virtual bool SetVariableValue(unsigned int ivar, double val)
set the value of an existing variable
Definition: BasicMinimizer.cxx:135
ROOT::Math::IBaseFunctionMultiDimTempl
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:62
MinimTransformVariable.h
ROOT::Math::BasicMinimizer::PrintResult
void PrintResult() const
print result of minimization
Definition: BasicMinimizer.cxx:346
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Math::BasicMinimizer::Minimize
virtual bool Minimize()
method to perform the minimization
Definition: BasicMinimizer.cxx:326
ROOT::Math::BasicMinimizer::TransformFunction
const ROOT::Math::MinimTransformFunction * TransformFunction() const
return transformation function (NULL if not having a transformation)
Definition: BasicMinimizer.cxx:362
Math
ROOT::Math::BasicMinimizer::SetLowerLimitedVariable
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 )
Definition: BasicMinimizer.cxx:98
ROOT::Math::BasicMinimizer::ObjFunction
const ROOT::Math::IMultiGenFunction * ObjFunction() const
return pointer to used objective function
Definition: BasicMinimizer.h:161
ROOT::Math::BasicMinimizer::~BasicMinimizer
virtual ~BasicMinimizer()
Destructor.
Definition: BasicMinimizer.cxx:69
ROOT::Math::BasicMinimizer::VariableIndex
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
Definition: BasicMinimizer.cxx:242