NAG FL Interface
e02jdf (dim2_​spline_​ts_​sctr)

Note: this routine uses optional parameters to define choices in the problem specification and in the details of the algorithm. If you wish to use default settings for all of the optional parameters, you need only read Sections 1 to 10 of this document. If, however, you wish to reset some or all of the settings please refer to Section 11 for a detailed description of the specification of the optional parameters produced by the routine.
Settings help

FL Name Style:


FL Specification Language:


1 Purpose

e02jdf computes a spline approximation to a set of scattered data using a two-stage approximation method.
The computational complexity of the method grows linearly with the number of data points; hence large datasets are easily accommodated.

2 Specification

Fortran Interface
Subroutine e02jdf ( n, x, y, f, lsminp, lsmaxp, nxcels, nycels, lcoefs, coefs, iopts, opts, ifail)
Integer, Intent (In) :: n, lsminp, lsmaxp, nxcels, nycels, lcoefs
Integer, Intent (Inout) :: iopts(*), ifail
Real (Kind=nag_wp), Intent (In) :: x(n), y(n), f(n)
Real (Kind=nag_wp), Intent (Inout) :: opts(*)
Real (Kind=nag_wp), Intent (Out) :: coefs(lcoefs)
C Header Interface
#include <nag.h>
void  e02jdf_ (const Integer *n, const double x[], const double y[], const double f[], const Integer *lsminp, const Integer *lsmaxp, const Integer *nxcels, const Integer *nycels, const Integer *lcoefs, double coefs[], Integer iopts[], double opts[], Integer *ifail)
The routine may be called by the names e02jdf or nagf_fit_dim2_spline_ts_sctr.
Before calling e02jdf, e02zkf must be called with optstr set to "Initialize = e02jdf". Settings for optional algorithmic arguments may be specified by calling e02zkf before a call to e02jdf.

3 Description

e02jdf determines a smooth bivariate spline approximation to a set of data points (xi,yi,fi), for i=1,2,,n. Here, ‘smooth’ means C1 or C2. (You may select the degree of smoothing using the optional parameter Global Smoothing Level.)
The approximation domain is the bounding box [xmin,xmax] × [ymin,ymax] , where xmin (respectively ymin) and xmax (respectively ymax) denote the lowest and highest data values of the (xi) (respectively (yi)).
The spline is computed by local approximations on a uniform triangulation of the bounding box. These approximations are extended to a smooth spline representation of the surface over the domain. The local approximation scheme is controlled by the optional parameter Local Method. The schemes provided are: by least squares polynomial approximation (Davydov and Zeilfelder (2004)); by hybrid polynomial and radial basis function (RBF) approximation (Davydov et al. (2006)); or by pure RBF approximation (Davydov et al. (2005)).
The two-stage approximation method employed by e02jdf is derived from the TSFIT package of O. Davydov and F. Zeilfelder.
Values of the computed spline can subsequently be computed by calling e02jef or e02jff.

4 References

Davydov O, Morandi R and Sestini A (2006) Local hybrid approximation for scattered data fitting with bivariate splines Comput. Aided Geom. Design 23 703–721
Davydov O, Sestini A and Morandi R (2005) Local RBF approximation for scattered data fitting with bivariate splines Trends and Applications in Constructive Approximation M. G. de Bruin, D. H. Mache, and J. Szabados, Eds ISNM Vol. 151 Birkhauser 91–102
Davydov O and Zeilfelder F (2004) Scattered data fitting by direct extension of local polynomials to bivariate splines Advances in Comp. Math. 21 223–271

5 Arguments

1: n Integer Input
On entry: n, the number of data values to be fitted.
Constraint: n>1.
2: x(n) Real (Kind=nag_wp) array Input
3: y(n) Real (Kind=nag_wp) array Input
4: f(n) Real (Kind=nag_wp) array Input
On entry: the (xi,yi,fi) data values to be fitted.
Constraint: x(j)x(1) for some j=2,,n and y(k)y(1) for some k=2,,n; i.e., there are at least two distinct x and y values.
5: lsminp Integer Input
6: lsmaxp Integer Input
On entry: lsminp and lsmaxp are control parameters for the local approximations.
Each local approximation is computed on a local domain containing one of the triangles in the discretization of the bounding box. The size of each local domain will be adaptively chosen such that if it contains fewer than lsminp sample points it is expanded, else if it contains greater than lsmaxp sample points a thinning method is applied. lsmaxp mainly controls computational cost (in that working with a thinned set of points is cheaper and may be appropriate if the input data is densely distributed), while lsminp allows handling of different types of scattered data.
Setting lsmaxp<lsminp, and, therefore, forcing either expansion or thinning, may be useful for computing initial coarse approximations. In general smaller values for these arguments reduces cost.
A calibration procedure (experimenting with a small subset of the data to be fitted and validating the results) may be needed to choose the most appropriate values for lsminp and lsmaxp.
Constraints:
  • 1lsminpn;
  • lsmaxp1.
