naginterfaces.library.fit.dim2_spline_sctr¶
- naginterfaces.library.fit.dim2_spline_sctr(start, x, y, f, w, s, nx, lamda, ny, mu, comm)[source]¶
dim2_spline_sctr
computes a bicubic spline approximation to a set of scattered data. The knots of the spline are located automatically, but a single argument must be specified to control the trade-off between closeness of fit and smoothness of fit.For full information please refer to the NAG Library document for e02dd
https://www.nag.com/numeric/nl/nagdoc_29/flhtml/e02/e02ddf.html
- Parameters
- startstr, length 1
Determines whether calculations are to be performed afresh (Cold Start) or whether knots found in previous calls are to be used as an initial estimate of knot placement (Warm Start).
The function will build up the knot set starting with no interior knots. No values need be assigned to the arguments , , , or [‘wrk’].
The function will restart the knot-placing strategy using the knots found in a previous call of the function. In this case, the arguments , , , and [‘wrk’] must be unchanged from that previous call. This warm start can save much time in determining a satisfactory set of knots for the given value of . This is particularly useful when different smoothing factors are used for the same dataset.
- xfloat, array-like, shape
, , must be set to the coordinates of , the th data point, for . The order of the data points is immaterial.
- yfloat, array-like, shape
, , must be set to the coordinates of , the th data point, for . The order of the data points is immaterial.
- ffloat, array-like, shape
, , must be set to the coordinates of , the th data point, for . The order of the data points is immaterial.
- wfloat, array-like, shape
must be set to , the th value in the set of weights, for . Zero weights are permitted and the corresponding points are ignored, except when determining , , and (see Further Comments). For advice on the choice of weights, see the E02 Introduction.
- sfloat
The smoothing factor, .
For advice on the choice of , see Notes and Further Comments.
- nxint
If the warm start option is used, the value of must be left unchanged from the previous call.
- lamdafloat, array-like, shape
If the warm start option is used, the values must be left unchanged from the previous call.
- nyint
If the warm start option is used, the value of must be left unchanged from the previous call.
- mufloat, array-like, shape
If the warm start option is used, the values must be left unchanged from the previous call.
- commdict, communication object, modified in place
Communication structure.
On initial entry: need not be set.
- Returns
- nxint
The total number of knots, , of the computed spline with respect to the variable.
- lamdafloat, ndarray, shape
Contains the complete set of knots associated with the variable, i.e., the interior knots as well as the additional knots
and
needed for the B-spline representation (where and are as described in Notes).
- nyint
The total number of knots, , of the computed spline with respect to the variable.
- mufloat, ndarray, shape
Contains the complete set of knots associated with the variable, i.e., the interior knots as well as the additional knots
and
needed for the B-spline representation (where and are as described in Notes).
- cfloat, ndarray, shape
The coefficients of the spline approximation. is the coefficient defined in Notes.
- fpfloat
The weighted sum of squared residuals, , of the computed spline approximation. should equal within a relative tolerance of unless , when the spline has no interior knots and so is simply a bicubic polynomial. For knots to be inserted, must be set to a value below the value of produced in this case.
- rankint
Gives the rank of the system of equations used to compute the final spline (as determined by a suitable machine-dependent threshold). When , the solution is unique; otherwise the system is rank-deficient and the minimum-norm solution is computed. The latter case may be caused by too small a value of .
- Raises
- NagValueError
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, or : .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, , where is the number of points with nonzero weight: .
- (errno )
On entry, all the values in array are equal.
- (errno )
On entry, all the values in array are equal.
- (errno )
The number of knots needed in one direction is greater than or : , . Possibly is too small: .
- (errno )
No more knots added; the number of -spline coefficients already exceeds . Either or is probably too small: and .
- (errno )
No more knots added; the additional knot would coincide with an old one. Possibly an inaccurate data point has too large a weight, or is too small: .
- (errno )
The iterative process has failed to converge. Possibly is too small: .
- 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.
dim2_spline_sctr
determines a smooth bicubic spline approximation to the set of data points with weights , for .The approximation domain is considered to be the rectangle , where and denote the lowest and highest data values of .
The spline is given in the B-spline representation
where and denote normalized cubic B-splines, the former defined on the knots to and the latter on the knots to . For further details, see Hayes and Halliday (1974) for bicubic splines and de Boor (1972) for normalized B-splines.
The total numbers and of these knots and their values and are chosen automatically by the function. The knots and are the interior knots; they divide the approximation domain into subpanels , for , for . Then, much as in the curve case (see
dim1_spline_auto()
), the coefficients are determined as the solution of the following constrained minimization problem:minimize
subject to the constraint
where
is a measure of the (lack of) smoothness of . Its value depends on the discontinuity jumps in across the boundaries of the subpanels. It is zero only when there are no discontinuities and is positive otherwise, increasing with the size of the jumps (see Dierckx (1981b) for details).
denotes the weighted residual ,
and
is a non-negative number to be specified by you.
By means of the argument , ‘the smoothing factor’, you will then control the balance between smoothness and closeness of fit, as measured by the sum of squares of residuals in (3). If is too large, the spline will be too smooth and signal will be lost (underfit); if is too small, the spline will pick up too much noise (overfit). In the extreme cases the method would return an interpolating spline if were set to zero, and returns the least squares bicubic polynomial if is set very large. Experimenting with -values between these two extremes should result in a good compromise. (See Further Comments for advice on choice of .) Note however, that this function, unlike
dim1_spline_auto()
anddim2_spline_grid()
, does not allow to be set exactly to zero: to compute an interpolant to scattered data,interp.dim2_scat
orinterp.dim2_scat_shep
should be used.The method employed is outlined in Further Comments and fully described in Dierckx (1981a) and Dierckx (1981b). It involves an adaptive strategy for locating the knots of the bicubic spline (depending on the function underlying the data and on the value of ), and an iterative method for solving the constrained minimization problem once the knots have been determined.
Values and derivatives of the computed spline can subsequently be computed by calling
dim2_spline_evalv()
,dim2_spline_evalm()
ordim2_spline_derivm()
as described in Further Comments.
- References
de Boor, C, 1972, On calculating with B-splines, J. Approx. Theory (6), 50–62
Dierckx, P, 1981, An algorithm for surface fitting with spline functions, IMA J. Numer. Anal. (1), 267–283
Dierckx, P, 1981, An improved algorithm for curve fitting with spline functions, Report TW54, Department of Computer Science, Katholieke Univerciteit Leuven
Hayes, J G and Halliday, J, 1974, The least squares fitting of cubic spline surfaces to general data sets, J. Inst. Math. Appl. (14), 89–103
Peters, G and Wilkinson, J H, 1970, The least squares problem and pseudo-inverses, Comput. J. (13), 309–316
Reinsch, C H, 1967, Smoothing by spline functions, Numer. Math. (10), 177–183