packages

interpolate::scatter::rbf

On this page

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 Rbf

A 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]).

nabi
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);
  • pub 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§

    Source

    The interpolant of values[i] at row i of points (n x d). degree defaults to the larger of 1 and kernel.min_degree(); pass -1 for no polynomial. epsilon scales distances (it matters for the multiquadrics and the Gaussian; the others are scale-free up to the polynomial).

    nabi
    use 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);
    
  • pub fn at(self, x: Vector<f64>) -> f64§

    Source

    The value at x (d coordinates); NaN for the wrong length.

    nabi
    use 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);
    
  • pub fn eval(self, xs: Matrix<f64>) throws (InterpError) -> Vector<f64>§

    Source

    The value at every row of xs (m x d); 256 rows and more run across the workers.

    nabi
    use 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 Kernel

The radial function phi(r) of an Rbf, applied to eps * r.

nabi
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.

  • ThinPlate§

    Source

    r^2 ln r, the thin-plate spline: minimal bending energy in 2-d.

  • r^3.

  • Quintic§

    Source

    -r^5.

  • Multiquadric§

    Source

    -sqrt(1 + r^2).

  • InverseMultiquadric§

    Source

    1 / sqrt(1 + r^2).

  • InverseQuadratic§

    Source

    1 / (1 + r^2).

  • Gaussian§

    Source

    exp(-r^2).

  • pub fn phi(self, r: f64) -> f64§

    Source

    phi(r).

    nabi
    use interpolate::scatter::Kernel;
    
    assert(Kernel::Cubic.phi(2.0) == 8.0);
    
  • pub fn min_degree(self) -> i64§

    Source

    The lowest polynomial degree that makes the system uniquely solvable for distinct points (-1: none needed).

    nabi
    use interpolate::scatter::Kernel;
    
    assert(Kernel::Quintic.min_degree() == 2 && Kernel::Gaussian.min_degree() == -1);