Mantid
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Mantid::CurveFitting::CostFunctions::CostFuncFitting Class Referenceabstract

A semi-abstract class for a cost function for fitting functions. More...

#include <CostFuncFitting.h>

Inheritance diagram for Mantid::CurveFitting::CostFunctions::CostFuncFitting:
Mantid::API::ICostFunction Mantid::CurveFitting::CostFunctions::CostFuncLeastSquares Mantid::CurveFitting::CostFunctions::CostFuncPoisson Mantid::CurveFitting::CostFunctions::CostFuncRwp Mantid::CurveFitting::CostFunctions::CostFuncUnweightedLeastSquares Mantid::CurveFitting::FuncMinimisers::MaleableCostFunction

Public Member Functions

void applyTies ()
 Apply ties in the fitting function. More...
 
virtual void calCovarianceMatrix (EigenMatrix &covar, double epsrel=1e-8)
 Calculates covariance matrix. More...
 
virtual void calFittingErrors (const EigenMatrix &covar, double chi2)
 Calculate fitting errors. More...
 
 CostFuncFitting ()
 Constructor. More...
 
virtual void deriv (std::vector< double > &der) const override
 Calculate the derivatives of the cost function. More...
 
void drop ()
 Discard saved parameters, derivatives and hessian. More...
 
const EigenVectorgetDeriv () const
 Return cached or calculate the drivatives. More...
 
API::FunctionDomain_sptr getDomain () const
 Get the domain the fitting function is applied to. More...
 
virtual API::IFunction_sptr getFittingFunction () const
 Get fitting function. More...
 
const EigenMatrixgetHessian () const
 Return cached or calculate the Hessian. More...
 
double getParameter (size_t i) const override
 Get i-th parameter. More...
 
void getParameters (EigenVector &params) const
 Get all parameters into a GSLVector. More...
 
API::FunctionValues_sptr getValues () const
 Get FunctionValues where function values are stored. More...
 
size_t nParams () const override
 Number of parameters. More...
 
std::string parameterName (size_t i) const
 Get name of i-th parameter. More...
 
void pop ()
 Restore saved parameters, derivatives and hessian. More...
 
void push ()
 Save current parameters, derivatives and hessian. More...
 
void reset () const
 Reset the fitting function (neccessary if parameters get fixed/unfixed) More...
 
virtual void setFittingFunction (API::IFunction_sptr function, API::FunctionDomain_sptr domain, API::FunctionValues_sptr values)
 Set fitting function. More...
 
void setParameter (size_t i, const double &value) override
 Set i-th parameter. More...
 
void setParameters (const EigenVector &params)
 Set all parameters. More...
 
virtual double val () const override
 Calculate value of cost function. More...
 
virtual double valAndDeriv (std::vector< double > &der) const override
 Calculate the value and the derivatives of the cost function. More...
 
virtual double valDerivHessian (bool evalDeriv=true, bool evalHessian=true) const
 Calculate the value, the first and the second derivatives of the cost function. More...
 
- Public Member Functions inherited from Mantid::API::ICostFunction
virtual void deriv (std::vector< double > &der) const =0
 Calculate the derivatives of the cost function. More...
 
virtual double getParameter (size_t i) const =0
 Get i-th parameter. More...
 
virtual std::string name () const =0
 Get name of minimizer. More...
 
virtual size_t nParams () const =0
 Number of parameters. More...
 
virtual void setParameter (size_t i, const double &value)=0
 Set i-th parameter. More...
 
virtual std::string shortName () const
 Get short name of minimizer - useful for say labels in guis. More...
 
virtual double val () const =0
 Calculate value of cost function. More...
 
virtual double valAndDeriv (std::vector< double > &der) const =0
 Calculate the value and the derivatives of the cost function. More...
 
virtual ~ICostFunction ()=default
 Virtual destructor. More...
 

Protected Member Functions

virtual void addVal (API::FunctionDomain_sptr domain, API::FunctionValues_sptr values) const =0
 Increment to the cost function by evaluating it on a domain. More...
 
virtual void addValDerivHessian (API::IFunction_sptr function, API::FunctionDomain_sptr domain, API::FunctionValues_sptr values, bool evalDeriv=true, bool evalHessian=true) const =0
 Increments the cost function and its derivatives by evaluating them on a domain. More...
 
virtual void calActiveCovarianceMatrix (EigenMatrix &covar, double epsrel=1e-8)
 Calculates covariance matrix for fitting function's active parameters. More...
 
