BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
ROOT::Math::WrappedParamFunctionGen< FuncPtr > Class Template Reference

Description

template<typename FuncPtr = FreeMultiFunctionPtr>
class ROOT::Math::WrappedParamFunctionGen< FuncPtr >

WrappedParamGenFunction class to wrap any multi-dimensional function implementing the operator()(const double * ) in an interface-like IParamFunction, by fixing some of the variables and define them as parameters. i.e. transform any multi-dim function in a parametric function

Definition at line 140 of file WrappedParamFunction.h.

Inheritance diagram for ROOT::Math::WrappedParamFunctionGen< FuncPtr >:
[legend]
Collaboration diagram for ROOT::Math::WrappedParamFunctionGen< FuncPtr >:
[legend]

Public Types

typedef T BackendType
 
typedef IBaseFunctionMultiDimTempl< double > BaseFunc
 

Public Member Functions

 WrappedParamFunctionGen (const FuncPtr &func, unsigned int dim, unsigned int npar, const double *par, const unsigned int *idx)
 
 WrappedParamFunctionGen (FuncPtr &func, unsigned int dim, unsigned int npar, const double *par, const unsigned int *idx)
 
IMultiGenFunctionClone () const
 clone the function More...
 
unsigned int NDim () const
 
unsigned int NPar () const
 
double operator() (const double *x) const
 
double operator() (const double *x, const double *p) const
 
operator() (const T *x) const
 
virtual std::string ParameterName (unsigned int i) const
 
const double * Parameters () const
 
void SetParameters (const double *p)
 

Private Member Functions

 WrappedParamFunctionGen (const WrappedParamFunctionGen &)
 
double DoEval (const double *x) const
 evaluate the function (re-implement for being more efficient) More...
 
double DoEvalPar (const double *x, const double *p) const
 
void DoInit ()
 
WrappedParamFunctionGenoperator= (const WrappedParamFunctionGen &)
 
void SetParValues (unsigned int npar, const double *p) const
 

Private Attributes

unsigned int fDim
 
FuncPtr fFunc
 
std::vector< double > fParams
 
std::vector< unsigned int > fParIndices
 
std::vector< unsigned int > fVarIndices
 
std::vector< double > fX
 

Member Typedef Documentation

◆ BackendType

template<class T >
typedef T ROOT::Math::IBaseFunctionMultiDimTempl< T >::BackendType
inherited

Definition at line 66 of file IFunction.h.

◆ BaseFunc

Definition at line 108 of file IParamFunction.h.

Constructor & Destructor Documentation

◆ WrappedParamFunctionGen() [1/3]

template<typename FuncPtr = FreeMultiFunctionPtr>
ROOT::Math::WrappedParamFunctionGen< FuncPtr >::WrappedParamFunctionGen ( const FuncPtr &  func,
unsigned int  dim,
unsigned int  npar,
const double *  par,
const unsigned int *  idx 
)
inline

Constructor a wrapped function from a pointer to a generic callable object implemention operator()(const double *), the new function dimension, the number of parameters (number of fixed variables) and an array specifying the index of the fixed variables which becames parameters in the new API

Definition at line 149 of file WrappedParamFunction.h.

149  :
150  fFunc(func),
151  fDim(dim),
152  fParams(std::vector<double>(par,par+npar) ),
153  fParIndices(std::vector<unsigned int>(idx, idx + npar) ),
154  fX(std::vector<double>(npar+dim) ) // cached vector
155  {
156  DoInit();
157  }
std::vector< unsigned int > fParIndices

References ROOT::Math::WrappedParamFunctionGen< FuncPtr >::DoInit().

Referenced by ROOT::Math::WrappedParamFunctionGen< FuncPtr >::Clone().

Here is the call graph for this function:

◆ WrappedParamFunctionGen() [2/3]

template<typename FuncPtr = FreeMultiFunctionPtr>
ROOT::Math::WrappedParamFunctionGen< FuncPtr >::WrappedParamFunctionGen ( FuncPtr &  func,
unsigned int  dim,
unsigned int  npar,
const double *  par,
const unsigned int *  idx 
)
inline