7: nxcels Integer Input
8: nycels Integer Input
On entry: nxcels (respectively nycels) is the number of cells in the x (respectively y) direction that will be used to create the triangulation of the bounding box of the domain of the function to be fitted.
Greater efficiency generally comes when nxcels and nycels are chosen to be of the same order of magnitude and are such that n is O(nxcels×nycels). Thus for a ‘square’ triangulation — when nxcels=nycels — the quantities n and nxcels should be of the same order of magnitude. See also Section 9.
Constraints:
  • nxcels1;
  • nycels1.
9: lcoefs Integer Input
On entry: the length of the array coefs of the computed spline coefficients.
Constraints:
  • if Global Smoothing Level=1, lcoefs (((nxcels+2)×(nycels+2)+1)/2) ×10+1;
  • if Global Smoothing Level=2, lcoefs 28 × (nxcels+2) × (nycels+2) × 4 + 1 .
10: coefs(lcoefs) Real (Kind=nag_wp) array Communication Array
On exit: if ifail=0 on exit, coefs contains the computed spline coefficients.
11: iopts(*) Integer array Communication Array
Note: the dimension of this array is dictated by the requirements of associated functions that must have been previously called. This array must be the same array passed as argument iopts in the previous call to e02zkf.
On entry: the contents of iopts must not be modified in any way either directly or indirectly, by further calls to e02zkf, before calling either or both of the evaluation routines e02jef and e02jff.
12: opts(*) Real (Kind=nag_wp) array Communication Array
Note: the dimension of this array is dictated by the requirements of associated functions that must have been previously called. This array must be the same array passed as argument opts in the previous call to e02zkf.
On entry: the contents of opts must not be modified in any way either directly or indirectly, by further calls to e02zkf, before calling either or both of the evaluation routines e02jef and e02jff.
13: ifail Integer Input/Output
On entry: ifail must be set to 0, −1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of −1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value −1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry ifail=0 or −1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
ifail=2
On entry, n=value.
Constraint: n>1.
ifail=4
On entry, lsminp=value and n=value.
Constraint: 1lsminpn.
ifail=5
On entry, lsmaxp=value.
Constraint: lsmaxp1.
ifail=6
On entry, nxcels=value.
Constraint: nxcels1.
ifail=7
On entry, nycels=value.
Constraint: nycels1.
ifail=8
On entry, lcoefs=value.
Constraint: if Global Smoothing Level=1,
lcoefs(((nxcels+2)×(nycels+2)+1)/2)×10+1;
if Global Smoothing Level=2,
lcoefs28×(nxcels+2)×(nycels+2)×4+1.
ifail=9
Option arrays are not initialized or are corrupted.
ifail=11
An unexpected algorithmic failure was encountered. Please contact NAG.
ifail=12
On entry, all elements of x or of y are equal.
ifail=20
The selected radial basis function cannot be used with the RBF local method.
ifail=21
The value of optional parameter Polynomial Starting Degree was invalid.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

Technical results on error bounds can be found in Davydov and Zeilfelder (2004), Davydov et al. (2006) and Davydov et al. (2005).
Local approximation by polynomials of degree d for n data points has optimal approximation order n -(d+1) / 2 . The improved approximation power of hybrid polynomial/RBF and of pure RBF approximations is shown in Davydov et al. (2006) and Davydov et al. (2005).
The approximation error for C1 global smoothing is O( n −2 ) . For C2 smoothing the error is O( n -7/2 ) when Supersmooth C2=YES and O( n −3 ) when Supersmooth C2=NO.
Whether maximal accuracy is achieved depends on the distribution of the input data and the choices of the algorithmic parameters. The references above contain extensive numerical tests and further technical discussions of how best to configure the method.

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
e02jdf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
e02jdf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9 Further Comments

n-linear complexity and memory usage can be attained for sufficiently dense input data if the triangulation parameters nxcels and nycels are chosen as recommended in their descriptions above. For sparse input data on such triangulations, if many expansion steps are required (see lsminp) the complexity may rise to be loglinear.
Parts of the pure RBF method used when Local Method=RBF have n-quadratic memory usage.
Note that if Local Method=HYBRID and an initial hybrid approximation is deemed unreliable (see the description of optional parameter Minimum Singular Value LHA), a pure polynomial approximation will be used instead on that local domain.

10 Example