void calTransformationMatrixNumerically (EigenMatrix &tm)
 Calculate the transformation matrix T by numeric differentiation. More...
 
void checkValidity () const
 Throw a runtime_error if function is invalid. More...
 
bool isValid () const
 Is the function set and valid? More...
 
void setDirty ()
 Set all dirty flags. More...
 

Protected Attributes

EigenVector m_der
 
bool m_dirtyDeriv
 dirty derivatives flag More...
 
bool m_dirtyHessian
 dirty hessian flag More...
 
bool m_dirtyVal
 dirty value flag More...
 
API::FunctionDomain_sptr m_domain
 Shared pointer to the function domain. More...
 
API::IFunction_sptr m_function
 Shared pointer to the fitting function. More...
 
EigenMatrix m_hessian
 
bool m_includePenalty
 Flag to include constraint in cost function value. More...
 
std::vector< size_t > m_indexMap
 maps the cost function's parameters to the ones of the fitting function. More...
 
size_t m_numberFunParams
 Number of all parameters in the fitting function. More...
 
bool m_pushed
 
EigenVector m_pushedParams
 
double m_pushedValue
 
double m_value
 
API::FunctionValues_sptr m_values
 Shared poinetr to the function values. More...
 

Friends

class CurveFitting::ParDomain
 
class CurveFitting::SeqDomain
 

Detailed Description

A semi-abstract class for a cost function for fitting functions.

Implement val(), deriv(), and valAndDeriv() methods in a concrete class.

Author
Roman Tolchenov, Tessella plc
Date
10/04/2012

Definition at line 29 of file CostFuncFitting.h.

Constructor & Destructor Documentation

◆ CostFuncFitting()

Mantid::CurveFitting::CostFunctions::CostFuncFitting::CostFuncFitting ( )

Constructor.

Definition at line 26 of file CostFuncFitting.cpp.

Member Function Documentation

◆ addVal()

virtual void Mantid::CurveFitting::CostFunctions::CostFuncFitting::addVal ( API::FunctionDomain_sptr  domain,
API::FunctionValues_sptr  values 
) const
protectedpure virtual

◆ addValDerivHessian()

virtual void Mantid::CurveFitting::CostFunctions::CostFuncFitting::addValDerivHessian ( API::IFunction_sptr  function,
API::FunctionDomain_sptr  domain,
API::FunctionValues_sptr  values,
bool  evalDeriv = true,
bool  evalHessian = true 
) const
protectedpure virtual

◆ applyTies()

void Mantid::CurveFitting::CostFunctions::CostFuncFitting::applyTies ( )

Apply ties in the fitting function.

Definition at line 240 of file CostFuncFitting.cpp.

References m_function.

◆ calActiveCovarianceMatrix()

void Mantid::CurveFitting::CostFunctions::CostFuncFitting::calActiveCovarianceMatrix ( EigenMatrix covar,
double  epsrel = 1e-8 
)
protectedvirtual

◆ calCovarianceMatrix()

void Mantid::CurveFitting::CostFunctions::CostFuncFitting::calCovarianceMatrix ( EigenMatrix covar,
double  epsrel = 1e-8 
)
virtual

Calculates covariance matrix.

Parameters
covar:: Returned covariance matrix, here as
epsrel:: Is used to remove linear-dependent columns
Parameters
covar:: Returned covariance matrix
epsrel:: Is used to remove linear-dependent columns

Definition at line 150 of file CostFuncFitting.cpp.

References calActiveCovarianceMatrix(), calTransformationMatrixNumerically(), checkValidity(), m_function, and Mantid::CurveFitting::EigenMatrix::tr().

◆ calFittingErrors()

void Mantid::CurveFitting::CostFunctions::CostFuncFitting::calFittingErrors ( const EigenMatrix covar,
double  chi2 
)
virtual

Calculate fitting errors.

Calculate the fitting errors and assign them to the fitting function.

Parameters
covar:: A covariance matrix to use for error calculations. It can be calculated with calCovarianceMatrix().
chi2:: The final chi-squared of the fit.

Definition at line 182 of file CostFuncFitting.cpp.

References checkValidity(), Mantid::CurveFitting::EigenMatrix::get(), m_function, m_values, Mantid::CurveFitting::EigenMatrix::size1(), and Mantid::CurveFitting::EigenMatrix::size2().

