RBFBlock#
- class RBFBlock(neighbors=None, smoothing=0.0, kernel='thin_plate_spline', epsilon=None, degree=None)[source]#
Bases:
Module
Radial Basis Function (RBF) interpolation layer. It need to be fitted with the data with the method
fit()
, before it can be used 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.- Parameters:
neighbors (int) – Number of neighbors to use for the interpolation. If
None
, use all data points.smoothing (float) – Smoothing parameter for the interpolation. if 0.0, the interpolation is exact and no smoothing is applied.
kernel (str) – Radial basis function to use. Must be one of
linear
,thin_plate_spline
,cubic
,quintic
,multiquadric
,inverse_multiquadric
,inverse_quadratic
, orgaussian
.epsilon (float) – Shape parameter that scaled the input to the RBF. This defaults to 1 for kernels in
scale_invariant
dictionary, and must be specified for other kernels.degree (int) – Degree of the added polynomial. For some kernels, there exists a minimum degree of the polynomial such that the RBF is well-posed. Those minimum degrees are specified in the min_degree_funcs dictionary above. If degree is less than the minimum degree, a warning is raised and the degree is set to the minimum value.
- fit(y, d)[source]#
Fit the RBF interpolator to the data.
- Parameters:
y (torch.Tensor) – (n, d) tensor of data points.
d (torch.Tensor) – (n, m) tensor of data values.
- forward(x)[source]#
Returns the interpolated data at the given points x.
- Parameters:
x (torch.Tensor) – (n, d) tensor of points at which to query the interpolator
- Return type:
(n, m) torch.Tensor of interpolated data.
- static kernel_vector(x, y, kernel_func)[source]#
Evaluate radial functions with centers y for all points in x.
- Parameters:
x (torch.Tensor) – (n, d) tensor of points.
y (torch.Tensor) – (m, d) tensor of centers.
kernel_func (str) – Radial basis function to use.
- Return type:
(n, m) torch.Tensor of radial function values.
- static polynomial_matrix(x, powers)[source]#
Evaluate monomials at x with given powers.
- Parameters:
x (torch.Tensor) – (n, d) tensor of points.
powers (torch.Tensor) – (r, d) tensor of powers for each monomial.
- Return type:
(n, r) torch.Tensor of monomial values.
- static kernel_matrix(x, kernel_func)[source]#
Returns radial function values for all pairs of points in x.
- Parameters:
x (torch.Tensor) – (n, d) tensor of points.
kernel_func (str) – Radial basis function to use.
- Return type:
(n, n) torch.Tensor of radial function values.
- static build(y, d, smoothing, kernel, epsilon, powers)[source]#
Build the RBF linear system.
- Parameters:
y (torch.Tensor) – (n, d) tensor of data points.
d (torch.Tensor) – (n, m) tensor of data values.
smoothing (torch.Tensor) – (n,) tensor of smoothing parameters.
kernel (str) – Radial basis function to use.
epsilon (float) – Shape parameter that scaled the input to the RBF.
powers (torch.Tensor) – (r, d) tensor of powers for each monomial.
- Return type:
(lhs, rhs, shift, scale) where lhs and rhs are the left-hand side and right-hand side of the linear system, and shift and scale are the shift and scale parameters.
- static solve(y, d, smoothing, kernel, epsilon, powers)[source]#
Build then solve the RBF linear system.
- Parameters:
y (torch.Tensor) – (n, d) tensor of data points.
d (torch.Tensor) – (n, m) tensor of data values.
smoothing (torch.Tensor) – (n,) tensor of smoothing parameters.
kernel (str) – Radial basis function to use.
epsilon (float) – Shape parameter that scaled the input to the RBF.
powers (torch.Tensor) – (r, d) tensor of powers for each monomial.
- Raises:
ValueError – If the linear system is singular.
- Return type:
(shift, scale, coeffs) where shift and scale are the shift and scale parameters, and coeffs are the coefficients of the interpolator