Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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#include <memory>
26#include <iostream>
27
28namespace ROOT {
29
30 namespace Math {
31
32
33
34/**
35 MinimTransformFunction class to perform a transformations on the
36 variables to deal with fixed or limited variables (support both double and single bounds)
37 The class manages the passed function pointer
38
39 @ingroup MultiMin
40*/
42
43public:
44
47
48
49 /**
50 Constructor from a IMultiGradFunction interface that is externally managed
51 vector specifying the variable types (free, bounded or fixed, defined in enum EMinimVariableTypes )
52 variable values (used for the fixed ones) and a map with the bounds (for the bounded variables)
53
54 */
55 MinimTransformFunction ( const IMultiGradFunction * f, const std::vector<ROOT::Math::EMinimVariableType> & types, const std::vector<double> & values,
56 const std::map<unsigned int, std::pair<double, double> > & bounds);
57
58
59 /**
60 Destructor (no operation)
61 */
63
64 // method inherited from IFunction interface
65
66 unsigned int NDim() const override { return fIndex.size(); }
67
68 unsigned int NTot() const { return fFunc->NDim(); }
69
70 /// clone: not supported (since unique_ptr used in the fVariables)
71 IMultiGenFunction * Clone() const override {
72 return nullptr;
73 }
74
75
76 /// transform from internal to external
77 /// result is cached also inside the class
78 const double * Transformation( const double * x) const {
79 Transformation(x, &fX[0]);
80 return &fX.front();
81 }
82
83
84 /// transform from internal to external
85 void Transformation( const double * xint, double * xext) const;
86
87 /// inverse transformation (external -> internal)
88 void InvTransformation(const double * xext, double * xint) const;
89
90 /// inverse transformation for steps (external -> internal) at external point x
91 void InvStepTransformation(const double * x, const double * sext, double * sint) const;
92
93 ///transform gradient vector (external -> internal) at internal point x
94 void GradientTransformation(const double * x, const double *gExt, double * gInt) const;
95
96 ///transform covariance matrix (internal -> external) at internal point x
97 /// use row storages for matrices m(i,j) = rep[ i * dim + j]
98 void MatrixTransformation(const double * x, const double *covInt, double * covExt) const;
99
100 // return original function
101 const IMultiGradFunction *OriginalFunction() const { return fFunc; }
102
103
104private:
105
106 /// function evaluation
107 double DoEval(const double * x) const override {
108#ifndef DO_THREADSAFE
109 return (*fFunc)(Transformation(x));
110#else
111 std::vector<double> xext(fVariables.size() );
112 Transformation(x, &xext[0]);
113 return (*fFunc)(&xext[0]);
114#endif
115 }
116
117 /// calculate derivatives
118 double DoDerivative (const double * x, unsigned int icoord ) const override {
119 const MinimTransformVariable & var = fVariables[ fIndex[icoord] ];
120 double dExtdInt = (var.IsLimited() ) ? var.DerivativeIntToExt( x[icoord] ) : 1.0;
121 double deriv = fFunc->Derivative( Transformation(x) , fIndex[icoord] );
122 //std::cout << "Derivative icoord (ext)" << fIndex[icoord] << " dtrafo " << dExtdInt << " " << deriv << std::endl;
123 return deriv * dExtdInt;
124 }
125
126 // copy constructor for this class (disable by having it private)
129 {}
130
131 // assignment operator for this class (disable by having it private)
133 return *this;
134 }
135
136
137
138private:
139
140 mutable std::vector<double> fX; ///< internal cached of external values
141 std::vector<MinimTransformVariable> fVariables; ///< vector of variable settings and tranformation function
142 std::vector<unsigned int> fIndex; ///< vector with external indices for internal variables
143 const IMultiGradFunction * fFunc; ///< user function
144
145};
146
147 } // end namespace Math
148
149} // end namespace ROOT
150
151
152#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:343
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...
IMultiGenFunction * Clone() const override
clone: not supported (since unique_ptr used in the fVariables)
~MinimTransformFunction() override
Destructor (no operation)
std::vector< unsigned int > fIndex
vector with external indices for internal variables
ROOT::Math::IMultiGradFunction::BaseFunc BaseFunc
unsigned int NDim() const override
Retrieve the dimension of the function.
double DoEval(const double *x) const override
function evaluation
void InvTransformation(const double *xext, double *xint) const
inverse transformation (external -> internal)
MinimTransformFunction & operator=(const MinimTransformFunction &)
const IMultiGradFunction * OriginalFunction() const
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 ...
double DoDerivative(const double *x, unsigned int icoord) const override
calculate derivatives
const double * Transformation(const double *x) const
transform from internal to external result is cached also inside the class
ROOT::Math::IMultiGradFunction BaseGradFunc
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
vector of variable settings and tranformation function
std::vector< double > fX
internal cached of external values
MinimTransformFunction(const MinimTransformFunction &)
const IMultiGradFunction * fFunc
user function
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.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.