◆ calTransformationMatrixNumerically()

void Mantid::CurveFitting::CostFunctions::CostFuncFitting::calTransformationMatrixNumerically ( EigenMatrix tm)
protected

Calculate the transformation matrix T by numeric differentiation.

Parameters
tm:: The output transformation matrix.

Definition at line 218 of file CostFuncFitting.cpp.

References getParameter(), m_function, nParams(), Mantid::CurveFitting::EigenMatrix::resize(), Mantid::CurveFitting::EigenMatrix::set(), and setParameter().

Referenced by calCovarianceMatrix().

◆ checkValidity()

void Mantid::CurveFitting::CostFunctions::CostFuncFitting::checkValidity ( ) const
protected

Throw a runtime_error if function is invalid.

Definition at line 114 of file CostFuncFitting.cpp.

References isValid().

Referenced by calCovarianceMatrix(), calFittingErrors(), getParameter(), nParams(), parameterName(), setParameter(), val(), and valDerivHessian().

◆ deriv()

void Mantid::CurveFitting::CostFunctions::CostFuncFitting::deriv ( std::vector< double > &  der) const
overridevirtual

Calculate the derivatives of the cost function.

Parameters
der:: Container to output the derivatives

Implements Mantid::API::ICostFunction.

Definition at line 334 of file CostFuncFitting.cpp.

References Mantid::CurveFitting::EigenVector::get(), m_der, nParams(), and valDerivHessian().

◆ drop()

void Mantid::CurveFitting::CostFunctions::CostFuncFitting::drop ( )

Discard saved parameters, derivatives and hessian.

Definition at line 504 of file CostFuncFitting.cpp.

References m_pushed, and setDirty().

◆ getDeriv()

const EigenVector & Mantid::CurveFitting::CostFunctions::CostFuncFitting::getDeriv ( ) const

Return cached or calculate the drivatives.

Definition at line 450 of file CostFuncFitting.cpp.

References m_der, m_dirtyDeriv, m_dirtyHessian, m_dirtyVal, m_pushed, and valDerivHessian().

◆ getDomain()

API::FunctionDomain_sptr Mantid::CurveFitting::CostFunctions::CostFuncFitting::getDomain ( ) const
inline

Get the domain the fitting function is applied to.

Definition at line 78 of file CostFuncFitting.h.

◆ getFittingFunction()

virtual API::IFunction_sptr Mantid::CurveFitting::CostFunctions::CostFuncFitting::getFittingFunction ( ) const
inlinevirtual

◆ getHessian()

const EigenMatrix & Mantid::CurveFitting::CostFunctions::CostFuncFitting::getHessian ( ) const

Return cached or calculate the Hessian.

Definition at line 463 of file CostFuncFitting.cpp.

References m_dirtyDeriv, m_dirtyHessian, m_dirtyVal, m_hessian, m_pushed, and valDerivHessian().

◆ getParameter()

double Mantid::CurveFitting::CostFunctions::CostFuncFitting::getParameter ( size_t  i) const
overridevirtual

Get i-th parameter.

Parameters
i:: Index of a parameter
Returns
:: Value of the parameter

Implements Mantid::API::ICostFunction.

Definition at line 42 of file CostFuncFitting.cpp.

References checkValidity(), m_function, and m_indexMap.

Referenced by calTransformationMatrixNumerically(), and getParameters().

◆ getParameters()

void Mantid::CurveFitting::CostFunctions::CostFuncFitting::getParameters ( EigenVector params) const

Get all parameters into a GSLVector.

Copy the parameter values to a GSLVector.

Parameters
params:: A vector to copy the parameters to

Definition at line 282 of file CostFuncFitting.cpp.

References getParameter(), nParams(), Mantid::CurveFitting::EigenVector::resize(), Mantid::CurveFitting::EigenVector::set(), and Mantid::CurveFitting::EigenVector::size().

Referenced by push().

◆ getValues()

API::FunctionValues_sptr Mantid::CurveFitting::CostFunctions::CostFuncFitting::getValues ( ) const
inline

Get FunctionValues where function values are stored.

Definition at line 80 of file CostFuncFitting.h.

◆ isValid()

bool Mantid::CurveFitting::CostFunctions::CostFuncFitting::isValid ( ) const
protected

Is the function set and valid?

Definition at line 91 of file CostFuncFitting.cpp.

References m_function, m_indexMap, m_numberFunParams, and reset().

