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
69 /// set the function to minimize
70 void SetFunction(const ROOT::Math::IMultiGenFunction & func) override;
71
72 /// set free variable
73 bool SetVariable(unsigned int ivar, const std::string & name, double val, double step) override;
74
75
76 /// set lower limit variable (override if minimizer supports them )
77 bool SetLowerLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double lower ) override;
78 /// set upper limit variable (override if minimizer supports them )
79 bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper ) override;
80 /// set upper/lower limited variable (override if minimizer supports them )
81 bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double /* lower */, double /* upper */) override;
82 /// set fixed variable (override if minimizer supports them )
83 bool SetFixedVariable(unsigned int /* ivar */, const std::string & /* name */, double /* val */) override;
84 /// set the value of an existing variable
85 bool SetVariableValue(unsigned int ivar, double val ) override;
86 /// set the values of all existing variables (array must be dimensioned to the size of existing parameters)
87 bool SetVariableValues(const double * x) override;
88 /// set the step size of an already existing variable
89 bool SetVariableStepSize(unsigned int ivar, double step ) override;
90 /// set the lower-limit of an already existing variable
91 bool SetVariableLowerLimit(unsigned int ivar, double lower) override;
92 /// set the upper-limit of an already existing variable
93 bool SetVariableUpperLimit(unsigned int ivar, double upper) override;
94 /// set the limits of an already existing variable
95 bool SetVariableLimits(unsigned int ivar, double lower, double upper) override;
96 /// fix an existing variable
97 bool FixVariable(unsigned int ivar) override;
98 /// release an existing variable
99 bool ReleaseVariable(unsigned int ivar) override;
100 /// query if an existing variable is fixed (i.e. considered constant in the minimization)
101 /// note that by default all variables are not fixed
102 bool IsFixedVariable(unsigned int ivar) const override;
103 /// get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
104 bool GetVariableSettings(unsigned int ivar, ROOT::Fit::ParameterSettings & varObj) const override;
105 /// get name of variables (override if minimizer support storing of variable names)
106 std::string VariableName(unsigned int ivar) const override;
107 /// get index of variable given a variable given a name
108 /// return -1 if variable is not found
109 int VariableIndex(const std::string & name) const override;
110
111 /// method to perform the minimization
112 bool Minimize() override;
113
114 /// return minimum function value
115 double MinValue() const override { return fMinVal; }
116
117 /// return pointer to X values at the minimum
118 const double * X() const override { return &fValues.front(); }
119
120 /// number of dimensions
121 unsigned int NDim() const override { return fDim; }
122
123 /// number of free variables (real dimension of the problem)
124 unsigned int NFree() const override;
125
126 /// total number of parameter defined
127 virtual unsigned int NPar() const { return fValues.size(); }
128
129 /// return pointer to used objective function
131
132 /// return pointer to used gradient object function (NULL if gradient is not supported)
134
135
136 /// print result of minimization
137 void PrintResult() const;
138
139 /// accessor methods
140 virtual const double * StepSizes() const { return &fSteps.front(); }
141
142protected:
143
144 bool CheckDimension() const;
145
146 bool CheckObjFunction() const;
147
148 MinimTransformFunction * CreateTransformation(std::vector<double> & startValues, const ROOT::Math::IMultiGradFunction * func = nullptr);
149
150 void SetFinalValues(const double * x, const MinimTransformFunction * func = nullptr);
151
152 void SetMinValue(double val) { fMinVal = val; }
153
154private:
155
156 // dimension of the function to be minimized
157 unsigned int fDim;
158
160
161 double fMinVal;
162 std::vector<double> fValues;
163 std::vector<double> fSteps;
164 std::vector<std::string> fNames;
165 std::vector<ROOT::Math::EMinimVariableType> fVarTypes; ///< vector specifying the type of variables
166 std::map< unsigned int, std::pair<double, double> > fBounds; ///< map specifying the bound using as key the parameter index
167
168};
169
170 } // end namespace Fit
171
172} // end namespace ROOT
173
174
175
176#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
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
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:119
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...