Logo ROOT   6.08/07
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 #ifndef ROOT_Math_IFunction
19 #include "Math/IFunction.h"
20 #endif
21 
22 #ifndef ROOT_Math_MinimTransformVariable
24 #endif
25 
26 
27 #include <vector>
28 #include <map>
29 
30 namespace ROOT {
31 
32  namespace Math {
33 
34 
35 
36 /**
37  MinimTransformFunction class to perform a transformations on the
38  variables to deal with fixed or limited variables (support both double and single bounds)
39  The class manages the passed function pointer
40 
41  @ingroup MultiMin
42 */
44 
45 public:
46 
49 
50 
51  /**
52  Constructor from a IMultiGradFunction interface (which is managed by the class)
53  vector specifying the variable types (free, bounded or fixed, defined in enum EMinimVariableTypes )
54  variable values (used for the fixed ones) and a map with the bounds (for the bounded variables)
55 
56  */
57  MinimTransformFunction ( const IMultiGradFunction * f, const std::vector<ROOT::Math::EMinimVariableType> & types, const std::vector<double> & values,
58  const std::map<unsigned int, std::pair<double, double> > & bounds);
59 
60 
61  /**
62  Destructor (delete function pointer)
63  */
65  if (fFunc) delete fFunc;
66  }
67 
68 
69  // method inherited from IFunction interface
70 
71  unsigned int NDim() const { return fIndex.size(); }
72 
73  unsigned int NTot() const { return fFunc->NDim(); }
74 
75  /// clone: not supported (since auto_ptr used in the fVariables)
77  return 0;
78  }
79 
80 
81  /// transform from internal to external
82  /// result is cached also inside the class
83  const double * Transformation( const double * x) const {
84  Transformation(x, &fX[0]);
85  return &fX.front();
86  }
87 
88 
89  /// transform from internal to external
90  void Transformation( const double * xint, double * xext) const;
91 
92  /// inverse transformation (external -> internal)
93  void InvTransformation(const double * xext, double * xint) const;
94 
95  /// inverse transformation for steps (external -> internal) at external point x
96  void InvStepTransformation(const double * x, const double * sext, double * sint) const;
97 
98  ///transform gradient vector (external -> internal) at internal point x
99  void GradientTransformation(const double * x, const double *gExt, double * gInt) const;
100 
101  ///transform covariance matrix (internal -> external) at internal point x
102  /// use row storages for matrices m(i,j) = rep[ i * dim + j]
103  void MatrixTransformation(const double * x, const double *covInt, double * covExt) const;
104 
105  // return original function
106  const IMultiGradFunction *OriginalFunction() const { return fFunc; }
107 
108 
109 private:
110 
111  /// function evaluation
112  virtual double DoEval(const double * x) const {
113 #ifndef DO_THREADSAFE
114  return (*fFunc)(Transformation(x));
115 #else
116  std::vector<double> xext(fVariables.size() );
117  Transformation(x, &xext[0]);
118  return (*fFunc)(&xext[0]);
119 #endif
120  }
121 
122  /// calculate derivatives
123  virtual double DoDerivative (const double * x, unsigned int icoord ) const {
124  const MinimTransformVariable & var = fVariables[ fIndex[icoord] ];
125  double dExtdInt = (var.IsLimited() ) ? var.DerivativeIntToExt( x[icoord] ) : 1.0;
126  double deriv = fFunc->Derivative( Transformation(x) , fIndex[icoord] );
127  //std::cout << "Derivative icoord (ext)" << fIndex[icoord] << " dtrafo " << dExtdInt << " " << deriv << std::endl;
128  return deriv * dExtdInt;
129  }
130 
131  // copy constructor for this class (disable by having it private)
133  BaseFunc(), BaseGradFunc()
134  {}
135 
136  // assignment operator for this class (disable by having it private)
138  return *this;
139  }
140 
141 
142 
143 private:
144 
145  mutable std::vector<double> fX; // internal cached of external values
146  std::vector<MinimTransformVariable> fVariables; // vector of variable settings and tranformation function
147  std::vector<unsigned int> fIndex; // vector with external indices for internal variables
148  const IMultiGradFunction * fFunc; // user function
149 
150 };
151 
152  } // end namespace Math
153 
154 } // end namespace ROOT
155 
156 
157 #endif /* ROOT_Math_MinimTransformFunction */
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
Definition: IFunction.h:322
virtual double DoDerivative(const double *x, unsigned int icoord) const
calculate derivatives
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 ...
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
const double * Transformation(const double *x) const
transform from internal to external result is cached also inside the class
MinimTransformFunction & operator=(const MinimTransformFunction &)
ROOT::Math::IMultiGradFunction BaseGradFunc
MinimTransformFunction class to perform a transformations on the variables to deal with fixed or limi...
virtual double DoEval(const double *x) const
function evaluation
Double_t x[n]
Definition: legend1.C:17
void InvTransformation(const double *xext, double *xint) const
inverse transformation (external -> internal)
IMultiGenFunction * Clone() const
clone: not supported (since auto_ptr used in the fVariables)
unsigned int NDim() const
Retrieve the dimension of the function.
MinimTransformVariable class Contains meta information of the variables such as bounds, fix flags and deals with transformation of the variable The class does not contain the values and the step size (error) of the variable This is an internal class used by the MinimTransformFunction class.
const IMultiGradFunction * OriginalFunction() const
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.
~MinimTransformFunction()
Destructor (delete function pointer)
ROOT::Math::IMultiGradFunction::BaseFunc BaseFunc
double Derivative(const double *x, unsigned int icoord=0) const
Return the partial derivative with respect to the passed coordinate.
Definition: IFunction.h:212
MinimTransformFunction(const MinimTransformFunction &)
double f(double x)
std::vector< MinimTransformVariable > fVariables
void InvStepTransformation(const double *x, const double *sext, double *sint) const
inverse transformation for steps (external -> internal) at external point x
Namespace for new Math classes and functions.
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
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:63