Referenced by checkValidity().

◆ nParams()

size_t Mantid::CurveFitting::CostFunctions::CostFuncFitting::nParams ( ) const
overridevirtual

◆ parameterName()

std::string Mantid::CurveFitting::CostFunctions::CostFuncFitting::parameterName ( size_t  i) const

Get name of i-th parameter.

Get parameter name.

Parameters
i:: Index of a cost function parameter. It may be different from the index of the same parameter in the fitting function.
Returns
The name of the parameter as defined by the fitting function.

Definition at line 61 of file CostFuncFitting.cpp.

References checkValidity(), m_function, and m_indexMap.

◆ pop()

void Mantid::CurveFitting::CostFunctions::CostFuncFitting::pop ( )

Restore saved parameters, derivatives and hessian.

Definition at line 489 of file CostFuncFitting.cpp.

References m_dirtyDeriv, m_dirtyHessian, m_dirtyVal, m_pushed, m_pushedParams, m_pushedValue, m_value, and setParameters().

◆ push()

void Mantid::CurveFitting::CostFunctions::CostFuncFitting::push ( )

Save current parameters, derivatives and hessian.

Definition at line 476 of file CostFuncFitting.cpp.

References getParameters(), m_pushed, m_pushedParams, m_pushedValue, and valDerivHessian().

◆ reset()

void Mantid::CurveFitting::CostFunctions::CostFuncFitting::reset ( ) const

Reset the fitting function (neccessary if parameters get fixed/unfixed)

Definition at line 247 of file CostFuncFitting.cpp.

References m_dirtyDeriv, m_dirtyHessian, m_function, m_indexMap, m_numberFunParams, and Mantid::API::IConstraint::setParamToSatisfyConstraint().

Referenced by isValid(), and setFittingFunction().

◆ setDirty()

void Mantid::CurveFitting::CostFunctions::CostFuncFitting::setDirty ( )
protected

◆ setFittingFunction()

void Mantid::CurveFitting::CostFunctions::CostFuncFitting::setFittingFunction ( API::IFunction_sptr  function,
API::FunctionDomain_sptr  domain,
API::FunctionValues_sptr  values 
)
virtual

Set fitting function.

Set fitting function, domain it will operate on, and container for values.

Parameters
function:: The fitting function.
domain:: The domain for the function.
values:: The FunctionValues object which receives the calculated values and also contains the data to fit to and the fitting weights (reciprocal errors).

Definition at line 80 of file CostFuncFitting.cpp.

References m_domain, m_function, m_values, and reset().

◆ setParameter()

void Mantid::CurveFitting::CostFunctions::CostFuncFitting::setParameter ( size_t  i,
const double &  value 
)
overridevirtual

Set i-th parameter.

Parameters
i:: Index of a parameter
value:: New value of the parameter

Implements Mantid::API::ICostFunction.

Definition at line 50 of file CostFuncFitting.cpp.

References checkValidity(), m_function, m_indexMap, setDirty(), and value.

Referenced by calTransformationMatrixNumerically(), and setParameters().

◆ setParameters()

void Mantid::CurveFitting::CostFunctions::CostFuncFitting::setParameters ( const EigenVector params)

Set all parameters.

Copy the parameter values from a GSLVector.

Parameters
params:: A vector to copy the parameters from

Definition at line 267 of file CostFuncFitting.cpp.

References Mantid::CurveFitting::EigenVector::get(), m_function, nParams(), setParameter(), and Mantid::CurveFitting::EigenVector::size().

Referenced by pop().

◆ val()

double Mantid::CurveFitting::CostFunctions::CostFuncFitting::val ( ) const
overridevirtual

Calculate value of cost function.

Returns
:: The value of the function

Implements Mantid::API::ICostFunction.

Definition at line 295 of file CostFuncFitting.cpp.

References addVal(), Mantid::API::IConstraint::check(), checkValidity(), m_dirtyVal, m_domain, m_function, m_includePenalty, m_value, and m_values.

Referenced by Mantid::CurveFitting::CostFunctions::CostFuncLeastSquares::addVal(), and valDerivHessian().

◆ valAndDeriv()

double Mantid::CurveFitting::CostFunctions::CostFuncFitting::valAndDeriv ( std::vector< double > &  der) const
overridevirtual

Calculate the value and the derivatives of the cost function.

Parameters
der:: Container to output the derivatives
Returns
:: The value of the function

Implements Mantid::API::ICostFunction.

