Radias Basis Function Block#

class RBFBlock(neighbors=None, smoothing=0.0, kernel='thin_plate_spline', epsilon=None, degree=None)[source]#

Bases: Module

Radial Basis Function (RBF) interpolation layer.

The user needs to fit the model with the data, before using it to interpolate new points. The layer is not trainable.

Note

It reproduces the implementation of scipy.interpolate.RBFBlock and it is inspired from the implementation in torchrbf.

Initialization of the RBFBlock class.

Parameters:
  • neighbors (int) – The number of neighbors used for interpolation. If None, all data are used.

  • smoothing (float) – The moothing parameter for the interpolation. If 0.0, the interpolation is exact and no smoothing is applied.

  • kernel (str) – The radial basis function to use. The available kernels are: linear, thin_plate_spline, cubic, quintic, multiquadric, inverse_multiquadric, inverse_quadratic, or gaussian.

  • epsilon (float) – The shape parameter that scales the input to the RBF. Default is 1 for kernels in the scale_invariant dictionary, while it must be specified for other kernels.

  • degree (int) – The degree of the polynomial. Some kernels require a minimum degree of the polynomial to ensure that the RBF is well defined. These minimum degrees are specified in the min_degree_funcs dictionary. If degree is less than the minimum degree required, a warning is raised and the degree is set to the minimum value.

property smoothing#

The smoothing parameter for the interpolation.

Returns:

The smoothing parameter.

Return type:

float

property kernel#

The Radial basis function.

Returns:

The radial basis function.

Return type:

str

property epsilon#

The shape parameter that scales the input to the RBF.

Returns:

The shape parameter.

Return type:

float

property degree#

The degree of the polynomial.

Returns:

The degree of the polynomial.

Return type:

int

fit(y, d)[source]#

Fit the RBF interpolator to the data.

Parameters:
Raises:
forward(x)[source]#

Forward pass.

Parameters:

x (torch.Tensor) – The tensor of points to interpolate.

Raises:
  • ValueError – If the input is not a 2-dimensional tensor.

  • ValueError – If the second dimension of the input is not the same as the second dimension of the data.

Returns:

The interpolated data.

Return type:

torch.Tensor

static kernel_vector(x, y, kernel_func)[source]#

Evaluate for all points x the radial functions with center y.

Parameters:
  • x (torch.Tensor) – The tensor of points.

  • y (torch.Tensor) – The tensor of centers.

  • kernel_func (str) – Radial basis function to use.

Returns:

The radial function values.

Return type:

torch.Tensor

static polynomial_matrix(x, powers)[source]#

Evaluate monomials of power powers at points x.

Parameters:
Returns:

The monomial values.

Return type:

torch.Tensor

static kernel_matrix(x, kernel_func)[source]#

Return the radial function values for all pairs of points in x.

Parameters:
  • x (torch.Tensor) – The tensor of points.

  • kernel_func (str) – The radial basis function to use.

Returns:

The radial function values.

Return type:

torch.Tensor

static monomial_powers(ndim, degree)[source]#

Return the powers for each monomial in a polynomial.

Parameters:
  • ndim (int) – The number of variables in the polynomial.

  • degree (int) – The degree of the polynomial.

Returns:

The powers for each monomial.

Return type:

torch.Tensor

static build(y, d, smoothing, kernel, epsilon, powers)[source]#

Build the RBF linear system.

Parameters:
  • y (torch.Tensor) – The tensor of data points.

  • d (torch.Tensor) – The tensor of data values.

  • smoothing (torch.Tensor) – The tensor of smoothing parameters.

  • kernel (str) – The radial basis function to use.

  • epsilon (float) – The shape parameter that scales the input to the RBF.

  • powers (torch.Tensor) – The tensor of powers for each monomial.

Returns:

The left-hand side and right-hand side of the linear system, and the shift and scale parameters.

Return type:

tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]

static solve(y, d, smoothing, kernel, epsilon, powers)[source]#

Build and solve the RBF linear system.

Parameters:
  • y (torch.Tensor) – The tensor of data points.

  • d (torch.Tensor) – The tensor of data values.

  • smoothing (torch.Tensor) – The tensor of smoothing parameters.

  • kernel (str) – The radial basis function to use.

  • epsilon (float) – The shape parameter that scaled the input to the RBF.

  • powers (torch.Tensor) – The tensor of powers for each monomial.

Raises:

ValueError – If the linear system is singular.

Returns:

The shift and scale parameters, and the coefficients of the interpolator.

Return type:

tuple[torch.Tensor, torch.Tensor, torch.Tensor]