naginterfaces.library.fit.dim2_spline_panel¶
- naginterfaces.library.fit.dim2_spline_panel(x, y, f, w, lamda, mu, point, eps)[source]¶
dim2_spline_panel
forms a minimal, weighted least squares bicubic spline surface fit with prescribed knots to a given set of data points.For full information please refer to the NAG Library document for e02da
https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/e02/e02daf.html
- Parameters
- xfloat, array-like, shape
The coordinates of the data point , for . The order of the data points is immaterial, but see the array .
- yfloat, array-like, shape
The coordinates of the data point , for . The order of the data points is immaterial, but see the array .
- ffloat, array-like, shape
The coordinates of the data point , for . The order of the data points is immaterial, but see the array .
- wfloat, array-like, shape
The weight of the th data point. It is important to note the definition of weight implied by the equation (1) in Notes, since it is also common usage to define weight as the square of this weight. In this function, each should be chosen inversely proportional to the (absolute) accuracy of the corresponding , as expressed, for example, by the standard deviation or probable error of the . When the are all of the same accuracy, all the may be set equal to .
- lamdafloat, array-like, shape
must contain the th interior knot associated with the variable , for . The knots must be in nondecreasing order and lie strictly within the range covered by the data values of . A knot is a value of at which the spline is allowed to be discontinuous in the third derivative with respect to , though continuous up to the second derivative. This degree of continuity can be reduced, if you require, by the use of coincident knots, provided that no more than four knots are chosen to coincide at any point. Two, or three, coincident knots allow loss of continuity in, respectively, the second and first derivative with respect to at the value of at which they coincide. Four coincident knots split the spline surface into two independent parts. For choice of knots see Further Comments.
- mufloat, array-like, shape
must contain the th interior knot associated with the variable , for .
- pointint, array-like, shape
Indexing information usually provided by
dim2_spline_sort()
which enables the data points to be accessed in the order which produces the advantageous matrix structure mentioned in Notes. This order is such that, if the plane is thought of as being divided into rectangular panels by the two sets of knots, all data in a panel occur before data in succeeding panels, where the panels are numbered from bottom to top and then left to right with the usual arrangement of axes, as indicated in Figure [label omitted].[figure omitted]
A data point lying exactly on one or more panel sides is considered to be in the highest numbered panel adjacent to the point.
dim2_spline_sort()
should be called to obtain the array , unless it is provided by other means.- epsfloat
A threshold for determining the effective rank of the system of linear equations. The rank is determined as the number of elements of the array which are nonzero. An element of is regarded as zero if it is less than . Machine precision is a suitable value for in most practical applications which have only or decimals accurate in data. If some coefficients of the fit prove to be very large compared with the data ordinates, this suggests that should be increased so as to decrease the rank. The array will give a guide to appropriate values of to achieve this, as well as to the choice of in other cases where some experimentation may be needed to determine a value which leads to a satisfactory fit.
- Returns
- lamdafloat, ndarray, shape
The interior knots to are unchanged, and the segments and contain additional (exterior) knots introduced by the function in order to define the full set of B-splines required. The four knots in the first segment are all set equal to the lowest data value of and the other four additional knots are all set equal to the highest value: there is experimental evidence that coincident end-knots are best for numerical accuracy. The complete array must be left undisturbed if
dim2_spline_evalv()
ordim2_spline_evalm()
is to be used subsequently.- mufloat, ndarray, shape
The same remarks apply to as to above, with replacing , and replacing .
- dlfloat, ndarray, shape
Gives the squares of the diagonal elements of the reduced triangular matrix, divided by the mean squared weight. It includes those elements, less than , which are treated as zero (see Notes).
- cfloat, ndarray, shape
Gives the coefficients of the fit. is the coefficient of Notes and Further Comments, for , for . These coefficients are used by
dim2_spline_evalv()
ordim2_spline_evalm()
to calculate values of the fitted function.- sigmafloat
, the weighted sum of squares of residuals. This is not computed from the individual residuals but from the right-hand sides of the orthogonally-transformed linear equations. For further details see page 97 of Hayes and Halliday (1974). The two methods of computation are theoretically equivalent, but the results may differ because of rounding error.
- rankint
The rank of the system as determined by the value of the threshold .
The least squares solution is unique.
The minimal least squares solution is computed.
- Raises
- NagValueError
- (errno )
At least one set of knots is not in nondecreasing order.
- (errno )
More than four knots coincide at a single point.
- (errno )
Array does not indicate the data points in panel order.
- (errno )
On entry, , , and .
Constraint: .
- (errno )
On entry, , and .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
All the weights are zero, or rank determined as zero.
- Notes
dim2_spline_panel
determines a bicubic spline fit to the set of data points with weights , for . The two sets of internal knots of the spline, and , associated with the variables and respectively, are prescribed by you. These knots can be thought of as dividing the data region of the plane into panels (see Figure [label omitted] in Parameters). A bicubic spline consists of a separate bicubic polynomial in each panel, the polynomials joining together with continuity up to the second derivative across the panel boundaries.has the property that , the sum of squares of its weighted residuals , for , where
is as small as possible for a bicubic spline with the given knot sets. The function produces this minimized value of and the coefficients in the B-spline representation of – see Further Comments.
dim2_spline_evalv()
,dim2_spline_evalm()
anddim2_spline_derivm()
are available to compute values and derivatives of the fitted spline from the coefficients .The least squares criterion is not always sufficient to determine the bicubic spline uniquely: there may be a whole family of splines which have the same minimum sum of squares. In these cases, the function selects from this family the spline for which the sum of squares of the coefficients is smallest: in other words, the minimal least squares solution. This choice, although arbitrary, reduces the risk of unwanted fluctuations in the spline fit. The method employed involves forming a system of linear equations in the coefficients and then computing its least squares solution, which will be the minimal least squares solution when appropriate. The basis of the method is described in Hayes and Halliday (1974). The matrix of the equation is formed using a recurrence relation for B-splines which is numerically stable (see Cox (1972) and de Boor (1972) – the former contains the more elementary derivation but, unlike de Boor (1972), does not cover the case of coincident knots). The least squares solution is also obtained in a stable manner by using orthogonal transformations, viz. a variant of Givens rotation (see Gentleman (1973)). This requires only one row of the matrix to be stored at a time. Advantage is taken of the stepped-band structure which the matrix possesses when the data points are suitably ordered, there being at most sixteen nonzero elements in any row because of the definition of B-splines. First the matrix is reduced to upper triangular form and then the diagonal elements of this triangle are examined in turn. When an element is encountered whose square, divided by the mean squared weight, is less than a threshold , it is replaced by zero and the rest of the elements in its row are reduced to zero by rotations with the remaining rows. The rank of the system is taken to be the number of nonzero diagonal elements in the final triangle, and the nonzero rows of this triangle are used to compute the minimal least squares solution. If all the diagonal elements are nonzero, the rank is equal to the number of coefficients and the solution obtained is the ordinary least squares solution, which is unique in this case.
- References
Cox, M G, 1972, The numerical evaluation of B-splines, J. Inst. Math. Appl. (10), 134–149
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
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