Constructor as before but taking now a non - const pointer to a callable object. This constructor is needed in the case FuncPtr is a std::unique_ptr which has a copy ctor taking non const objects

Definition at line 163 of file WrappedParamFunction.h.

163  :
164  fFunc(func),
165  fDim(dim),
166  fParams(std::vector<double>(par,par+npar) ),
167  fParIndices(std::vector<unsigned int>(idx, idx + npar) ),
168  fX(std::vector<double>(npar+dim) ) // cached vector
169  {
170  DoInit();
171  }

References ROOT::Math::WrappedParamFunctionGen< FuncPtr >::DoInit().

Here is the call graph for this function:

◆ WrappedParamFunctionGen() [3/3]

template<typename FuncPtr = FreeMultiFunctionPtr>
ROOT::Math::WrappedParamFunctionGen< FuncPtr >::WrappedParamFunctionGen ( const WrappedParamFunctionGen< FuncPtr > &  )
private

Member Function Documentation

◆ Clone()

template<typename FuncPtr = FreeMultiFunctionPtr>
IMultiGenFunction* ROOT::Math::WrappedParamFunctionGen< FuncPtr >::Clone ( ) const
inlinevirtual

clone the function

Implements ROOT::Math::IBaseFunctionMultiDimTempl< T >.

Definition at line 174 of file WrappedParamFunction.h.

174  {
175  return new WrappedParamFunctionGen(fFunc, fDim, fParams.size(), fParams.empty() ? nullptr : &fParams.front(), fParIndices.empty() ? nullptr : &fParIndices.front());
176  }
WrappedParamFunctionGen(const FuncPtr &func, unsigned int dim, unsigned int npar, const double *par, const unsigned int *idx)

References ROOT::Math::WrappedParamFunctionGen< FuncPtr >::WrappedParamFunctionGen(), ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fDim, ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fFunc, ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fParams, and ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fParIndices.

Here is the call graph for this function:

◆ DoEval()

template<typename FuncPtr = FreeMultiFunctionPtr>
double ROOT::Math::WrappedParamFunctionGen< FuncPtr >::DoEval ( const double *  x) const
inlineprivatevirtual

evaluate the function (re-implement for being more efficient)

Reimplemented from ROOT::Math::IParametricFunctionMultiDimTempl< double >.

Definition at line 210 of file WrappedParamFunction.h.

210  {
211 
212 // std::cout << this << fDim << " x : ";
213 // std::ostream_iterator<double> oix(std::cout," , ");
214 // std::copy(x, x+fDim, oix);
215 // std::cout << std::endl;
216 // std::cout << "npar " << npar << std::endl;
217 // std::cout << fVarIndices.size() << std::endl;
218 // assert ( fVarIndices.size() == fDim); // otherwise something is wrong
219 
220  for (unsigned int i = 0; i < fDim; ++i) {
221  unsigned int j = fVarIndices[i];
222  assert ( j < NPar() + fDim);
223  fX[ j ] = x[i];
224  }
225 // std::cout << "X : (";
226 // std::ostream_iterator<double> oi(std::cout," , ");
227 // std::copy(fX.begin(), fX.end(), oi);
228 // std::cout << std::endl;
229 
230  return (*fFunc)( fX.empty() ? nullptr : &fX.front() );
231  }
std::vector< unsigned int > fVarIndices

References ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fDim, ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fFunc, ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fVarIndices, ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fX, and ROOT::Math::WrappedParamFunctionGen< FuncPtr >::NPar().

Referenced by ROOT::Math::WrappedParamFunctionGen< FuncPtr >::DoEvalPar().

Here is the call graph for this function:

◆ DoEvalPar()

template<typename FuncPtr = FreeMultiFunctionPtr>
double ROOT::Math::WrappedParamFunctionGen< FuncPtr >::DoEvalPar ( const double *  x,
const double *  p 
) const
inlineprivatevirtual