Definition at line 349 of file CostFuncFitting.cpp.

References Mantid::CurveFitting::EigenVector::get(), m_der, m_value, nParams(), and valDerivHessian().

◆ valDerivHessian()

double Mantid::CurveFitting::CostFunctions::CostFuncFitting::valDerivHessian ( bool  evalDeriv = true,
bool  evalHessian = true 
) const
virtual

Friends And Related Function Documentation

◆ CurveFitting::ParDomain

friend class CurveFitting::ParDomain
friend

Definition at line 133 of file CostFuncFitting.h.

◆ CurveFitting::SeqDomain

friend class CurveFitting::SeqDomain
friend

Definition at line 132 of file CostFuncFitting.h.

Member Data Documentation

◆ m_der

EigenVector Mantid::CurveFitting::CostFunctions::CostFuncFitting::m_der
mutableprotected

◆ m_dirtyDeriv

bool Mantid::CurveFitting::CostFunctions::CostFuncFitting::m_dirtyDeriv
mutableprotected

dirty derivatives flag

Definition at line 117 of file CostFuncFitting.h.

Referenced by getDeriv(), getHessian(), pop(), reset(), setDirty(), and valDerivHessian().

◆ m_dirtyHessian

bool Mantid::CurveFitting::CostFunctions::CostFuncFitting::m_dirtyHessian
mutableprotected

dirty hessian flag

Definition at line 119 of file CostFuncFitting.h.

Referenced by getDeriv(), getHessian(), pop(), reset(), setDirty(), and valDerivHessian().

◆ m_dirtyVal

bool Mantid::CurveFitting::CostFunctions::CostFuncFitting::m_dirtyVal
mutableprotected

dirty value flag

Definition at line 115 of file CostFuncFitting.h.

Referenced by getDeriv(), getHessian(), pop(), setDirty(), val(), and valDerivHessian().

◆ m_domain

API::FunctionDomain_sptr Mantid::CurveFitting::CostFunctions::CostFuncFitting::m_domain
protected

Shared pointer to the function domain.

Definition at line 106 of file CostFuncFitting.h.

Referenced by calActiveCovarianceMatrix(), setFittingFunction(), val(), and valDerivHessian().

◆ m_function

API::IFunction_sptr Mantid::CurveFitting::CostFunctions::CostFuncFitting::m_function
protected

◆ m_hessian

EigenMatrix Mantid::CurveFitting::CostFunctions::CostFuncFitting::m_hessian
mutableprotected

◆ m_includePenalty

bool Mantid::CurveFitting::CostFunctions::CostFuncFitting::m_includePenalty
protected

Flag to include constraint in cost function value.

Definition at line 122 of file CostFuncFitting.h.

Referenced by val(), and valDerivHessian().

◆ m_indexMap

std::vector<size_t> Mantid::CurveFitting::CostFunctions::CostFuncFitting::m_indexMap
mutableprotected

maps the cost function's parameters to the ones of the fitting function.

Definition at line 110 of file CostFuncFitting.h.

Referenced by getParameter(), isValid(), nParams(), parameterName(), reset(), and setParameter().

◆ m_numberFunParams

size_t Mantid::CurveFitting::CostFunctions::CostFuncFitting::m_numberFunParams
mutableprotected

Number of all parameters in the fitting function.

Definition at line 112 of file CostFuncFitting.h.

Referenced by isValid(), and reset().

◆ m_pushed

bool Mantid::CurveFitting::CostFunctions::CostFuncFitting::m_pushed
mutableprotected

Definition at line 128 of file CostFuncFitting.h.

Referenced by drop(), getDeriv(), getHessian(), pop(), push(), and valDerivHessian().

◆ m_pushedParams

EigenVector Mantid::CurveFitting::CostFunctions::CostFuncFitting::m_pushedParams
mutableprotected

Definition at line 130 of file CostFuncFitting.h.

Referenced by pop(), and push().

◆ m_pushedValue

double Mantid::CurveFitting::CostFunctions::CostFuncFitting::m_pushedValue
mutableprotected

Definition at line 129 of file CostFuncFitting.h.

Referenced by pop(), and push().

◆ m_value

double Mantid::CurveFitting::CostFunctions::CostFuncFitting::m_value
mutableprotected

◆ m_values

API::FunctionValues_sptr Mantid::CurveFitting::CostFunctions::CostFuncFitting::m_values
protected

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