Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 functionality of various minimizer
44 implementations (apart from Minuit and Minuit2)
45 It provides support for storing parameter values, step size,
46 parameter transformation etc.. in case real minimizer implementations 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 ~BasicMinimizer () override;
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 void SetFunction(const ROOT::Math::IMultiGenFunction & func) override;
89
90 /// set free variable
91 bool SetVariable(unsigned int ivar, const std::string & name, double val, double step) override;
92
93
94 /// set lower limit variable (override if minimizer supports them )
95 bool SetLowerLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double lower ) override;
96 /// set upper limit variable (override if minimizer supports them )
97 bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper ) override;
98 /// set upper/lower limited variable (override if minimizer supports them )
99 bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double /* lower */, double /* upper */) override;
100 /// set fixed variable (override if minimizer supports them )
101 bool SetFixedVariable(unsigned int /* ivar */, const std::string & /* name */, double /* val */) override;
102 /// set the value of an existing variable
103 bool SetVariableValue(unsigned int ivar, double val ) override;
104 /// set the values of all existing variables (array must be dimensioned to the size of existing parameters)
105 bool SetVariableValues(const double * x) override;
106 /// set the step size of an already existing variable
107 bool SetVariableStepSize(unsigned int ivar, double step ) override;
108 /// set the lower-limit of an already existing variable
109 bool SetVariableLowerLimit(unsigned int ivar, double lower) override;
110 /// set the upper-limit of an already existing variable
111 bool SetVariableUpperLimit(unsigned int ivar, double upper) override;
112 /// set the limits of an already existing variable
113 bool SetVariableLimits(unsigned int ivar, double lower, double upper) override;
114 /// fix an existing variable
115 bool FixVariable(unsigned int ivar) override;
116 /// release an existing variable
117 bool ReleaseVariable(unsigned int ivar) override;
118 /// query if an existing variable is fixed (i.e. considered constant in the minimization)
119 /// note that by default all variables are not fixed
120 bool IsFixedVariable(unsigned int ivar) const override;
121 /// get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
122 bool GetVariableSettings(unsigned int ivar, ROOT::Fit::ParameterSettings & varObj) const override;
123 /// get name of variables (override if minimizer support storing of variable names)
124 std::string VariableName(unsigned int ivar) const override;
125 /// get index of variable given a variable given a name
126 /// return -1 if variable is not found
127 int VariableIndex(const std::string & name) const override;
128
129 /// method to perform the minimization
130 bool Minimize() override;
131
132 /// return minimum function value
133 double MinValue() const override { return fMinVal; }
134
135 /// return pointer to X values at the minimum
136 const double * X() const override { return &fValues.front(); }
137
138 /// number of dimensions
139 unsigned int NDim() const override { return fDim; }
140
141 /// number of free variables (real dimension of the problem)
142 unsigned int NFree() const override;
143
144 /// total number of parameter defined
145 virtual unsigned int NPar() const { return fValues.size(); }
146
147 /// return pointer to used objective function
149
150 /// return pointer to used gradient object function (NULL if gradient is not supported)
152
153
154 /// print result of minimization
155 void PrintResult() const;
156
157 /// accessor methods
158 virtual const double * StepSizes() const { return &fSteps.front(); }
159
160protected:
161
162 bool CheckDimension() const;
163
164 bool CheckObjFunction() const;
165
166 MinimTransformFunction * CreateTransformation(std::vector<double> & startValues, const ROOT::Math::IMultiGradFunction * func = nullptr);
167
168 void SetFinalValues(const double * x, const MinimTransformFunction * func = nullptr);
169
170 void SetMinValue(double val) { fMinVal = val; }
171
172private:
173
174 // dimension of the function to be minimized
175 unsigned int fDim;
176
178
179 double fMinVal;
180 std::vector<double> fValues;
181 std::vector<double> fSteps;
182 std::vector<std::string> fNames;
183 std::vector<ROOT::Math::EMinimVariableType> fVarTypes; ///< vector specifying the type of variables
184 std::map< unsigned int, std::pair<double, double> > fBounds; ///< map specifying the bound using as key the parameter index
185
186};
187
188 } // end namespace Fit
189
190} // end namespace ROOT
191
192
193
194#endif /* ROOT_Math_BasicMinimizer */
char name[80]
Definition TGX11.cxx:110
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
Base Minimizer class, which defines the basic functionality of various minimizer implementations (apa...
~BasicMinimizer() override
Destructor.
virtual unsigned int NPar() const
total number of parameter defined
BasicMinimizer(const BasicMinimizer &)
Copy constructor.
bool IsFixedVariable(unsigned int ivar) const override
query if an existing variable is fixed (i.e.
void PrintResult() const
print result of minimization
BasicMinimizer()
Default constructor.
const ROOT::Math::IMultiGenFunction * fObjFunc
unsigned int NFree() const override
number of free variables (real dimension of the problem)
unsigned int NDim() const override
number of dimensions
bool SetVariableStepSize(unsigned int ivar, double step) override
set the step size of an already existing variable
std::vector< ROOT::Math::EMinimVariableType > fVarTypes
vector specifying the type of variables
void SetFinalValues(const double *x, const MinimTransformFunction *func=nullptr)
double MinValue() const override
return minimum function value
bool SetVariable(unsigned int ivar, const std::string &name, double val, double step) override
set free variable
MinimTransformFunction * CreateTransformation(std::vector< double > &startValues, const ROOT::Math::IMultiGradFunction *func=nullptr)
int VariableIndex(const std::string &name) const override
get index of variable given a variable given a name return -1 if variable is not found
bool SetLowerLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double lower) override
set lower limit variable (override if minimizer supports them )
virtual const double * StepSizes() const
accessor methods
void SetFunction(const ROOT::Math::IMultiGenFunction &func) override
set the function to minimize
const ROOT::Math::IMultiGenFunction * ObjFunction() const
return pointer to used objective function
bool SetVariableLowerLimit(unsigned int ivar, double lower) override
set the lower-limit of an already existing variable
BasicMinimizer & operator=(const BasicMinimizer &rhs)
Assignment operator.
bool SetVariableValues(const double *x) override
set the values of all existing variables (array must be dimensioned to the size of existing parameter...
bool Minimize() override
method to perform the minimization
std::vector< double > fSteps
bool SetFixedVariable(unsigned int, const std::string &, double) override
set fixed variable (override if minimizer supports them )
bool GetVariableSettings(unsigned int ivar, ROOT::Fit::ParameterSettings &varObj) const override
get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
std::map< unsigned int, std::pair< double, double > > fBounds
map specifying the bound using as key the parameter index
bool SetUpperLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double upper) override
set upper limit variable (override if minimizer supports them )
bool SetLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double, double) override
set upper/lower limited variable (override if minimizer supports them )
bool ReleaseVariable(unsigned int ivar) override
release an existing variable
bool SetVariableLimits(unsigned int ivar, double lower, double upper) override
set the limits of an already existing variable
std::vector< double > fValues
bool FixVariable(unsigned int ivar) override
fix an existing variable
const ROOT::Math::IMultiGradFunction * GradObjFunction() const
return pointer to used gradient object function (NULL if gradient is not supported)
std::vector< std::string > fNames
const double * X() const override
return pointer to X values at the minimum
std::string VariableName(unsigned int ivar) const override
get name of variables (override if minimizer support storing of variable names)
bool SetVariableValue(unsigned int ivar, double val) override
set the value of an existing variable
bool SetVariableUpperLimit(unsigned int ivar, double upper) override
set the upper-limit of an already existing variable
Documentation for the abstract class IBaseFunctionMultiDim.
Definition IFunction.h:61
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
Definition IFunction.h:168
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:117
Double_t x[n]
Definition legend1.C:17
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...