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; }
70 virtual void calCovarianceMatrix(EigenMatrix &covar, double epsrel = 1e-8);
71
73 virtual void calFittingErrors(const EigenMatrix &covar, double chi2);
75 API::FunctionDomain_sptr getDomain() const { return m_domain; }
77 API::FunctionValues_sptr getValues() const { return m_values; }
79 void applyTies();
81 void reset() const;
82
84 void setIgnoreInvalidData(bool ignoreInvalidData) { m_ignoreInvalidData = ignoreInvalidData; }
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
99 virtual void updateValidateFitWeights() {};
100
101 bool isValid() const;
102 void checkValidity() const;
103 void calTransformationMatrixNumerically(EigenMatrix &tm);
104 void setDirty();
105 void validateNegativeFitWeights();
106
114 mutable std::vector<size_t> m_indexMap;
116 mutable size_t m_numberFunParams;
117
119 mutable bool m_dirtyVal;
121 mutable bool m_dirtyDeriv;
123 mutable bool m_dirtyHessian;
124
127
128 mutable double m_value;
131
132 mutable bool m_pushed;
133 mutable double m_pushedValue;
135
137
140};
141
142} // namespace CostFunctions
143} // namespace CurveFitting
144} // 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,...
A semi-abstract class for a cost function for fitting functions.
bool m_includePenalty
Flag to include constraint in cost function value.
void setIgnoreInvalidData(bool ignoreInvalidData)
Set to ignore invalid data.
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.
virtual void updateValidateFitWeights()
Update or validate the fit weights in m_values when necessary.
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:743
std::shared_ptr< FunctionDomain > FunctionDomain_sptr
typedef for a shared pointer
Helper class which provides the Collimation Length for SANS instruments.