implement the required IParamFunction interface

Implements ROOT::Math::IParametricFunctionMultiDimTempl< double >.

Definition at line 237 of file WrappedParamFunction.h.

237  {
238  SetParValues(NPar(), p);
239  return DoEval(x);
240  }
double DoEval(const double *x) const
evaluate the function (re-implement for being more efficient)
void SetParValues(unsigned int npar, const double *p) const

References ROOT::Math::WrappedParamFunctionGen< FuncPtr >::DoEval(), ROOT::Math::WrappedParamFunctionGen< FuncPtr >::NPar(), and ROOT::Math::WrappedParamFunctionGen< FuncPtr >::SetParValues().

Here is the call graph for this function:

◆ DoInit()

template<typename FuncPtr = FreeMultiFunctionPtr>
void ROOT::Math::WrappedParamFunctionGen< FuncPtr >::DoInit ( )
inlineprivate

Definition at line 243 of file WrappedParamFunction.h.

243  {
244  // calculate variable indices and set in X the parameter values
245  fVarIndices.reserve(fDim);
246  unsigned int npar = NPar();
247  for (unsigned int i = 0; i < npar + fDim; ++i) {
248  bool isVar = true;
249  for (unsigned int j = 0; j < npar; ++j) {
250  if (fParIndices[j] == i) {
251  isVar = false;
252  break;
253  }
254  }
255  if (isVar) fVarIndices.push_back(i);
256  }
257  assert ( fVarIndices.size() == fDim); // otherwise something is wrong
258 
259 // std::cout << "n variables " << fVarIndices.size() << std::endl;
260 // std::ostream_iterator<int> oi(std::cout," ");
261 // std::copy(fVarIndices.begin(), fVarIndices.end(), oi);
262 // std::cout << std::endl;
263 // assert( fVarIndices.size() == fDim);
264 // std::cout << this << std::endl;
265 
266  // set parameter values in fX
267  SetParValues(npar, fParams.empty() ? nullptr : &fParams.front());
268  for (unsigned int i = 0; i < npar; ++i) {
269  unsigned int j = fParIndices[i];
270  assert ( j < npar + fDim);
271  fX[j] = fParams[i];
272  }
273 
274  }

References ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fDim, ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fParams, ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fParIndices, ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fVarIndices, ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fX, ROOT::Math::WrappedParamFunctionGen< FuncPtr >::NPar(), and ROOT::Math::WrappedParamFunctionGen< FuncPtr >::SetParValues().

Referenced by ROOT::Math::WrappedParamFunctionGen< FuncPtr >::WrappedParamFunctionGen().

Here is the call graph for this function:

◆ NDim()

template<typename FuncPtr = FreeMultiFunctionPtr>
unsigned int ROOT::Math::WrappedParamFunctionGen< FuncPtr >::NDim ( ) const
inlinevirtual

Retrieve the dimension of the function

Implements ROOT::Math::IBaseFunctionMultiDimTempl< T >.

Definition at line 197 of file WrappedParamFunction.h.

197 { return fDim; }

References ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fDim.

◆ NPar()

◆ operator()() [1/3]

double ROOT::Math::IParametricFunctionMultiDimTempl< double >::operator() ( const T *  x) const
inlineinherited

Definition at line 125 of file IParamFunction.h.

126  {
127  return DoEval(x);
128  }
virtual double DoEval(const double *x) const

◆ operator()() [2/3]

double ROOT::Math::IParametricFunctionMultiDimTempl< double >::operator() ( const T *  x,
const double *  p 
) const
inlineinherited

Evaluate function at a point x and for given parameters p. This method does not change the internal status of the function (internal parameter values). If for some reason one prefers caching the parameter values, SetParameters(p) and then operator()(x) should be called. Use the pure virtual function DoEvalPar to implement it

Definition at line 120 of file IParamFunction.h.