The Franke function
f(x,y) = 0.75 exp(-( (9x-2) 2 + (9y-2) 2 )/4) + 0.75 exp(- (9x+1) 2 /49-(9y+1)/10) + 0.5 exp(-( (9x-7) 2 + (9y-3) 2 )/4) - 0.2 exp(- (9x-4) 2 - (9y-7) 2 )  
is widely used for testing surface-fitting methods. The example program randomly generates a number of points on this surface. From these a spline is computed and then evaluated at a vector of points and on a mesh.

10.1 Program Text

Program Text (e02jdfe.f90)

10.2 Program Data

Program Data (e02jdfe.d)

10.3 Program Results

Program Results (e02jdfe.r)
GnuplotProduced by GNUPLOT 5.4 patchlevel 6 gnuplot_plot_1 gnuplot_plot_2 0 0.2 0.4 0.6 0.8 1 x 0 0.2 0.4 0.6 0.8 1 y −0.2 0 0.2 0.4 0.6 0.8 1 1.2 Example Program Calculation and Evaluation of Bivariate Spline Fit from Scattered Data using Two-Stage Approximation

11 Optional Parameters

Several optional parameters in e02jdf control aspects of the algorithm, methodology used, logic or output. Their values are contained in the arrays iopts and opts; these must be initialized before calling e02jdf by first calling e02zkf with optstr set to "Initialize = e02jdf".
Each optional parameter has an associated default value; to set any of them to a non-default value, or to reset any of them to the default value, use e02zkf. The current value of an optional parameter can be queried using e02zlf.
The remainder of this section can be skipped if you wish to use the default values for all optional parameters.
The following is a list of the optional parameters available. A full description of each optional parameter is provided in Section 11.1.

11.1 Description of the Optional Parameters

