naginterfaces.library.fit.dim1_spline_knots¶
- naginterfaces.library.fit.dim1_spline_knots(x, y, w, lamda)[source]¶
dim1_spline_knots
computes a weighted least squares approximation to an arbitrary set of data points by a cubic spline with knots prescribed by you. Cubic spline interpolation can also be carried out.For full information please refer to the NAG Library document for e02ba
https://www.nag.com/numeric/nl/nagdoc_29/flhtml/e02/e02baf.html
- Parameters
- xfloat, array-like, shape
The values of the independent variable (abscissa), for . The values must satisfy the Schoenberg–Whitney conditions (see Further Comments).
- yfloat, array-like, shape
The values of the dependent variable (ordinate), for .
- wfloat, array-like, shape
The values of the weights, for . For advice on the choice of weights, see the E02 Introduction.
- lamdafloat, array-like, shape
must be set to the th (interior) knot, , for .
- Returns
- lamdafloat, ndarray, shape
The input values are unchanged, and , for , , , , contains the additional (exterior) knots introduced by the function. For advice on the choice of knots, see the E02 Introduction.
- cfloat, ndarray, shape
The coefficient of the B-spline , for . The remaining elements of the array are not used.
- ssfloat
The residual sum of squares, .
- Raises
- NagValueError
- (errno )
On entry, , and .
Constraint: .
- (errno )
On entry, , , and .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, the values are not in nondecreasing order. , , and .
Constraint: , where xdist is the set of distinct -values.
- (errno )
On entry, and .
Constraint: , where mdist is the number of distinct x-values.
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, the Schoenberg–Whitney conditions fail to hold for at least one subset of the distinct data abscissae. , , and .
Constraint: , where xdist is the set of distinct -values.
- (errno )
On entry, the Schoenberg–Whitney conditions fail to hold for at least one subset of the distinct data abscissae. , , and .
Constraint: , where xdist is the set of distinct -values.
- (errno )
On entry, the Schoenberg–Whitney conditions fail to hold for at least one subset of the distinct data abscissae. , , and .
Constraint: , where xdist is the set of distinct -values.
- Notes
In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.
dim1_spline_knots
determines a least squares cubic spline approximation to the set of data points with weights , for . The value of , where is the number of intervals of the spline (one greater than the number of interior knots), and the values of the knots , interior to the data interval, are prescribed by you.has the property that it minimizes , the sum of squares of the weighted residuals , for , where
The function produces this minimizing value of and the coefficients , where , in the B-spline representation
Here denotes the normalized B-spline of degree defined upon the knots .
In order to define the full set of B-splines required, eight additional knots and are inserted automatically by the function. The first four of these are set equal to the smallest and the last four to the largest .
The representation of in terms of B-splines is the most compact form possible in that only coefficients, in addition to the knots, fully define .
The method employed involves forming and then computing the least squares solution of a set of linear equations in the coefficients , for . The equations are formed using a recurrence relation for B-splines that is unconditionally stable (see Cox (1972) and de Boor (1972)), even for multiple (coincident) knots. The least squares solution is also obtained in a stable manner by using orthogonal transformations, viz. a variant of Givens rotations (see Gentleman (1974) and Gentleman (1973)). This requires only one equation to be stored at a time. Full advantage is taken of the structure of the equations, there being at most four nonzero values of for any value of and hence at most four coefficients in each equation.
For further details of the algorithm and its use see Cox (1974), Cox (1975) and Cox and Hayes (1973).
Subsequent evaluation of from its B-spline representation may be carried out using
dim1_spline_eval()
. If derivatives of are also required,dim1_spline_deriv()
may be used.dim1_spline_integ()
can be used to compute the definite integral of .
- References
Cox, M G, 1972, The numerical evaluation of B-splines, J. Inst. Math. Appl. (10), 134–149
Cox, M G, 1974, A data-fitting package for the non-specialist user, Software for Numerical Mathematics, (ed D J Evans), Academic Press
Cox, M G, 1975, Numerical methods for the interpolation and approximation of data by spline functions, PhD Thesis, City University, London
Cox, M G and Hayes, J G, 1973, Curve fitting: a guide and suite of algorithms for the non-specialist user, NPL Report NAC26, National Physical Laboratory
de Boor, C, 1972, On calculating with B-splines, J. Approx. Theory (6), 50–62
Gentleman, W M, 1973, Least squares computations by Givens transformations without square roots, J. Inst. Math. Applic. (12), 329–336
Gentleman, W M, 1974, Algorithm AS 75. Basic procedures for large sparse or weighted linear least squares problems, Appl. Statist. (23), 448–454
Schoenberg, I J and Whitney, A, 1953, On Polya frequency functions III, Trans. Amer. Math. Soc. (74), 246–259