Logo ROOT  
Reference Guide
MinimTransformFunction.h
Go to the documentation of this file.
1// @(#)root/mathmore:$Id$
2// Author: L. Moneta June 2009
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11
12// Header file for class MinimTransformFunction
13
14#ifndef ROOT_Math_MinimTransformFunction
15#define ROOT_Math_MinimTransformFunction
16
17
18#include "Math/IFunction.h"
19
21
22
23#include <vector>
24#include <map>
25
26namespace ROOT {
27
28 namespace Math {
29
30
31
32/**
33 MinimTransformFunction class to perform a transformations on the
34 variables to deal with fixed or limited variables (support both double and single bounds)
35 The class manages the passed function pointer
36
37 @ingroup MultiMin
38*/
40
41public:
42
45
46
47 /**
48 Constructor from a IMultiGradFunction interface (which is managed by the class)
49 vector specifying the variable types (free, bounded or fixed, defined in enum EMinimVariableTypes )
50 variable values (used for the fixed ones) and a map with the bounds (for the bounded variables)
51
52 */
53 MinimTransformFunction ( const IMultiGradFunction * f, const std::vector<ROOT::Math::EMinimVariableType> & types, const std::vector<double> & values,
54 const std::map<unsigned int, std::pair<double, double> > & bounds);
55
56
57 /**
58 Destructor (delete function pointer)
59 */
61 if (fFunc) delete fFunc;
62 }
63
64
65 // method inherited from IFunction interface
66
67 unsigned int NDim() const { return fIndex.size(); }
68
69 unsigned int NTot() const { return fFunc->NDim(); }
70
71 /// clone: not supported (since unique_ptr used in the fVariables)
73 return 0;
74 }
75
76
77 /// transform from internal to external
78 /// result is cached also inside the class
79 const double * Transformation( const double * x) const {
80 Transformation(x, &fX[0]);
81 return &fX.front();
82 }
83
84
85 /// transform from internal to external
86 void Transformation( const double * xint, double * xext) const;
87
88 /// inverse transformation (external -> internal)
89 void InvTransformation(const double * xext, double * xint) const;
90
91 /// inverse transformation for steps (external -> internal) at external point x
92 void InvStepTransformation(const double * x, const double * sext, double * sint) const;
93
94 ///transform gradient vector (external -> internal) at internal point x
95 void GradientTransformation(const double * x, const double *gExt, double * gInt) const;
96
97 ///transform covariance matrix (internal -> external) at internal point x
98 /// use row storages for matrices m(i,j) = rep[ i * dim + j]
99 void MatrixTransformation(const double * x, const double *covInt, double * covExt) const;
100
101 // return original function
102 const IMultiGradFunction *OriginalFunction() const { return fFunc; }
103
104
105private:
106
107 /// function evaluation
108 virtual double DoEval(const double * x) const {
109#ifndef DO_THREADSAFE
110 return (*fFunc)(Transformation(x));
111#else
112 std::vector<double> xext(fVariables.size() );
113 Transformation(x, &xext[0]);
114 return (*fFunc)(&xext[0]);
115#endif
116 }
117
118 /// calculate derivatives
119 virtual double DoDerivative (const double * x, unsigned int icoord ) const {
120 const MinimTransformVariable & var = fVariables[ fIndex[icoord] ];
121 double dExtdInt = (var.IsLimited() ) ? var.DerivativeIntToExt( x[icoord] ) : 1.0;
122 double deriv = fFunc->Derivative( Transformation(x) , fIndex[icoord] );
123 //std::cout << "Derivative icoord (ext)" << fIndex[icoord] << " dtrafo " << dExtdInt << " " << deriv << std::endl;
124 return deriv * dExtdInt;
125 }
126
127 // copy constructor for this class (disable by having it private)
130 {}
131
132 // assignment operator for this class (disable by having it private)
134 return *this;
135 }
136
137
138
139private:
140
141 mutable std::vector<double> fX; // internal cached of external values
142 std::vector<MinimTransformVariable> fVariables; // vector of variable settings and tranformation function
143 std::vector<unsigned int> fIndex; // vector with external indices for internal variables
144 const IMultiGradFunction * fFunc; // user function
145
146};
147
148 } // end namespace Math
149
150} // end namespace ROOT
151
152
153#endif /* ROOT_Math_MinimTransformFunction */
#define f(i)
Definition: RSha256.hxx:104
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
virtual unsigned int NDim() const=0
Retrieve the dimension of the function.
T Derivative(const T *x, unsigned int icoord=0) const
Return the partial derivative with respect to the passed coordinate.
Definition: IFunction.h:217
MinimTransformFunction class to perform a transformations on the variables to deal with fixed or limi...
virtual double DoDerivative(const double *x, unsigned int icoord) const
calculate derivatives
~MinimTransformFunction()
Destructor (delete function pointer)
unsigned int NDim() const
Retrieve the dimension of the function.
ROOT::Math::IMultiGradFunction::BaseFunc BaseFunc
void InvTransformation(const double *xext, double *xint) const
inverse transformation (external -> internal)
MinimTransformFunction & operator=(const MinimTransformFunction &)
const IMultiGradFunction * OriginalFunction() const
virtual double DoEval(const double *x) const
function evaluation
MinimTransformFunction(const IMultiGradFunction *f, const std::vector< ROOT::Math::EMinimVariableType > &types, const std::vector< double > &values, const std::map< unsigned int, std::pair< double, double > > &bounds)
Constructor from a IMultiGradFunction interface (which is managed by the class) vector specifying the...
void GradientTransformation(const double *x, const double *gExt, double *gInt) const
transform gradient vector (external -> internal) at internal point x
void MatrixTransformation(const double *x, const double *covInt, double *covExt) const
transform covariance matrix (internal -> external) at internal point x use row storages for matrices ...
const double * Transformation(const double *x) const
transform from internal to external result is cached also inside the class
ROOT::Math::IMultiGradFunction BaseGradFunc
IMultiGenFunction * Clone() const
clone: not supported (since unique_ptr used in the fVariables)
void InvStepTransformation(const double *x, const double *sext, double *sint) const
inverse transformation for steps (external -> internal) at external point x
std::vector< MinimTransformVariable > fVariables
MinimTransformFunction(const MinimTransformFunction &)
MinimTransformVariable class Contains meta information of the variables such as bounds,...
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...
Definition: StringConv.hxx:21