121  {
122  return DoEvalPar(x, p);
123  }
virtual double DoEvalPar(const double *x, const double *p) const=0

◆ operator()() [3/3]

template<class T >
T ROOT::Math::IBaseFunctionMultiDimTempl< T >::operator() ( const T *  x) const
inlineinherited

Evaluate the function at a point x[]. Use the pure virtual private method DoEval which must be implemented by the sub-classes

Definition at line 92 of file IFunction.h.

93  {
94  return DoEval(x);
95  }
virtual T DoEval(const T *x) const =0

References ROOT::Math::IBaseFunctionMultiDimTempl< T >::DoEval().

Referenced by ROOT::Math::IGradientFunctionMultiDimTempl< T >::FdF().

Here is the call graph for this function:

◆ operator=()

template<typename FuncPtr = FreeMultiFunctionPtr>
WrappedParamFunctionGen& ROOT::Math::WrappedParamFunctionGen< FuncPtr >::operator= ( const WrappedParamFunctionGen< FuncPtr > &  )
private

◆ ParameterName()

virtual std::string ROOT::Math::IBaseParam::ParameterName ( unsigned int  i) const
inlinevirtualinherited

Return the name of the i-th parameter (starting from zero) Overwrite if want to avoid the default name ("Par_0, Par_1, ...")

Definition at line 83 of file IParamFunction.h.

84  {
85  assert(i < NPar());
86  return "Par_" + Util::ToString(i);
87  }
virtual unsigned int NPar() const =0
std::string ToString(const T &val)
Definition: Util.h:42

References ROOT::Math::IBaseParam::NPar(), and ROOT::Math::Util::ToString().

Referenced by ROOT::Fit::FitConfig::CreateParamsSettings().

Here is the call graph for this function:

◆ Parameters()

template<typename FuncPtr = FreeMultiFunctionPtr>
const double* ROOT::Math::WrappedParamFunctionGen< FuncPtr >::Parameters ( ) const
inlinevirtual

Access the parameter values

Implements ROOT::Math::IBaseParam.

Definition at line 185 of file WrappedParamFunction.h.

185  {
186  return fParams.empty() ? nullptr : &fParams.front();
187  }

References ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fParams.

◆ SetParameters()

template<typename FuncPtr = FreeMultiFunctionPtr>
void ROOT::Math::WrappedParamFunctionGen< FuncPtr >::SetParameters ( const double *  p)
inlinevirtual

Set the parameter values

Parameters
pvector of doubles containing the parameter values.

to be defined: can user change number of params ? At the moment no.

Implements ROOT::Math::IBaseParam.

Definition at line 189 of file WrappedParamFunction.h.

189  {
190  unsigned int npar = NPar();
191  std::copy(p, p+ npar, fParams.begin() );
192  SetParValues(npar, p);
193  }

References ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fParams, ROOT::Math::WrappedParamFunctionGen< FuncPtr >::NPar(), and ROOT::Math::WrappedParamFunctionGen< FuncPtr >::SetParValues().

Here is the call graph for this function:

◆ SetParValues()

template<typename FuncPtr = FreeMultiFunctionPtr>
void ROOT::Math::WrappedParamFunctionGen< FuncPtr >::SetParValues ( unsigned int  npar,
const double *  p 
) const
inlineprivate

Member Data Documentation

◆ fDim

◆ fFunc

template<typename FuncPtr = FreeMultiFunctionPtr>
FuncPtr ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fFunc
mutableprivate

◆ fParams

◆ fParIndices

template<typename FuncPtr = FreeMultiFunctionPtr>
std::vector<unsigned int> ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fParIndices
private

◆ fVarIndices

template<typename FuncPtr = FreeMultiFunctionPtr>
std::vector<unsigned int> ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fVarIndices
private

◆ fX

template<typename FuncPtr = FreeMultiFunctionPtr>
std::vector<double> ROOT::Math::WrappedParamFunctionGen< FuncPtr >::fX
mutableprivate

The documentation for this class was generated from the following file: