interpolate::scatter::rbf
Radial basis function interpolation (Fasshauer, "Meshfree Approximation Methods with MATLAB", 2007): s(x) = sum_i c_i phi(eps |x - x_i|) + p(x) with p a polynomial of low degree, the coefficients from the saddle-point system [K + lambda I, P; P^T, 0] [c; d] = [y; 0] solved by LU with partial pivoting. The polynomial is built on coordinates shifted and scaled to [-1, 1] per axis. Fit O(n^3), evaluation O(n) per point.
Structs
RbfSource
pub struct RbfA radial basis function interpolant of scattered data in any
dimension. smoothing > 0 trades exactness for a smoother fit
(ridge on the kernel part); with a polynomial of degree >= 1,
linear data comes back exactly whatever the kernel. Call it at a
point, f([x, y]).
use interpolate::scatter::{Kernel, Rbf};
use core::array::Matrix;
let p: Matrix<f64> = [[0, 0], [1, 0], [0, 1], [1, 1], [0.5, 0.5]];
let f = try Rbf::new(p, [0, 1, 1, 2, 1.5]); // thin plate, degree 1
assert((f([0.5, 0.5]) - 1.5).abs() < 1e-12);
let g = try Rbf::new(p, [0, 1, 1, 2, 1.5], kernel: Kernel::Gaussian, epsilon: 2.0);
assert((g([1.0, 0.0]) - 1.0).abs() < 1e-12);
Sourcepub fn new(§points: Matrix<f64>, values: Vector<f64>, kernel: Kernel = Kernel::ThinPlate, epsilon: f64 = 1.0, smoothing: f64 = 0.0, degree: i64? = none) throws (InterpError) -> Rbf The interpolant of
values[i]at rowiofpoints(n x d).degreedefaults to the larger of 1 andkernel.min_degree(); pass -1 for no polynomial.epsilonscales distances (it matters for the multiquadrics and the Gaussian; the others are scale-free up to the polynomial).nabiuse interpolate::scatter::{Kernel, Rbf}; use core::array::Matrix; let p: Matrix<f64> = [[0], [1], [2], [3]]; let f = try Rbf::new(p, [0, 1, 4, 9], kernel: Kernel::Cubic, smoothing: 0.0); assert((f.at([2.0]) - 4.0).abs() < 1e-12);The value at
x(d coordinates); NaN for the wrong length.nabiuse interpolate::scatter::Rbf; use core::array::Matrix; let p: Matrix<f64> = [[0, 0], [1, 0], [0, 1]]; let f = try Rbf::new(p, [1, 2, 3]); // the plane 1 + x + 2y assert((f.at([0.5, 0.5]) - 2.5).abs() < 1e-12);
Sourcepub fn eval(§self, xs: Matrix<f64>) throws (InterpError) -> Vector<f64> The value at every row of
xs(m x d); 256 rows and more run across the workers.nabiuse interpolate::scatter::Rbf; use core::array::Matrix; let p: Matrix<f64> = [[0], [1], [2]]; let f = try Rbf::new(p, [0, 1, 0]); let v = try f.eval(p); assert((v[1] - 1.0).abs() < 1e-12);
Trait implementations 1
impl ops::Call<Vector<f64>> for Rbf
Enums
KernelSource
pub enum KernelThe radial function phi(r) of an Rbf, applied to eps * r.
use interpolate::scatter::Kernel;
assert(Kernel::ThinPlate.phi(1.0) == 0.0);
assert(Kernel::Gaussian.phi(0.0) == 1.0);
assert(Kernel::ThinPlate.min_degree() == 1);
-r, conditionally positive definite of order 1.r^2 ln r, the thin-plate spline: minimal bending energy in 2-d.r^3.-r^5.-sqrt(1 + r^2).1 / sqrt(1 + r^2).1 / (1 + r^2).exp(-r^2).phi(r).nabiuse interpolate::scatter::Kernel; assert(Kernel::Cubic.phi(2.0) == 8.0);The lowest polynomial degree that makes the system uniquely solvable for distinct points (-1: none needed).
nabiuse interpolate::scatter::Kernel; assert(Kernel::Quintic.min_degree() == 2 && Kernel::Gaussian.min_degree() == -1);