Struct GridCubicSmoothingSpline

Source
pub struct GridCubicSmoothingSpline<'a, T, D>
where T: Real, D: Dimension,
{ /* private fields */ }
Expand description

N-dimensional grid cubic smoothing spline calculator/evaluator

The struct represents n-dimensional grid smoothing cubic spline and allows you to make and evaluate the splines for given n-dimensional grid data.

GridCubicSmoothingSpline struct is parametrized by data type (f64 or f32) and data dimension.

The methods API of GridCubicSmoothingSpline is implemented as builder-like pattern or in other words as chained API (also as CubicSmoothingSpline struct).

§Examples

use ndarray::array;
use csaps::GridCubicSmoothingSpline;

let x0 = array![1.0, 2.0, 3.0, 4.0];
let x1 = array![1.0, 2.0, 3.0, 4.0];
let x = vec![x0.view(), x1.view()];

let y = array![
    [0.5, 1.2, 3.4, 2.5],
    [1.5, 2.2, 4.4, 3.5],
    [2.5, 3.2, 5.4, 4.5],
    [3.5, 4.2, 6.4, 5.5],
];

let ys = GridCubicSmoothingSpline::new(&x, &y)
    .make().unwrap()
    .evaluate(&x).unwrap();

Implementations§

Source§

impl<'a, T, D> GridCubicSmoothingSpline<'a, T, D>
where T: Real, D: Dimension,

Source

pub fn new<Y>(x: &[ArrayView1<'a, T>], y: Y) -> Self
where Y: AsArray<'a, T, D>,

Creates NdGridCubicSmoothingSpline struct from the given X data sites and Y data values

§Arguments
  • x – the slice of X-data sites 1-d array view for each dimension. Each data sites must strictly increasing: x1 < x2 < x3 < ... < xN.
  • y – The Y-data n-d grid values array-like. ndim can be from 1 to N.
Source

pub fn with_weights(self, weights: &[Option<ArrayView1<'a, T>>]) -> Self

Sets the weights data vectors for each dimension

§Arguments
  • weights – the slice of optional weights arrays (array-like) for each dimension
§Notes

weights vectors sizes must be equal to x data site sizes for each dimension.

Source

pub fn with_smooth(self, smooth: &[Option<T>]) -> Self

Sets the smoothing parameters for each dimension

§Arguments
  • smooth - the slice of optional smoothing parameters for each dimension
§Notes

The smoothing parameters should be in range [0, 1] or None, where bounds are:

  • 0: The smoothing spline is the least-squares straight line fit to the data
  • 1: The cubic spline interpolant with natural boundary condition

If the smoothing parameter value is None, it will be computed automatically.

Source

pub fn with_smooth_fill(self, smooth: T) -> Self

Sets the smoothing parameter for all dimensions

§Arguments
  • smooth - the smoothing parameter value that the same for all dimensions
§Notes

The smoothing parameter should be in range [0, 1], where bounds are:

  • 0: The smoothing spline is the least-squares straight line fit to the data
  • 1: The cubic spline interpolant with natural boundary condition
Source

pub fn make(self) -> Result<Self>

Makes (computes) the n-dimensional grid spline for given data and parameters

§Errors
  • If the data or parameters are invalid
Source

pub fn evaluate(&self, xi: &[ArrayView1<'a, T>]) -> Result<Array<T, D>>

Evaluates the computed n-dimensional grid spline on the given data sites

§Errors
  • If the xi data is invalid
  • If the spline yet has not been computed
Source

pub fn smooth(&self) -> &Vec<Option<T>>

Returns the ref to smoothing parameters vector or None

Source

pub fn spline(&self) -> Option<&NdGridSpline<'a, T, D>>

Returns ref to NdGridSpline struct with data of computed spline or None

Auto Trait Implementations§

§

impl<'a, T, D> Freeze for GridCubicSmoothingSpline<'a, T, D>
where D: Freeze,

§

impl<'a, T, D> RefUnwindSafe for GridCubicSmoothingSpline<'a, T, D>

§

impl<'a, T, D> Send for GridCubicSmoothingSpline<'a, T, D>

§

impl<'a, T, D> Sync for GridCubicSmoothingSpline<'a, T, D>

§

impl<'a, T, D> Unpin for GridCubicSmoothingSpline<'a, T, D>
where D: Unpin, T: Unpin,

§

impl<'a, T, D> UnwindSafe for GridCubicSmoothingSpline<'a, T, D>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

unsafe fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.