Mantid
Loading...
Searching...
No Matches
CostFuncFitting.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2010 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
13#include "MantidAPI/IFunction.h"
14#include "MantidCurveFitting/DllConfig.h"
17
18namespace Mantid {
19namespace CurveFitting {
20class SeqDomain;
21class ParDomain;
22namespace CostFunctions {
29class MANTID_CURVEFITTING_DLL CostFuncFitting : public API::ICostFunction {
30public:
33 size_t nParams() const override;
37 double getParameter(size_t i) const override;
41 void setParameter(size_t i, const double &value) override;
43 std::string parameterName(size_t i) const;
45 void setParameters(const EigenVector &params);
47 void getParameters(EigenVector &params) const;
48
50 virtual double val() const override;
52 virtual void deriv(std::vector<double> &der) const override;
54 virtual double valAndDeriv(std::vector<double> &der) const override;
57 virtual double valDerivHessian(bool evalDeriv = true, bool evalHessian = true) const;
58 const EigenVector &getDeriv() const;
59 const EigenMatrix &getHessian() const;
60 void push();
61 void pop();
62 void drop();
63
65 virtual void setFittingFunction(API::IFunction_sptr function, API::FunctionDomain_sptr domain,
68 virtual API::IFunction_sptr getFittingFunction() const { return m_function; }
73 virtual void calCovarianceMatrix(EigenMatrix &covar, double epsrel = 1e-8);
74
76 virtual void calFittingErrors(const EigenMatrix &covar, double chi2);
78 API::FunctionDomain_sptr getDomain() const { return m_domain; }
80 API::FunctionValues_sptr getValues() const { return m_values; }
82 void applyTies();
84 void reset() const;
85
86protected:
88 virtual void calActiveCovarianceMatrix(EigenMatrix &covar, double epsrel = 1e-8);
90 virtual void addVal(API::FunctionDomain_sptr domain, API::FunctionValues_sptr values) const = 0;
91
95 API::FunctionValues_sptr values, bool evalDeriv = true,
96 bool evalHessian = true) const = 0;
97
98 bool isValid() const;
99 void checkValidity() const;
100 void calTransformationMatrixNumerically(EigenMatrix &tm);
101 void setDirty();
102
110 mutable std::vector<size_t> m_indexMap;
112 mutable size_t m_numberFunParams;
113
115 mutable bool m_dirtyVal;
117 mutable bool m_dirtyDeriv;
119 mutable bool m_dirtyHessian;
120
123
124 mutable double m_value;
127
128 mutable bool m_pushed;
129 mutable double m_pushedValue;
131
134};
135
136} // namespace CostFunctions
137} // namespace CurveFitting
138} // namespace Mantid
double value
The value of the point.
Definition: FitMW.cpp:51
An interface for specifying the cost function to be used with Fit algorithm or minimizers,...
Definition: ICostFunction.h:24
A semi-abstract class for a cost function for fitting functions.
bool m_includePenalty
Flag to include constraint in cost function value.
API::FunctionValues_sptr m_values
Shared poinetr to the function values.
std::vector< size_t > m_indexMap
maps the cost function's parameters to the ones of the fitting function.
API::FunctionDomain_sptr m_domain
Shared pointer to the function domain.
API::FunctionValues_sptr getValues() const
Get FunctionValues where function values are stored.
virtual void addVal(API::FunctionDomain_sptr domain, API::FunctionValues_sptr values) const =0
Increment to the cost function by evaluating it on a domain.
API::IFunction_sptr m_function
Shared pointer to the fitting function.
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.
size_t m_numberFunParams
Number of all parameters in the fitting function.
virtual API::IFunction_sptr getFittingFunction() const
Get fitting function.
API::FunctionDomain_sptr getDomain() const
Get the domain the fitting function is applied to.
A wrapper around Eigen::Matrix.
Definition: EigenMatrix.h:33
A wrapper around Eigen::Vector.
Definition: EigenVector.h:27
An implementation of SeqDomain for parallel cost function and derivatives computation.
Definition: ParDomain.h:23
An implementation of CompositeDomain.
Definition: SeqDomain.h:30
std::shared_ptr< FunctionValues > FunctionValues_sptr
typedef for a shared pointer
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
Definition: IFunction.h:732
std::shared_ptr< FunctionDomain > FunctionDomain_sptr
typedef for a shared pointer
Helper class which provides the Collimation Length for SANS instruments.