9#include "MantidCurveFitting/DllConfig.h"
22namespace CurveFitting {
74 size_t order()
const {
return m_n; }
76 size_t size()
const {
return m_x.size(); }
78 double startX()
const {
return m_x.front(); }
80 double endX()
const {
return m_x.back(); }
82 double width()
const {
return endX() - startX(); }
84 const std::vector<double> &
xPoints()
const {
return m_x; }
86 const std::vector<double> &integrationWeights()
const;
88 double integrate(
const std::vector<double> &p)
const;
90 std::vector<double> calcA(
const std::vector<double> &p)
const;
92 std::vector<double> calcP(
const std::vector<double> &a)
const;
99 double eval(
double x,
const std::vector<double> &p)
const;
101 void evalVector(
const std::vector<double> &x,
const std::vector<double> &p, std::vector<double> &res)
const;
103 std::vector<double> evalVector(
const std::vector<double> &x,
const std::vector<double> &p)
const;
105 void derivative(
const std::vector<double> &a, std::vector<double> &aout)
const;
107 std::shared_ptr<ChebfunBase>
integral(
const std::vector<double> &a, std::vector<double> &aout)
const;
109 std::vector<double> roots(
const std::vector<double> &a)
const;
112 static std::shared_ptr<ChebfunBase> bestFit(
double start,
double end,
ChebfunFunctionType, std::vector<double> &p,
113 std::vector<double> &a,
double maxA = 0.0,
double tolerance = 0.0,
116 static std::shared_ptr<ChebfunBase> bestFit(
double start,
double end,
const API::IFunction &, std::vector<double> &p,
117 std::vector<double> &a,
double maxA = 0.0,
double tolerance = 0.0,
124 template <
class FunctionType>
125 static std::shared_ptr<ChebfunBase>
126 bestFitAnyTolerance(
double start,
double end, FunctionType f, std::vector<double> &p, std::vector<double> &a,
127 double maxA = 0.0,
double tolerance = 0.0,
size_t maxSize = 0);
130 std::vector<double> linspace(
size_t n)
const;
131 std::vector<double> smooth(
const std::vector<double> &xvalues,
const std::vector<double> &yvalues)
const;
140 void calcIntegrationWeights()
const;
145 std::vector<double> fitOdd(
const API::IFunction &f, std::vector<double> &pEven)
const;
147 static bool hasConverged(
const std::vector<double> &a,
double maxA,
double tolerance,
size_t shift = 0);
149 template <
class FunctionType>
150 static std::shared_ptr<ChebfunBase>
bestFitTempl(
double start,
double end, FunctionType f, std::vector<double> &p,
151 std::vector<double> &a,
double maxA,
double tolerance,
177template <
class FunctionType>
179 std::vector<double> &p, std::vector<double> &a,
180 double maxA,
double tolerance,
size_t maxSize) {
186 auto base =
bestFit(start, end, f, p, a, maxA, tol, maxSize);
This is an interface to a fitting function - a semi-abstarct class.
The ChebfunBase class provides a base for function approximation with Chebyshev polynomials.
size_t m_n
Polynomial order.
size_t size() const
Get the size of the base which is the number of x-points.
double m_start
Start of the interval.
ChebfunBase(ChebfunBase &&) noexcept=default
Move constructor.
ChebfunBase & operator=(const ChebfunBase &other)=delete
Private assingment operator to stress the immutability of ChebfunBase.
std::vector< double > m_x
The x-points.
std::vector< double > m_bw
The barycentric weights.
static const size_t g_maxNumberPoints
Maximum number of (x) points in a base.
static const double g_tolerance
Maximum tolerance in comparing doubles.
double width() const
Get the width of the interval.
double endX() const
End of the interval.
std::vector< double > m_integrationWeights
The integration weights.
ChebfunBase & operator=(ChebfunBase &&other)=delete
double startX() const
Start of the interval.
static std::shared_ptr< ChebfunBase > bestFit(double start, double end, ChebfunFunctionType, std::vector< double > &p, std::vector< double > &a, double maxA=0.0, double tolerance=0.0, size_t maxSize=0)
Fit a function until full convergence.
const std::vector< double > & xPoints() const
Get a reference to the x-points.
static std::shared_ptr< ChebfunBase > bestFitAnyTolerance(double start, double end, FunctionType f, std::vector< double > &p, std::vector< double > &a, double maxA=0.0, double tolerance=0.0, size_t maxSize=0)
Find best fit with highest possible tolerance (to be used with noisy data).
static std::shared_ptr< ChebfunBase > bestFitTempl(double start, double end, FunctionType f, std::vector< double > &p, std::vector< double > &a, double maxA, double tolerance, size_t maxSize)
Templated implementation of bestFit method.
double tolerance()
Tolerance for comparing doubles.
ChebfunBase(const ChebfunBase &)=default
Copy constructor.
const double m_tolerance
Actual tolerance in comparing doubles.
double m_end
End of the interval.
std::shared_ptr< ChebfunBase > ChebfunBase_sptr
std::function< double(double)> ChebfunFunctionType
Type of the approximated function.
double integral(double func(const double, const double, const double), const double a, const double b, const double g, const double w0)
Helper class which provides the Collimation Length for SANS instruments.