RBF_INTERPOLATOR
Overview
The RBF_INTERPOLATOR function performs Radial Basis Function (RBF) interpolation in N-dimensional space, enabling smooth approximation of scattered, multivariate data points. RBF interpolation is a meshfree method commonly used in surface reconstruction, geostatistics, computer graphics, and machine learning when data points are irregularly distributed across multiple dimensions.
A Radial Basis Function is a scalar-valued function whose value at any point x depends only on the Euclidean distance r = \|x - c\| from a center point c. The RBF interpolant constructs a smooth function that passes through (or approximates) all data points by combining RBFs centered at each data location with a polynomial term. The interpolant takes the form:
f(x) = K(x, y) \cdot a + P(x) \cdot b
where K(x, y) is a matrix of RBF evaluations, P(x) is a polynomial basis matrix, and a and b are coefficients determined by solving a linear system that enforces interpolation conditions.
This implementation uses SciPy’s RBFInterpolator from the scipy.interpolate module. The function supports eight different kernel types:
| Kernel | Formula |
|---|---|
| Linear | -r |
| Thin Plate Spline | r^2 \log(r) |
| Cubic | r^3 |
| Quintic | -r^5 |
| Multiquadric | -\sqrt{1 + r^2} |
| Inverse Multiquadric | 1 / \sqrt{1 + r^2} |
| Inverse Quadratic | 1 / (1 + r^2) |
| Gaussian | \exp(-r^2) |
The thin plate spline kernel (default) is particularly popular for smooth interpolation as it minimizes a bending energy functional, producing surfaces analogous to a thin elastic plate deformed to pass through the data points.
The smoothing parameter controls the trade-off between exact interpolation and regularization. When set to 0, the interpolant passes exactly through all data points. Larger values produce smoother approximations, approaching a least-squares polynomial fit. The epsilon parameter acts as a shape parameter that scales the input to the RBF—smaller values produce wider, smoother basis functions, while larger values create narrower, more localized functions. The degree parameter specifies the degree of the polynomial term added to improve interpolation stability.
For theoretical background on RBF methods, see Fasshauer’s Meshfree Approximation Methods with Matlab and the SciPy source code on GitHub.
This example function is provided as-is without any representation of accuracy.
Excel Usage
=RBF_INTERPOLATOR(y, d, xi, smoothing, kernel, epsilon, degree)
y(list[list], required): Coordinates of the data points (n_points, n_dims)d(list[list], required): Values of the data points (n_points, 1)xi(list[list], required): Points at which to interpolate (n_new_points, n_dims)smoothing(float, optional, default: 0): Smoothing parameter (non-negative)kernel(str, optional, default: “thin_plate_spline”): Radial basis function kernelepsilon(float, optional, default: 1): Shape parameter for some kernels (positive)degree(int, optional, default: 1): Degree of polynomial term (non-negative)
Returns (list[list]): A 2D list of interpolated values (n_new_points, 1), or str error message if invalid.
Examples
Example 1: Demo case 1
Inputs:
| y | d | xi |
|---|---|---|
| 0 | 0 | 0.5 |
| 1 | 1 | |
| 2 | 4 |
Excel formula:
=RBF_INTERPOLATOR({0;1;2}, {0;1;4}, {0.5})
Expected output:
| Result |
|---|
| 0.3915 |
Example 2: Demo case 2
Inputs:
| y | d | xi | smoothing |
|---|---|---|---|
| 0 | 0 | 1.5 | 0.1 |
| 1 | 1 | ||
| 2 | 4 |
Excel formula:
=RBF_INTERPOLATOR({0;1;2}, {0;1;4}, {1.5}, 0.1)
Expected output:
| Result |
|---|
| 2.418 |
Example 3: Demo case 3
Inputs:
| y | d | xi | kernel | ||
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0.5 | 0.5 | cubic |
| 1 | 0 | 1 | |||
| 0 | 1 | 1 | |||
| 1 | 1 | 2 |
Excel formula:
=RBF_INTERPOLATOR({0,0;1,0;0,1;1,1}, {0;1;1;2}, {0.5,0.5}, "cubic")
Expected output:
| Result |
|---|
| 1 |
Example 4: Demo case 4
Inputs:
| y | d | xi | smoothing | kernel | epsilon | degree |
|---|---|---|---|---|---|---|
| 0 | 0 | 1 | 0 | gaussian | 2 | 0 |
| 1 | 1 | 2 | ||||
| 2 | 0 | |||||
| 3 | 1 |
Excel formula:
=RBF_INTERPOLATOR({0;1;2;3}, {0;1;0;1}, {1;2}, 0, "gaussian", 2, 0)
Expected output:
| Result |
|---|
| 1 |
| 5.551e-17 |
Python Code
import numpy as np
from scipy.interpolate import RBFInterpolator as scipy_RBFInterpolator
def rbf_interpolator(y, d, xi, smoothing=0, kernel='thin_plate_spline', epsilon=1, degree=1):
"""
Radial basis function interpolation in N dimensions.
See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.RBFInterpolator.html
This example function is provided as-is without any representation of accuracy.
Args:
y (list[list]): Coordinates of the data points (n_points, n_dims)
d (list[list]): Values of the data points (n_points, 1)
xi (list[list]): Points at which to interpolate (n_new_points, n_dims)
smoothing (float, optional): Smoothing parameter (non-negative) Default is 0.
kernel (str, optional): Radial basis function kernel Valid options: Linear, Thin Plate Spline, Cubic, Quintic, Multiquadric, Inverse Multiquadric, Inverse Quadratic, Gaussian. Default is 'thin_plate_spline'.
epsilon (float, optional): Shape parameter for some kernels (positive) Default is 1.
degree (int, optional): Degree of polynomial term (non-negative) Default is 1.
Returns:
list[list]: A 2D list of interpolated values (n_new_points, 1), or str error message if invalid.
"""
def to2d(x):
return [[x]] if not isinstance(x, list) else x
# Normalize inputs to 2D lists
y = to2d(y)
d = to2d(d)
xi = to2d(xi)
# Validate kernel parameter
valid_kernels = [
'linear', 'thin_plate_spline', 'cubic', 'quintic',
'multiquadric', 'inverse_multiquadric', 'inverse_quadratic', 'gaussian'
]
if kernel not in valid_kernels:
return f"Invalid kernel: '{kernel}'. Must be one of {valid_kernels}."
# Validate smoothing parameter
if not isinstance(smoothing, (int, float)):
return "Invalid smoothing: must be a number."
if smoothing < 0:
return "Invalid smoothing: must be non-negative."
# Validate epsilon parameter
if not isinstance(epsilon, (int, float)):
return "Invalid epsilon: must be a number."
if epsilon <= 0:
return "Invalid epsilon: must be positive."
# Validate degree parameter
if not isinstance(degree, int):
return "Invalid degree: must be an integer."
if degree < 0:
return "Invalid degree: must be non-negative."
try:
# Convert to numpy arrays
y_arr = np.array(y, dtype=float)
d_arr = np.array(d, dtype=float).flatten()
xi_arr = np.array(xi, dtype=float)
# Validate shapes
if y_arr.ndim != 2:
return "Invalid y: must be a 2D list."
if xi_arr.ndim != 2:
return "Invalid xi: must be a 2D list."
if y_arr.shape[0] != len(d_arr):
return "Invalid d: number of values must match number of points in y."
if y_arr.shape[1] != xi_arr.shape[1]:
return "Invalid xi: dimensions must match y."
# Create interpolator
interp = scipy_RBFInterpolator(
y_arr, d_arr,
smoothing=smoothing,
kernel=kernel,
epsilon=epsilon,
degree=degree
)
# Perform interpolation
result = interp(xi_arr)
# Return as 2D list (column vector)
return [[float(val)] for val in result]
except ValueError as e:
return f"Invalid input: {str(e)}"
except Exception as e:
return f"Error: {str(e)}"