Radial basis functions: Implementation

In the interface to the library we break somewhat with the mathematical notation of the previous section; the set of nodes \(\mathbf{x}_i (i = 1, 2, \ldots, n)\) is represented as a set of (NumPy) arrays of the coordinates of the nodes. So a (mathematical) set of n 3-dimensional nodes would be represented as 3 NumPy arrays (x, y, z say), each with n elements.

The library does not care a jot what shape the arrays x, y, z is (they are flattened to 1-dimensional vectors internally in any case); except that they are the same shape. This is a common representation in interpreted languages (Python, Matlab, Octave, …) so there is a certain amount of library support for it: see NumPy’s meshgrid, for example.

The RBFBase class

class mvpoly.rbf.RBFBase(*args, **kwargs)

Base class for radial basis functions

A class for radial basis function approximation/interpolation of n-dimensional scattered data.

Parameters:
*argsarrays

x, y, z, …, f, where x, y, z, … are the vectors of the coordinates of the nodes and f is the array of values at the nodes

smoothfloat, optional

Values greater than zero increase the smoothness of the approximation. The default value of zero gives interpolation, i.e., the function will always go through the nodal points.

poly_ordernon-negative integer or None, optional (default 1)

The order of a (low-order) polynomial to be fitted and added to the input data; the default of 1 corresponds to a linear term, 0 to a constant, None for no polynomial part.

poly_classone of the MVPoly polynomial classes, optional

Notes

The base class is not used directly, instead one uses a subclass for which a particular basis function is defined,

Examples

For a set of n points in 3-dimensional space with coordinates in the n-vectors x, y and z; and with f being a n-vector of the data from which to interpolate, the interpolant rbf is created with

>>> from mvpoly.rbf import RBFGauss
>>> x, y, z, f = np.random.rand(4, 50)
>>> rbf = RBFGauss(x, y, z, f)
>>> rbf.name
Gaussian
__init__(*args, **kwargs)
__call__(*args, **kwargs)

Evaluate the interpolant instance

Parameters:
*argsnumbers or arrays

The vectors components x, y, z, … at which to evaluate the interpolant. All must be the same shape.

largeBoolean, optional (default False)

Interpolation is performed iteratively rather than in a vectorised manner; this saves memory but is slower, use if there are a large number of sites on which to interpolate.

Returns:
array

A NumPy array which is the same shape as (each of the) input arguments.

Examples

With the interpolant rbf as defined in the example above, one can evaluate the interpolant at arbitrary points xi, yi, zi (in this case on a uniform grid) with

>>> L = np.linspace(0, 1, 20)
>>> xi, yi, zi = np.meshgrid(L, L, L)
>>> fi = rbf(xi, yi, zi, large=False)
>>> fi.shape
(20, 20, 20)
__weakref__

list of weak references to the object (if defined)

The RBFGaussian subclass

class mvpoly.rbf.RBFGaussian(*args, **kwargs)

An RBF subclass for the Gaussian function

\[\phi(r) = \exp\left(-(r/\epsilon)^2\right)\]

The parameters are as for the base class RBFBase, and in addition

Parameters:
epsilonfloat, optional

Adjustable constant modifying the shape of the radial function, if not specified then a value will be calculated which is approximately twice the average distance between adjacent nodes.

radial(r)

The radial function itself

The RBFMultiQuadric subclass

class mvpoly.rbf.RBFMultiQuadric(*args, **kwargs)

An RBF subclass for the multiquadric function

\[\phi(r) = \sqrt{(r/\epsilon)^2 + 1}.\]

The parameters are as for the base class RBFBase, and in addition

Parameters:
epsilonfloat, optional

Adjustable constant modifying the shape of the radial function, if not specified then a value will be calculated which is approximately the average distance between adjacent nodes.

radial(r)

The radial function itself

The RBFInverseMultiQuadric subclass

class mvpoly.rbf.RBFInverseMultiQuadric(*args, **kwargs)

An RBF subclass for the inverse multiquadric

\[\phi(r) = \frac{1}{\sqrt{(r/\epsilon)^2 + 1}}.\]

The parameters are as for the base class RBFBase, and in addition

Parameters:
epsilonfloat, optional

Adjustable constant modifying the shape of the radial function, if not specified then a value will be calculated which is approximately the average distance between adjacent nodes.

radial(r)

The radial function itself

The RBFThinPlateSpline subclass

class mvpoly.rbf.RBFThinPlateSpline(*args, **kwargs)

An RBF subclass for the thin-plate spline

\[\phi(r) = r^2 \log(r).\]

The parameters are as for the base class RBFBase.

static radial(r)

The radial function itself

The RBFWendland subclass

class mvpoly.rbf.RBFWendland(*args, **kwargs)

An RBF subclass for the Wendland function, a compactly supported basis function whose radial is parametersed by the optional non-negative integer keyword argument n. The form of the polynomial depends on n and the dimension of the RBF; the larger the value of n, the smoother the interpolant. As an example, the radial function for n=2 and RBF dimension one is

\[\phi_{1, 2}(r) \propto (8r^2 + 5r + 1)(1 - r)^5 \qquad (0 \leq r \leq 1)\]

The parameters are as for the base class RBFBase, and in addition

Parameters:
ninteger, optional

A parameter controlling the order of the radial function, and the smoothness of the resulting interpolant (to be precise, the latter will be 2n-times continuously differentiable. If not specified a default value of 2 will be used.

radiusfloat, optional

A scaling factor for the basis function, the radius of the support of the function. If not specified then a value will be calculated which is a small factor times the average distance between neigbouring nodes.

Notes

This class requires features of SciPy introduced in version 0.17.0, earlier versions will cause an error to be raised.

See also mvpoly.cube.MVPolyCube.wendland().

radial(r)

The radial function itself