pub struct PolyharmonicSpline { /* private fields */ }Expand description
A polyharmonic spline interpolator for arbitrary-dimension data.
Given n data points in d dimensions with scalar values, the
polyharmonic spline builds an interpolant (or smoothing approximation)
using radial basis functions augmented with a polynomial of degree <= order - 1.
§Examples
use scirs2_interpolate::polyharmonic::PolyharmonicSpline;
// 2D scattered data
let points = vec![
vec![0.0, 0.0],
vec![1.0, 0.0],
vec![0.0, 1.0],
vec![1.0, 1.0],
];
let values = vec![0.0, 1.0, 1.0, 2.0];
let spline = PolyharmonicSpline::fit(&points, &values, 2, 0.0)
.expect("should fit successfully");
// Evaluate at a query point
let result = spline.evaluate(&[0.5, 0.5]).expect("should evaluate");
assert!((result - 1.0).abs() < 1e-8);Implementations§
Source§impl PolyharmonicSpline
impl PolyharmonicSpline
Sourcepub fn fit(
points: &[Vec<f64>],
values: &[f64],
order: usize,
smoothing: f64,
) -> InterpolateResult<Self>
pub fn fit( points: &[Vec<f64>], values: &[f64], order: usize, smoothing: f64, ) -> InterpolateResult<Self>
Fit a polyharmonic spline to scattered data.
§Arguments
points- Data point coordinates,npoints each of dimensiond.values- Function values at the data points (lengthn).order- Order of the polyharmonic kernel (>= 1).order = 1:phi(r) = rorder = 2:phi(r) = r^2 log(r)(thin-plate spline)order = 3:phi(r) = r^3
smoothing- Regularization parameter (>= 0). When0, exact interpolation is performed. Larger values produce smoother results.
§Errors
Returns an error if:
pointsis emptypointsandvalueshave different lengths- The linear system is singular
Sourcepub fn thin_plate_spline(
points: &[Vec<f64>],
values: &[f64],
smoothing: f64,
) -> InterpolateResult<Self>
pub fn thin_plate_spline( points: &[Vec<f64>], values: &[f64], smoothing: f64, ) -> InterpolateResult<Self>
Create a thin-plate spline interpolator (order = 2).
This is a convenience method equivalent to fit(points, values, 2, smoothing).
Sourcepub fn evaluate(&self, query: &[f64]) -> InterpolateResult<f64>
pub fn evaluate(&self, query: &[f64]) -> InterpolateResult<f64>
Evaluate the polyharmonic spline at a single query point.
§Errors
Returns an error if the query point dimension does not match the data point dimension.
Sourcepub fn evaluate_batch(
&self,
queries: &[Vec<f64>],
) -> InterpolateResult<Vec<f64>>
pub fn evaluate_batch( &self, queries: &[Vec<f64>], ) -> InterpolateResult<Vec<f64>>
Evaluate the polyharmonic spline at multiple query points.
Returns a vector of interpolated values, one per query point.
Sourcepub fn num_points(&self) -> usize
pub fn num_points(&self) -> usize
Return the number of data points.
Sourcepub fn poly_coefficients(&self) -> &[f64]
pub fn poly_coefficients(&self) -> &[f64]
Return the polynomial coefficients.
Auto Trait Implementations§
impl Freeze for PolyharmonicSpline
impl RefUnwindSafe for PolyharmonicSpline
impl Send for PolyharmonicSpline
impl Sync for PolyharmonicSpline
impl Unpin for PolyharmonicSpline
impl UnsafeUnpin for PolyharmonicSpline
impl UnwindSafe for PolyharmonicSpline
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.