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::GSLMultiFitFunctionAdapter< FuncVector > Class Template Reference

Description

template<class FuncVector>
class ROOT::Math::GSLMultiFitFunctionAdapter< FuncVector >

Class for adapting a C++ functor class to C function pointers used by GSL MultiFit Algorithm The templated C++ function class must implement:

double operator( const double * x) and if the derivatives are required: void Gradient( const double * x, double * g) and void FdF( const double * x, double &f, double * g)

This class defines static methods with will be used to fill the gsl_multimin_function and gsl_multimin_function_fdf structs used by GSL. See for examples the GSL online manual

Definition at line 69 of file GSLMultiFitFunctionAdapter.h.

Static Public Member Functions

static int Df (const gsl_vector *x, void *p, gsl_matrix *h)
 
static int F (const gsl_vector *x, void *p, gsl_vector *f)
 
static int FDf (const gsl_vector *x, void *p, gsl_vector *f, gsl_matrix *h)
 evaluate derivative and function at the same time More...
 

Member Function Documentation

◆ Df()

template<class FuncVector >
static int ROOT::Math::GSLMultiFitFunctionAdapter< FuncVector >::Df ( const gsl_vector *  x,
void *  p,
gsl_matrix *  h 
)
inlinestatic

Definition at line 86 of file GSLMultiFitFunctionAdapter.h.

86  {
87 
88  // p is a pointer to an iterator of functions
89  unsigned int n = h->size1;
90  unsigned int npar = h->size2;
91  if (n == 0) return -1;
92  if (npar == 0) return -2;
93  FuncVector & funcVec = *( reinterpret_cast< FuncVector *> (p) );
94  for (unsigned int i = 0; i < n ; ++i) {
95  double * g = (h->data)+i*npar; //pointer to start of i-th row
96  assert ( npar == (funcVec[i]).NDim() );
97  (funcVec[i]).Gradient(x->data, g);
98  }
99  return 0;
100  }

◆ F()

template<class FuncVector >
static int ROOT::Math::GSLMultiFitFunctionAdapter< FuncVector >::F ( const gsl_vector *  x,
void *  p,
gsl_vector *  f 
)
inlinestatic

Definition at line 73 of file GSLMultiFitFunctionAdapter.h.

73  {
74  // p is a pointer to an iterator of functions
75  unsigned int n = f->size;
76  // need to copy iterator otherwise next time the function is called it wont work
77  FuncVector & funcVec = *( reinterpret_cast< FuncVector *> (p) );
78  if (n == 0) return -1;
79  for (unsigned int i = 0; i < n ; ++i) {
80  gsl_vector_set(f, i, (funcVec[i])(x->data) );
81  }
82  return 0;
83  }

◆ FDf()

template<class FuncVector >
static int ROOT::Math::GSLMultiFitFunctionAdapter< FuncVector >::FDf ( const gsl_vector *  x,
void *  p,
gsl_vector *  f,
gsl_matrix *  h 
)
inlinestatic

evaluate derivative and function at the same time

Definition at line 103 of file GSLMultiFitFunctionAdapter.h.

103  {
104  // should be implemented in the function
105  // p is a pointer to an iterator of functions
106  unsigned int n = h->size1;
107  unsigned int npar = h->size2;
108  if (n == 0) return -1;
109  if (npar == 0) return -2;
110  FuncVector & funcVec = *( reinterpret_cast< FuncVector *> (p) );
111  assert ( f->size == n);
112  for (unsigned int i = 0; i < n ; ++i) {
113  assert ( npar == (funcVec[i]).NDim() );
114  double fval = 0;
115  double * g = (h->data)+i*npar; //pointer to start of i-th row
116  (funcVec[i]).FdF(x->data, fval, g);
117  gsl_vector_set(f, i, fval );
118  }
119  return 0;
120  }

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