BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
RootResidualFunction Class Reference

Description

Minimizer function with access to single data element residuals, required by Fumili2 and GSLMultiMin minimizers.

Definition at line 37 of file RootResidualFunction.h.

Inheritance diagram for RootResidualFunction:
[legend]
Collaboration diagram for RootResidualFunction:
[legend]

Public Types

typedef FunctionType::BaseFunc BaseFunction
 
using Type_t = ROOT::Math::BasicFitMethodFunction< ROOT::Math::IMultiGenFunction >::Type_t
 

Public Member Functions

 RootResidualFunction (scalar_function_t objective_fun, gradient_function_t gradient_fun, size_t npars, size_t ndatasize)
 Constructs RootResidualFunction. More...
 
ROOT::Math::IMultiGenFunctionClone () const override
 
double DataElement (const double *pars, unsigned int index, double *gradients=nullptr) const override
 Evaluation of single data element residual. Will be called by ROOT minimizer. More...
 
virtual unsigned int NCalls () const
 
virtual unsigned int NDim () const
 
virtual unsigned int NPoints () const
 
virtual void ResetNCalls ()
 
Type_t Type () const override
 
virtual void UpdateNCalls () const
 

Private Member Functions

double DoEval (const double *pars) const override
 evaluation of chi2 More...
 

Private Attributes

unsigned int fNCalls
 
unsigned int fNDim
 
unsigned int fNPoints
 
size_t m_datasize
 
gradient_function_t m_gradient_fun
 User function to get residual and gradients. More...
 
size_t m_npars
 
scalar_function_t m_objective_fun
 User function to get value to minimizer. More...
 

Member Typedef Documentation

◆ BaseFunction

template<class FunctionType >
typedef FunctionType::BaseFunc ROOT::Math::BasicFitMethodFunction< FunctionType >::BaseFunction
inherited

Definition at line 41 of file FitMethodFunction.h.

◆ Type_t

Constructor & Destructor Documentation

◆ RootResidualFunction()

RootResidualFunction::RootResidualFunction ( scalar_function_t  objective_fun,
gradient_function_t  gradient_fun,
size_t  npars,
size_t  ndatasize 
)

Constructs RootResidualFunction.

Definition at line 19 of file RootResidualFunction.cpp.

22  : ROOT::Math::FitMethodFunction(static_cast<int>(npars), static_cast<int>(ndatasize))
23  , m_objective_fun(std::move(objective_fun))
24  , m_gradient_fun(std::move(gradient_fun))
25  , m_npars(npars)
26  , m_datasize(ndatasize)
27 {
28 }
scalar_function_t m_objective_fun
User function to get value to minimizer.
gradient_function_t m_gradient_fun
User function to get residual and gradients.
BasicFitMethodFunction< ROOT::Math::IMultiGenFunction > FitMethodFunction
Definition: Fitter.h:40

Referenced by Clone().

Member Function Documentation

◆ Clone()

ROOT::Math::IMultiGenFunction * RootResidualFunction::Clone ( ) const
override

Definition at line 35 of file RootResidualFunction.cpp.

36 {
38 }
RootResidualFunction(scalar_function_t objective_fun, gradient_function_t gradient_fun, size_t npars, size_t ndatasize)
Constructs RootResidualFunction.

References RootResidualFunction(), m_datasize, m_gradient_fun, m_npars, and m_objective_fun.

Here is the call graph for this function:

◆ DataElement()

double RootResidualFunction::DataElement ( const double *  pars,
unsigned int  index,
double *  gradients = nullptr 
) const
overridevirtual

Evaluation of single data element residual. Will be called by ROOT minimizer.

Returns residual value for given data element index. Transform call of ancient pointer based function to safer gradient_function_t.

Parameters
parsarray of fit parameter values from the minimizer
indexindex of residual element
gradientsif not zero, then array where we have to put gradients
Returns
value of residual for given data element index

Implements ROOT::Math::BasicFitMethodFunction< FunctionType >.

Definition at line 47 of file RootResidualFunction.cpp.

