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 gradient the function to minimize
91 void SetFunction(const ROOT::Math::IMultiGradFunction & func) override;
92
93 /// set free variable
94 bool SetVariable(unsigned int ivar, const std::string & name, double val, double step) override;
95
96
97 /// set lower limit variable (override if minimizer supports them )
98 bool SetLowerLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double lower ) override;
99 /// set upper limit variable (override if minimizer supports them )
100 bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper ) override;
101 /// set upper/lower limited variable (override if minimizer supports them )
102 bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double /* lower */, double /* upper */) override;
103 /// set fixed variable (override if minimizer supports them )
104 bool SetFixedVariable(unsigned int /* ivar */, const std::string & /* name */, double /* val */) override;
105 /// set the value of an existing variable
106 bool SetVariableValue(unsigned int ivar, double val ) override;
107 /// set the values of all existing variables (array must be dimensioned to the size of existing parameters)
108 bool SetVariableValues(const double * x) override;
109 /// set the step size of an already existing variable
110 bool SetVariableStepSize(unsigned int ivar, double step ) override;
111 /// set the lower-limit of an already existing variable
112 bool SetVariableLowerLimit(unsigned int ivar, double lower) override;
113 /// set the upper-limit of an already existing variable
114 bool SetVariableUpperLimit(unsigned int ivar, double upper) override;
115 /// set the limits of an already existing variable
116 bool SetVariableLimits(unsigned int ivar, double lower, double upper) override;
117 /// fix an existing variable
118 bool FixVariable(unsigned int ivar) override;
119 /// release an existing variable
120 bool ReleaseVariable(unsigned int ivar) override;
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 bool IsFixedVariable(unsigned int ivar) const override;
124 /// get variable settings in a variable object (like ROOT::Fit::ParamsSettings)
125 bool GetVariableSettings(unsigned int ivar, ROOT::Fit::ParameterSettings & varObj) const override;
126 /// get name of variables (override if minimizer support storing of variable names)
127 std::string VariableName(unsigned int ivar) const override;
128 /// get index of variable given a variable given a name
129 /// return -1 if variable is not found
130 int VariableIndex(const std::string & name) const override;
131
132 /// method to perform the minimization
133 bool Minimize() override;
134
135 /// return minimum function value
136 double MinValue() const override { return fMinVal; }
137
138 /// return pointer to X values at the minimum
139 const double * X() const override { return &fValues.front(); }
140
141 /// number of dimensions
142 unsigned int NDim() const override { return fDim; }
143
144 /// number of free variables (real dimension of the problem)
145 unsigned int NFree() const override;
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
157 /// print result of minimization
158 void PrintResult() const;
159
160 /// accessor methods
161 virtual const double * StepSizes() const { return &fSteps.front(); }
162
163protected:
164
165 bool CheckDimension() const;
166
167 bool CheckObjFunction() const;
168
169 MinimTransformFunction * CreateTransformation(std::vector<double> & startValues, const ROOT::Math::IMultiGradFunction * func = nullptr);
170
171 void SetFinalValues(const double * x, const MinimTransformFunction * func = nullptr);
172
173 void SetMinValue(double val) { fMinVal = val; }
174
175private:
176
177 // dimension of the function to be minimized
178 unsigned int fDim;
179
181
182 double fMinVal;
183 std::vector<double> fValues;
184 std::vector<double> fSteps;
185 std::vector<std::string> fNames;
186 std::vector<ROOT::Math::EMinimVariableType> fVarTypes; ///< vector specifying the type of variables
187 std::map< unsigned int, std::pair<double, double> > fBounds; ///< map specifying the bound using as key the parameter index
188
189};
190
191 } // end namespace Fit
192
193} // end namespace ROOT
194
195
196
197#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:62
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
Definition IFunction.h:343
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.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.