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
23
25
26
27#include <vector>
28#include <map>
29#include <string>
30
31
32
33namespace ROOT {
34
35namespace 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
56public:
57
58 /**
59 Default constructor
60 */
62
63
64 /**
65 Destructor
66 */
67 virtual ~BasicMinimizer ();
68
69private:
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
85public:
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
165protected:
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
177private:
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 */
char name[80]
Definition: TGX11.cxx:109
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
Base Minimizer class, which defines the basic funcionality of various minimizer implementations (apar...
virtual ~BasicMinimizer()
Destructor.
virtual double MinValue() const
return minimum function value
virtual unsigned int NPar() const
total number of parameter defined
BasicMinimizer(const BasicMinimizer &)
Copy constructor.
virtual unsigned int NFree() const
number of free variables (real dimension of the problem)
virtual bool GetVariableSettings(unsigned int ivar, ROOT::Fit::ParameterSettings &varObj) const
get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
void PrintResult() const
print result of minimization
BasicMinimizer()
Default constructor.
const ROOT::Math::IMultiGenFunction * fObjFunc
virtual bool IsFixedVariable(unsigned int ivar) const
query if an existing variable is fixed (i.e.
std::vector< ROOT::Math::EMinimVariableType > fVarTypes
const ROOT::Math::MinimTransformFunction * TransformFunction() const
return transformation function (NULL if not having a transformation)
void SetMinValue(double val)
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 const double * StepSizes() const
accessor methods
virtual void SetFunction(const ROOT::Math::IMultiGenFunction &func)
set the function to minimize
virtual bool SetVariable(unsigned int ivar, const std::string &name, double val, double step)
set free variable
virtual bool FixVariable(unsigned int ivar)
fix an existing variable
const ROOT::Math::IMultiGenFunction * ObjFunction() const
return pointer to used objective function
virtual unsigned int NDim() const
number of dimensions
BasicMinimizer & operator=(const BasicMinimizer &rhs)
Assignment operator.
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 )
virtual bool SetVariableLimits(unsigned int ivar, double lower, double upper)
set the limits of an already existing variable
std::vector< double > fSteps
virtual bool SetVariableValues(const double *x)
set the values of all existing variables (array must be dimensioned to the size of existing parameter...
virtual bool SetVariableStepSize(unsigned int ivar, double step)
set the step size of an already existing variable
virtual bool ReleaseVariable(unsigned int ivar)
release an existing variable
virtual std::string VariableName(unsigned int ivar) const
get name of variables (override if minimizer support storing of variable names)
std::map< unsigned int, std::pair< double, double > > fBounds
virtual const double * X() const
return pointer to X values at the minimum
virtual bool SetVariableValue(unsigned int ivar, double val)
set the value of an existing variable
void SetFinalValues(const double *x)
virtual bool SetFixedVariable(unsigned int, const std::string &, double)
set fixed variable (override if minimizer supports them )
virtual bool SetVariableLowerLimit(unsigned int ivar, double lower)
set the lower-limit of an already existing variable
virtual bool Minimize()
method to perform the minimization
MinimTransformFunction * CreateTransformation(std::vector< double > &startValues, const ROOT::Math::IMultiGradFunction *func=0)
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
std::vector< double > fValues
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::IMultiGradFunction * GradObjFunction() const
return pointer to used gradient object function (NULL if gradient is not supported)
std::vector< std::string > fNames
virtual bool SetVariableUpperLimit(unsigned int ivar, double upper)
set the upper-limit of an already existing variable
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:62
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
Definition: IFunction.h:327
MinimTransformFunction class to perform a transformations on the variables to deal with fixed or limi...
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2,...
Definition: Minimizer.h:78
Double_t x[n]
Definition: legend1.C:17
Namespace for new Math classes and functions.
VSD Structures.
Definition: StringConv.hxx:21