49 {
50  std::vector<double> par_values;
51  par_values.resize(m_npars, 0.0);
52  std::copy(pars, pars + m_npars, par_values.begin());
53 
54  std::vector<double> par_gradients;
55 
56  if (gradients)
57  par_gradients.resize(m_npars);
58 
59  // retrieving result from user function
60  double result = m_gradient_fun(par_values, index, par_gradients);
61 
62  // packing result back to minimizer's array
63  if (gradients)
64  for (size_t i = 0; i < m_npars; ++i)
65  gradients[i] = par_gradients[i];
66 
67  return result;
68 }

References m_gradient_fun, and m_npars.

◆ DoEval()

double RootResidualFunction::DoEval ( const double *  pars) const
overrideprivate

evaluation of chi2

Definition at line 70 of file RootResidualFunction.cpp.

71 {
72  std::vector<double> par_values;
73  par_values.resize(m_npars, 0.0);
74  std::copy(pars, pars + m_npars, par_values.begin());
75  return m_objective_fun(par_values);
76 }

References m_npars, and m_objective_fun.

◆ NCalls()

template<class FunctionType >
virtual unsigned int ROOT::Math::BasicFitMethodFunction< FunctionType >::NCalls ( ) const
inlinevirtualinherited

return the total number of function calls (overrided if needed)

Definition at line 85 of file FitMethodFunction.h.

85 { return fNCalls; }

References ROOT::Math::BasicFitMethodFunction< FunctionType >::fNCalls.

Referenced by ROOT::Math::GSLNLSMinimizer::NCalls().

◆ NDim()

template<class FunctionType >
virtual unsigned int ROOT::Math::BasicFitMethodFunction< FunctionType >::NDim ( ) const
inlinevirtualinherited

Number of dimension (parameters) . From IGenMultiFunction interface

Definition at line 61 of file FitMethodFunction.h.

61 { return fNDim; }

References ROOT::Math::BasicFitMethodFunction< FunctionType >::fNDim.

Referenced by ROOT::Math::LSResidualFunc::NDim().

◆ NPoints()

template<class FunctionType >
virtual unsigned int ROOT::Math::BasicFitMethodFunction< FunctionType >::NPoints ( ) const
inlinevirtualinherited

return the number of data points used in evaluating the function

Definition at line 75 of file FitMethodFunction.h.

75 { return fNPoints; }

References ROOT::Math::BasicFitMethodFunction< FunctionType >::fNPoints.

◆ ResetNCalls()

template<class FunctionType >
virtual void ROOT::Math::BasicFitMethodFunction< FunctionType >::ResetNCalls ( )
inlinevirtualinherited

reset number of function calls

Definition at line 95 of file FitMethodFunction.h.

95 { fNCalls = 0; }

References ROOT::Math::BasicFitMethodFunction< FunctionType >::fNCalls.

◆ Type()

RootResidualFunction::Type_t RootResidualFunction::Type ( ) const
overridevirtual

◆ UpdateNCalls()

template<class FunctionType >
virtual void ROOT::Math::BasicFitMethodFunction< FunctionType >::UpdateNCalls ( ) const
inlinevirtualinherited

update number of calls

Definition at line 90 of file FitMethodFunction.h.

90 { fNCalls++; }

References ROOT::Math::BasicFitMethodFunction< FunctionType >::fNCalls.

Member Data Documentation

◆ fNCalls

◆ fNDim

template<class FunctionType >
unsigned int ROOT::Math::BasicFitMethodFunction< FunctionType >::fNDim
privateinherited

◆ fNPoints

template<class FunctionType >
unsigned int ROOT::Math::BasicFitMethodFunction< FunctionType >::fNPoints
privateinherited

◆ m_datasize

size_t RootResidualFunction::m_datasize
private

Definition at line 60 of file RootResidualFunction.h.

Referenced by Clone().

◆ m_gradient_fun

gradient_function_t RootResidualFunction::m_gradient_fun
private

User function to get residual and gradients.

Definition at line 58 of file RootResidualFunction.h.

Referenced by Clone(), and DataElement().

◆ m_npars

size_t RootResidualFunction::m_npars
private

Definition at line 59 of file RootResidualFunction.h.

Referenced by Clone(), DataElement(), and DoEval().

◆ m_objective_fun

scalar_function_t RootResidualFunction::m_objective_fun
private

User function to get value to minimizer.

Definition at line 57 of file RootResidualFunction.h.

Referenced by Clone(), and DoEval().


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