19using namespace CurveFitting;
20using namespace Kernel;
29 const size_t nbreak = 10;
32 orderValidator.setLower(1);
33 declareAttribute(
"Order",
Attribute(3), orderValidator);
36 NBreakValidator.setLower(2);
37 declareAttribute(
"NBreak",
Attribute(
static_cast<int>(nbreak)), NBreakValidator);
40 startXValidator.setUpper(1.0);
41 startXValidator.setUpperExclusive(
true);
42 declareAttribute(
"StartX",
Attribute(0.0), startXValidator);
45 endXValidator.setLower(0.0);
46 endXValidator.setLowerExclusive(
true);
47 declareAttribute(
"EndX",
Attribute(1.0), endXValidator);
50 breakPointsValidator.setError(1e-8);
51 declareAttribute(
"BreakPoints",
Attribute(std::vector<double>(nbreak)), breakPointsValidator);
53 declareAttribute(
"Uniform",
Attribute(
true));
65 startXValidator->
setUpper(attEndX.asDouble());
68 endXValidator->
setLower(attStartX.asDouble());
70 auto breakPointsValidator =
72 breakPointsValidator->
setLower(attStartX.asDouble());
73 breakPointsValidator->setUpper(attEndX.asDouble());
85 size_t currentBBase = 0;
89 for (
size_t i = 0; i < nData; ++i) {
90 double x = xValues[i];
91 if (x < startX || x > endX) {
97 for (
size_t j = 0; j < np; ++j) {
127 for (
int i = 0; i < res.size(); i++) {
128 B[currentBBase + i] = res.data()[i];
143 const size_t clampedKnots = clamped ?
static_cast<size_t>(
getClampedKnots()) : 1u;
144 size_t nKnots =
m_knots.size();
145 for (
size_t i = currentBBase + clampedKnots; i < nKnots; i++) {
147 return i - clampedKnots;
150 return nKnots - clampedKnots * 2;
166 for (
size_t i = 0; i < nData; ++i) {
167 double x = xValues[i];
168 if (x < startX || x > endX) {
172 size_t jend = jstart + splineOrder;
176 for (
size_t j = jstart; j < jend; ++j) {
203 bool isUniform = attName ==
"Uniform" && att.
asBool();
206 if (attName ==
"BreakPoints") {
210 }
else if (isUniform || attName ==
"StartX" || attName ==
"EndX") {
213 }
else if (attName ==
"NBreak" || attName ==
"Order") {
223 return {
"Uniform",
"Order",
"NBreak",
"EndX",
"StartX",
"BreakPoints"};
234 for (
size_t i = 0; i < np; ++i) {
245 std::vector<double> breakPoints;
259 double prev = breakPoints[0];
260 for (
size_t i = 1; i < breakPoints.size(); ++i) {
261 double next = breakPoints[i];
263 throw std::invalid_argument(
"BreakPoints must be in ascending order.");
269 if (
static_cast<size_t>(nbreaks) != breakPoints.size()) {
286 std::vector<double> breakPoints(nBreak);
287 const double interval = (endX - startX) / (nBreak - 1.0);
288 std::generate(breakPoints.begin(), breakPoints.end(),
289 [
n = 0, &interval, &startX]()
mutable { return n++ * interval + startX; });
303 for (
int i = 0; i < nKnots; i++) {
304 if (i < clampedKnots) {
306 }
else if (i >= nKnots - clampedKnots) {
307 m_knots[i] = breakPoints[breakPoints.size() - 1];
309 m_knots[i] = breakPoints[i - clampedKnots + 1];
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
Mantid::API::IFunction::Attribute Attribute
Attribute is a non-fitting parameter.
std::vector< double > asVector() const
Returns vector<double> if attribute is vector<double>, throws exception otherwise.
int asInt() const
Returns int value if attribute is a int, throws exception otherwise.
Kernel::IValidator_sptr getValidator()
Return a clone of the attribute validator;.
double asDouble() const
Returns double value if attribute is a double, throws exception otherwise.
bool asBool() const
Returns bool value if attribute is a bool, throws exception otherwise.
virtual Attribute getAttribute(const std::string &name) const
Return a value of attribute attName.
void storeAttributeValue(const std::string &name, const API::IFunction::Attribute &value)
Store an attribute's value.
void clearAllParameters()
Nonvirtual member which removes all declared parameters.
void declareParameter(const std::string &name, double initValue=0, const std::string &description="") override
Declare a new parameter.
size_t nParams() const override
Total number of parameters.
double getParameter(size_t i) const override
Get i-th parameter.
A wrapper around Eigen::Matrix.
map_type & mutator()
Get the map to Eigen matrix.
A wrapper around Eigen::Vector.
double get(const size_t i) const
Get an element.
A wrapper around Eigen functions implementing a B-spline.
void resetKnotVector(const std::vector< double > &breakPoints)
Reset knot vector based upon break points.
size_t evaluateBasisFunctions(EigenVector &B, const double x, size_t currentBBase) const
evaluate non-zero basis functions, return which index to use as the base of the results vector.
std::vector< double > calcUniformBreakPoints(const double startX, const double endX)
Populate a vector with a uniform set of break points.
void initialiseSpline(const std::vector< double > &breakPoints)
initialise the m_spline variable based on the knot vector and given a vector of breakpoints
void function1D(double *out, const double *xValues, const size_t nData) const override
Execute the function.
int getNBreakPoints() const
Get number of Break Points.
void setAttribute(const std::string &attName, const Attribute &) override
Set a value to attribute attName.
int getClampedKnots() const
Get number of knots required to clamp the spline closed.
void resetKnots()
Reset b-spline knots.
int getDegree() const
Get the degree of constituent polynomial functions.
void resetValidators()
Reset Function Attribute Validators.
void resetParameters()
Reset fitting parameters.
int getNBSplineCoefficients()
Get number of B-Spline coefficients.
Spline1D m_spline
Member variable for spline.
int getNKnots() const
Get number of Knots.
size_t getSpanIndex(const double x, const size_t currentBBase, const bool clamped=true) const
get the index of the span/interval which x is in
void derivative1D(double *out, const double *xValues, size_t nData, const size_t order) const override
Calculate the derivatives for a set of points on the spline.
std::vector< std::string > getAttributeNames() const override
Returns a list of attribute names.
EigenMatrix evaluateBasisFnDerivatives(const double x, const size_t derivOrder) const
Evaluate derivatives up to a specified order for each non-zero basis function.
std::vector< double > m_knots
Kernel/ArrayBoundedValidator.h.
void setLower(const TYPE &value) noexcept
Set lower bound value.
BoundedValidator is a validator that requires the values to be between upper or lower bounds,...
void setLower(const TYPE &value) noexcept
Set lower bound value.
void setUpper(const TYPE &value) noexcept
Set upper bound value.
Eigen::Spline< double, 1, Eigen::Dynamic > Spline1D
std::string to_string(const wide_integer< Bits, Signed > &n)