This function creates spline using the set of points and interpolates the input between them taking into account the least-squares fit.
First and second derivatives from the spline can be calculated by using the derivative1D function.
A BSpline is a polynomial function of order N, defined between an interval . When using BSplines for interpolation or for fitting, we essentially chain BSplines together so that each spline passes through the breakpoints in that interval.
There are conditions at each breakpoint that need to be fulfilled for the overall BSpline to be piecewise-smooth.
To demonstrate these conditions we can set up a basic BSpline of order 2 with 3 breakpoints:
Breakpoints :
Our BSpline will be defined as the following:
We can write our function as a series
where is the coefficient of the BSpline. This coefficient maps to our fitting parameters found below. The coefficients to can be readily retrieved from a least-squares fit.
If is our number of breakpoints for a spline of order then we can expect coefficients as the -2 accounts for our 2 exterior breakpoints at and .
To make our BSpline piecewise-smooth we must ensure that these conditions are satisfied:
This point of smoothness is represented by the red circle in the graph below of our BSpline function
BSplines are commonly used when interpolating between points. An interpolation is different to a fit as it uses all of the data points to connect a straight line through them. It acts as if all of your data points are also breakpoints and a smooth spline of order N will connect the points together.
Fitting with a BSpline is different to interpolation as it requires your number of breakpoints to be less than your number of data points. The reason being, the BSplines will attempt to fit close to the data points but might only pass through some of the data points. It is not necessarily going to pass through all data points, only passing through breakpoints is gauranteed.
An example of a fit using BSplines of order 3 can be seen in the image below, our breakpoints have been highlighted in green. The original dataset is in black, while the calculated fit using a least-squares fit with 4 breakpoints is in red.
Name | Type | Default | Description |
---|---|---|---|
Uniform | Boolean | true | If set to true, all breakpoints will be evenly spaced between startX and endX |
Order | Integer | 3 | The order of the spline you wish to use i.e Order = 2 will use Quadratic Splines |
NBreak | Integer | - | The number of breakpoints you wish to have (must be greater than 1) |
StartX | Double | 0.0 | Minimum value of X |
EndX | Double | 1.0 | Maximum value of X |
BreakPoints | Double list | - | If Uniform is set to false, you must supply the breakpoints as a comma-separated list |
Name | Default | Description |
---|---|---|
A0 | 0.0 | |
A1 | 0.0 | |
A2 | 0.0 | |
A3 | 0.0 | |
A4 | 0.0 | |
A5 | 0.0 | |
A6 | 0.0 | |
A7 | 0.0 | |
A8 | 0.0 | |
A9 | 0.0 | |
A10 | 0.0 |
Categories: FitFunctions | Background
C++ source: BSpline.cpp (last modified: 2017-06-19)
C++ header: BSpline.h (last modified: 2017-06-19)