For each option, we give a summary line, a description of the optional parameter and details of constraints.
The summary line contains:
Keywords and character values are case insensitive.
For e02jdf the maximum length of the parameter cvalue used by e02zlf is 16.
Averaged SplineaDefault =NO
When the bounding box is triangulated there are 8 equivalent configurations of the mesh. Setting Averaged Spline=YES will use the averaged value of the 8 possible local polynomial approximations over each triangle in the mesh. This usually gives better results but at (about 8 times) higher computational cost.
Constraint: Averaged Spline=YES or NO.
Global Smoothing LeveliDefault =1
The smoothness level for the global spline approximation.
Global Smoothing Level=1
Will use C1 piecewise cubics.
Global Smoothing Level=2
Will use C2 piecewise sextics.
Constraint: Global Smoothing Level=1 or 2.
Interpolation Only RBFaDefault =YES
If Interpolation Only RBF=YES, each local RBF approximation is computed by interpolation.
If Interpolation Only RBF=NO, each local RBF approximation is computed by a discrete least squares approach. This is likely to be more accurate and more expensive than interpolation.
If Local Method=HYBRID or POLYNOMIAL, this option setting is ignored.
Constraint: Interpolation Only RBF=YES or NO.
Local MethodaDefault =POLYNOMIAL
The local approximation scheme to use.
Local Method=POLYNOMIAL
Uses least squares polynomial approximations.
Local Method=HYBRID
Uses hybrid polynomial and RBF approximations.
Local Method=RBF
Uses pure RBF approximations.
In general POLYNOMIAL is less computationally expensive than HYBRID is less computationally expensive than RBF with the reverse ordering holding for accuracy of results.
Constraint: Local Method=POLYNOMIAL, HYBRID or RBF.
Minimum Singular Value LHArDefault =1.0
A tolerance measure for accepting or rejecting a local hybrid approximation (LHA) as reliable.
The solution of a local least squares problem solved on each triangle subdomain is accepted as reliable if the minimum singular value σ of the collocation matrix (of polynomial and radial basis function terms) associated with the least squares problem satisfies Minimum Singular Value LHAσ.
In general the approximation power will be reduced as Minimum Singular Value LHA is reduced. (A small σ indicates that the local data has hidden redundancies which prevent it from carrying enough information for a good approximation to be made.) Setting Minimum Singular Value LHA very large may have the detrimental effect that only approximations of low degree are deemed reliable.
A calibration procedure (experimenting with a small subset of the data to be fitted and validating the results) may be needed to choose the most appropriate value for this parameter.
If Local Method=POLYNOMIAL or RBF, this option setting is ignored.
Constraint: Minimum Singular Value LHA0.0.
Minimum Singular Value LPArDefault =1.0
A tolerance measure for accepting or rejecting a local polynomial approximation (LPA) as reliable. Clearly this setting is relevant when Local Method=POLYNOMIAL, but it also may be used when Local Method=HYBRID (see Section 9.)
The solution of a local least squares problem solved on each triangle subdomain is accepted as reliable if the minimum singular value σ of the matrix (of Bernstein polynomial values) associated with the least squares problem satisfies Minimum Singular Value LPAσ.
In general the approximation power will be reduced as Minimum Singular Value LPA is reduced. (A small σ indicates that the local data has hidden redundancies which prevent it from carrying enough information for a good approximation to be made.) Setting Minimum Singular Value LPA very large may have the detrimental effect that only approximations of low degree are deemed reliable.
Minimum Singular Value LPA will have no effect if Polynomial Starting Degree=0, and it will have little effect if the input data is ‘smooth’ (e.g., from a known function).
A calibration procedure (experimenting with a small subset of the data to be fitted and validating the results) may be needed to choose the most appropriate value for this parameter.
If Local Method=RBF, this option setting is ignored.
Constraint: Minimum Singular Value LPA0.0.
Polynomial Starting Degreei Default =5 if Local Method=HYBRID,
Default =1 otherwise
The degree to be used for the polynomial part in the initial step of each local approximation.
At this initial step the method will attempt to fit with a local approximation having polynomial part of degree Polynomial Starting Degree. If Local Method=POLYNOMIAL and the approximation is deemed unreliable (according to Minimum Singular Value LPA), the degree will be decremented by one and a new local approximation computed, ending with a constant approximation if no other is reliable. If Local Method=HYBRID and the approximation is deemed unreliable (according to Minimum Singular Value LHA), a pure polynomial approximation of this degree will be tried instead. The method then proceeds as in the POLYNOMIAL case.
Polynomial Starting Degree is bounded from above by the maximum possible spline degree, which is 6 (when performing C2 global super-smoothing). Note that the best-case approximation error (see Section 7) for C2 smoothing with Supersmooth C2=NO is achieved for local polynomials of degree 5; that is, for this level of global smoothing no further benefit is gained by setting Polynomial Starting Degree=6.
The default value gives a good compromise between efficiency and accuracy. In general the best approximation can be obtained by setting:
If Local Method=RBF, this option setting is ignored.
Constraints:
Radial Basis FunctionaDefault =MQ
Scaling Coefficient RBFrDefault =1.0
Radial Basis Function selects the RBF to use in each local RBF approximation, while Scaling Coefficient RBF selects the scale factor to use in its evaluation, as described below.
A calibration procedure (experimenting with a small subset of the data to be fitted and validating the results) may be needed to choose the most appropriate scale factor and RBF.
If Local Method=POLYNOMIAL, these option settings are ignored.
If Local Method=HYBRID or RBF, the following (conditionally) positive definite functions may be chosen.
Define R=x2+y2 and ρ=R/r.
GAUSS Gaussian exp(-ρ2)
IMQ inverse multiquadric 1/r2+R2
IMQ2 inverse multiquadric 1/(r2+R2)
IMQ3 inverse multiquadric 1/(r2+R2)(3/2)
IMQ0_5 inverse multiquadric 1/(r2+R2)(1/4)
WENDLAND31 H. Wendland's C2 function max(0,1-ρ) 4 (4ρ+1)
WENDLAND32 H. Wendland's C4 function max(0,1-ρ) 6 (35ρ2+18ρ+3)
WENDLAND33 H. Wendland's C6 function max(0,1-ρ) 8 (32ρ3+25ρ2+8ρ+1)
BUHMANNC3 M. Buhmann's C3 function 112/45 ρ (9/2) + 16/3 ρ(7/2) - 7 ρ4 -14/15 ρ2 + 1/9 if ρ1, 0 otherwise
MQ multiquadric r2 + R2
MQ1_5 multiquadric (r2+R2) (1.5/2)
POLYHARMONIC1_5 polyharmonic spline ρ1.5
POLYHARMONIC1_75 polyharmonic spline ρ1.75
If Local Method=HYBRID the following conditionally positive definite functions may also be chosen.
MQ2 multiquadric (r2+R2) log(r2+R2)
MQ3 multiquadric (r2+R2) (3/2)
TPS thin plate spline ρ2 logρ2
POLYHARMONIC3 polyharmonic spline ρ3
TPS4 thin plate spline ρ4 logρ2
POLYHARMONIC5 polyharmonic spline ρ5
TPS6 thin plate spline ρ6 logρ2
POLYHARMONIC7 polyharmonic spline ρ7
POLYHARMONIC9 polyharmonic spline ρ9
Constraints:
Separation LRBFArDefault =16.0/Scaling Coefficient RBF
A knot-separation parameter used to control the condition number of the matrix used in each local RBF approximation (LRBFA). A smaller value may mean greater numerical stability but fewer knots.
If Local Method=HYBRID or POLYNOMIAL, this option setting is ignored.
Constraint: Separation LRBFA>0.0.
Supersmooth C2aDefault =NO
If Supersmooth C2=YES, the C2 spline is generated using additional smoothness constraints. This usually gives better results but at higher computational cost.
If Global Smoothing Level=1 this option setting is ignored.
Constraint: Supersmooth C2=YES or NO.