|
Mantid
|
A semi-abstract class for a cost function for fitting functions. More...
#include <CostFuncFitting.h>
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 EigenVector & | getDeriv () 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 EigenMatrix & | getHessian () const |
| Return cached or calculate the Hessian. More... | |
| double | getParameter (size_t i) const override |
| Get i-th parameter. More... | |
| void | getParameters (EigenVector ¶ms) 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 ¶ms) |
| 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 |
A semi-abstract class for a cost function for fitting functions.
Implement val(), deriv(), and valAndDeriv() methods in a concrete class.
Definition at line 29 of file CostFuncFitting.h.
| Mantid::CurveFitting::CostFunctions::CostFuncFitting::CostFuncFitting | ( | ) |
Constructor.
Definition at line 26 of file CostFuncFitting.cpp.
|
protectedpure virtual |
Increment to the cost function by evaluating it on a domain.
Implemented in Mantid::CurveFitting::CostFunctions::CostFuncLeastSquares, and Mantid::CurveFitting::CostFunctions::CostFuncPoisson.
Referenced by Mantid::CurveFitting::SeqDomain::additiveCostFunctionVal(), Mantid::CurveFitting::ParDomain::additiveCostFunctionVal(), and val().
|
protectedpure virtual |
Increments the cost function and its derivatives by evaluating them on a domain.
Implemented in Mantid::CurveFitting::CostFunctions::CostFuncLeastSquares, and Mantid::CurveFitting::CostFunctions::CostFuncPoisson.
Referenced by Mantid::CurveFitting::SeqDomain::additiveCostFunctionValDerivHessian(), Mantid::CurveFitting::ParDomain::additiveCostFunctionValDerivHessian(), and valDerivHessian().
| void Mantid::CurveFitting::CostFunctions::CostFuncFitting::applyTies | ( | ) |
Apply ties in the fitting function.
Definition at line 240 of file CostFuncFitting.cpp.
References m_function.
|
protectedvirtual |
Calculates covariance matrix for fitting function's active parameters.
Reimplemented in Mantid::CurveFitting::CostFunctions::CostFuncUnweightedLeastSquares, and Mantid::CurveFitting::CostFunctions::CostFuncLeastSquares.
Definition at line 123 of file CostFuncFitting.cpp.
References Mantid::CurveFitting::getGSLMatrixView(), Mantid::CurveFitting::getGSLMatrixView_const(), Mantid::CurveFitting::EigenJacobian::getJ(), Mantid::CurveFitting::EigenMatrix::inspector(), m_domain, m_function, m_values, Mantid::CurveFitting::EigenMatrix::mutator(), nParams(), Mantid::CurveFitting::EigenMatrix::resize(), and Mantid::CurveFitting::EigenMatrix::tr().
Referenced by calCovarianceMatrix().
|
virtual |
Calculates covariance matrix.
| covar | :: Returned covariance matrix, here as |
| epsrel | :: Is used to remove linear-dependent columns |
| 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().
|
virtual |
Calculate fitting errors.
Calculate the fitting errors and assign them to the fitting function.
| 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().
|
protected |
Calculate the transformation matrix T by numeric differentiation.
| 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().
|
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().
|
overridevirtual |
Calculate the derivatives of the cost function.
| 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().
| 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().
| 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().
|
inline |
Get the domain the fitting function is applied to.
Definition at line 78 of file CostFuncFitting.h.
|
inlinevirtual |
Get fitting function.
Definition at line 68 of file CostFuncFitting.h.
Referenced by Mantid::CurveFitting::SeqDomain::additiveCostFunctionValDerivHessian(), Mantid::CurveFitting::ParDomain::additiveCostFunctionValDerivHessian(), and Mantid::CurveFitting::SeqDomain::rwpValDerivHessian().
| 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().
|
overridevirtual |
Get i-th parameter.
| i | :: Index of a 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().
| void Mantid::CurveFitting::CostFunctions::CostFuncFitting::getParameters | ( | EigenVector & | params | ) | const |
Get all parameters into a GSLVector.
Copy the parameter values to a GSLVector.
| 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().
|
inline |
Get FunctionValues where function values are stored.
Definition at line 80 of file CostFuncFitting.h.
|
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().
|
overridevirtual |
Number of parameters.
Implements Mantid::API::ICostFunction.
Definition at line 67 of file CostFuncFitting.cpp.
References checkValidity(), and m_indexMap.
Referenced by Mantid::CurveFitting::CostFunctions::CostFuncPoisson::addValDerivHessian(), calActiveCovarianceMatrix(), calTransformationMatrixNumerically(), deriv(), getParameters(), Mantid::CurveFitting::CostFunctions::CostFuncUnweightedLeastSquares::getResidualVariance(), setParameters(), valAndDeriv(), and valDerivHessian().
| std::string Mantid::CurveFitting::CostFunctions::CostFuncFitting::parameterName | ( | size_t | i | ) | const |
Get name of i-th parameter.
Get parameter name.
| i | :: Index of a cost function parameter. It may be different from the index of the same parameter in the fitting function. |
Definition at line 61 of file CostFuncFitting.cpp.
References checkValidity(), m_function, and m_indexMap.
| 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().
| 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().
| 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().
|
protected |
Set all dirty flags.
Definition at line 33 of file CostFuncFitting.cpp.
References m_dirtyDeriv, m_dirtyHessian, and m_dirtyVal.
Referenced by drop(), Mantid::CurveFitting::FuncMinimisers::MaleableCostFunction::setDirtyInherited(), and setParameter().
|
virtual |
Set fitting function.
Set fitting function, domain it will operate on, and container for values.
| 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().
|
overridevirtual |
Set i-th parameter.
| 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().
| void Mantid::CurveFitting::CostFunctions::CostFuncFitting::setParameters | ( | const EigenVector & | params | ) |
Set all parameters.
Copy the parameter values from a GSLVector.
| 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().
|
overridevirtual |
Calculate value of cost 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().
|
overridevirtual |
Calculate the value and the derivatives of the cost function.
| der | :: Container to output the derivatives |
Implements Mantid::API::ICostFunction.
Definition at line 349 of file CostFuncFitting.cpp.
References Mantid::CurveFitting::EigenVector::get(), m_der, m_value, nParams(), and valDerivHessian().
|
virtual |
Calculate the value, the first and the second derivatives of the cost function.
Calculate the value and the first and second derivatives of the cost function.
| evalDeriv | :: flag for evaluation of the first derivatives |
| evalHessian | :: flag for evaluation of the second derivatives |
Definition at line 366 of file CostFuncFitting.cpp.
References addValDerivHessian(), Mantid::API::IConstraint::check(), Mantid::API::IConstraint::checkDeriv(), Mantid::API::IConstraint::checkDeriv2(), checkValidity(), Mantid::Geometry::d, Mantid::CurveFitting::EigenVector::get(), Mantid::CurveFitting::EigenMatrix::get(), Mantid::CurveFitting::EigenMatrix::isEmpty(), m_der, m_dirtyDeriv, m_dirtyHessian, m_dirtyVal, m_domain, m_function, m_hessian, m_includePenalty, m_pushed, m_value, m_values, nParams(), Mantid::CurveFitting::EigenVector::resize(), Mantid::CurveFitting::EigenMatrix::resize(), Mantid::CurveFitting::EigenVector::set(), Mantid::CurveFitting::EigenMatrix::set(), val(), Mantid::CurveFitting::EigenMatrix::zero(), and Mantid::CurveFitting::EigenVector::zero().
Referenced by Mantid::CurveFitting::CostFunctions::CostFuncLeastSquares::calActiveCovarianceMatrix(), deriv(), getDeriv(), getHessian(), push(), and valAndDeriv().
|
friend |
Definition at line 133 of file CostFuncFitting.h.
|
friend |
Definition at line 132 of file CostFuncFitting.h.
|
mutableprotected |
Definition at line 125 of file CostFuncFitting.h.
Referenced by Mantid::CurveFitting::CostFunctions::CostFuncLeastSquares::addValDerivHessian(), Mantid::CurveFitting::CostFunctions::CostFuncPoisson::addValDerivHessian(), Mantid::CurveFitting::CostFunctions::CostFuncPoisson::calculateDerivative(), deriv(), getDeriv(), valAndDeriv(), and valDerivHessian().
|
mutableprotected |
dirty derivatives flag
Definition at line 117 of file CostFuncFitting.h.
Referenced by getDeriv(), getHessian(), pop(), reset(), setDirty(), and valDerivHessian().
|
mutableprotected |
dirty hessian flag
Definition at line 119 of file CostFuncFitting.h.
Referenced by getDeriv(), getHessian(), pop(), reset(), setDirty(), and valDerivHessian().
|
mutableprotected |
dirty value flag
Definition at line 115 of file CostFuncFitting.h.
Referenced by getDeriv(), getHessian(), pop(), setDirty(), val(), and valDerivHessian().
|
protected |
Shared pointer to the function domain.
Definition at line 106 of file CostFuncFitting.h.
Referenced by calActiveCovarianceMatrix(), setFittingFunction(), val(), and valDerivHessian().
|
protected |
Shared pointer to the fitting function.
Definition at line 104 of file CostFuncFitting.h.
Referenced by Mantid::CurveFitting::CostFunctions::CostFuncLeastSquares::addVal(), Mantid::CurveFitting::CostFunctions::CostFuncPoisson::addVal(), applyTies(), calActiveCovarianceMatrix(), calCovarianceMatrix(), calFittingErrors(), calTransformationMatrixNumerically(), getParameter(), isValid(), parameterName(), reset(), setFittingFunction(), setParameter(), setParameters(), val(), and valDerivHessian().
|
mutableprotected |
Definition at line 126 of file CostFuncFitting.h.
Referenced by Mantid::CurveFitting::CostFunctions::CostFuncLeastSquares::addValDerivHessian(), Mantid::CurveFitting::CostFunctions::CostFuncPoisson::addValDerivHessian(), Mantid::CurveFitting::CostFunctions::CostFuncLeastSquares::calActiveCovarianceMatrix(), Mantid::CurveFitting::CostFunctions::CostFuncPoisson::calculateHessian(), getHessian(), and valDerivHessian().
|
protected |
Flag to include constraint in cost function value.
Definition at line 122 of file CostFuncFitting.h.
Referenced by val(), and valDerivHessian().
|
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().
|
mutableprotected |
Number of all parameters in the fitting function.
Definition at line 112 of file CostFuncFitting.h.
|
mutableprotected |
Definition at line 128 of file CostFuncFitting.h.
Referenced by drop(), getDeriv(), getHessian(), pop(), push(), and valDerivHessian().
|
mutableprotected |
Definition at line 130 of file CostFuncFitting.h.
|
mutableprotected |
Definition at line 129 of file CostFuncFitting.h.
|
mutableprotected |
Definition at line 124 of file CostFuncFitting.h.
Referenced by Mantid::CurveFitting::CostFunctions::CostFuncLeastSquares::addVal(), Mantid::CurveFitting::CostFunctions::CostFuncPoisson::addVal(), Mantid::CurveFitting::CostFunctions::CostFuncLeastSquares::addValDerivHessian(), Mantid::CurveFitting::CostFunctions::CostFuncPoisson::calculateDerivative(), pop(), val(), valAndDeriv(), and valDerivHessian().
|
protected |
Shared poinetr to the function values.
Definition at line 108 of file CostFuncFitting.h.
Referenced by calActiveCovarianceMatrix(), calFittingErrors(), Mantid::CurveFitting::CostFunctions::CostFuncUnweightedLeastSquares::getResidualVariance(), setFittingFunction(), val(), and valDerivHessian().