RBF_INTERPOLATOR
This function performs radial basis function (RBF) interpolation for scattered points in N dimensions, with configurable kernel, smoothing, shape parameter, and polynomial degree. It builds a smooth interpolant and evaluates it at new query points.
The interpolant is of the form
f(\mathbf{x}) = \sum_{i=1}^{n} a_i\,\phi\big(\|\mathbf{x}-\mathbf{y}_i\|\big) + p(\mathbf{x}),
where \phi is the selected radial kernel and p(\mathbf{x}) is an optional polynomial term.
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.
Example 1: RBF interpolation on 1D quadratic data
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:
0.391541
Example 2: 1D RBF with smoothing parameter
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:
2.4184
Example 3: 2D RBF with cubic kernel
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:
1
Example 4: RBF with gaussian kernel and custom epsilon
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 |
| 0 |
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.
"""
try:
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"Error: Invalid kernel: '{kernel}'. Must be one of {valid_kernels}."
# Validate smoothing parameter
if not isinstance(smoothing, (int, float)):
return "Error: Invalid smoothing: must be a number."
if smoothing < 0:
return "Error: Invalid smoothing: must be non-negative."
# Validate epsilon parameter
if not isinstance(epsilon, (int, float)):
return "Error: Invalid epsilon: must be a number."
if epsilon <= 0:
return "Error: Invalid epsilon: must be positive."
# Validate degree parameter
if not isinstance(degree, int):
return "Error: Invalid degree: must be an integer."
if degree < 0:
return "Error: 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 "Error: Invalid y: must be a 2D list."
if xi_arr.ndim != 2:
return "Error: Invalid xi: must be a 2D list."
if y_arr.shape[0] != len(d_arr):
return "Error: Invalid d: number of values must match number of points in y."
if y_arr.shape[1] != xi_arr.shape[1]:
return "Error: 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"Error: Invalid input: {str(e)}"
except Exception as e:
return f"Error: {str(e)}"
except Exception as e:
return f"Error: {str(e)}"