[][src]Struct csaps::CubicSmoothingSpline

pub struct CubicSmoothingSpline<'a, T, D> where
    T: Real,
    D: Dimension
{ /* fields omitted */ }

N-dimensional (univariate/multivariate) smoothing spline calculator/evaluator

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

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

The methods API of CubicSmoothingSpline is implemented as builder-loke pattern or in other words as chained API.

Examples

use csaps::CubicSmoothingSpline;

let x = vec![1.0, 2.0, 3.0, 4.0];
let y = vec![0.5, 1.2, 3.4, 2.5];

let ys = CubicSmoothingSpline::new(&x, &y)
    .make().unwrap()
    .evaluate(&x).unwrap();
use ndarray::array;
use csaps::CubicSmoothingSpline;

let x = array![1.0, 2.0, 3.0, 4.0];
let y = array![0.5, 1.2, 3.4, 2.5];
let w = array![1.0, 0.7, 0.5, 1.0];
let smooth = 0.85;

let s = CubicSmoothingSpline::new(&x, &y)
    .with_weights(&w)
    .with_smooth(smooth)
    .make().unwrap();

let xi = array![1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0];
let yi = s.evaluate(&xi).unwrap();

Methods

impl<'a, T, D> CubicSmoothingSpline<'a, T, D> where
    T: Real,
    D: Dimension
[src]

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

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

Arguments

  • x -- the X-data sites 1-d array-like. Must strictly increasing: x1 < x2 < x3 < ... < xN
  • y -- The Y-data values n-d array-like. ndim can be from 1 to N. The splines will be computed for all data by given axis. By default the axis parameter is equal to the last axis of Y data. For example, for 1-d axis is equal to 0, for 2-d axis is equal to 1, for 3-d axis is equal to 2 and etc.

pub fn with_axis(self, axis: Axis) -> Self[src]

Sets the axis parameter

The Y-data axis. Axis along which Y-data is assumed to be varying. In other words, the axis parameter specifies Y-data axis for computing spline.

y.shape()[axis] must be equal to x.len()

Example

use ndarray::{array, Axis};
use csaps::CubicSmoothingSpline;

let x = array![1., 2., 3., 4.];
let y = array![[1., 5., 9.],
               [2., 6., 10.],
               [3., 7., 11.],
               [4., 8., 12.]];

let ys = CubicSmoothingSpline::new(&x, &y)
    .with_axis(Axis(0))  // y.shape()[0] == x.len()
    .make().unwrap()
    .evaluate(&x).unwrap();

assert_eq!(ys, y);

In the example y data view will be reshaped from shape [4, 3] to shape [3, 4] before computing spline and reshaped back while evaluating the spline for correct shape of ys output.

pub fn with_weights<W>(self, weights: W) -> Self where
    W: AsArray<'a, T>, 
[src]

Sets the weights data vector

weights.len() must be equal to x.len()

pub fn with_optional_weights<W>(self, weights: Option<W>) -> Self where
    W: AsArray<'a, T>, 
[src]

Sets the weights data vector in Option wrap

weights.len() must be equal to x.len()

pub fn with_smooth(self, smooth: T) -> Self[src]

Sets the smoothing parameter

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

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

Sets the smoothing parameter in Option wrap

pub fn make(self) -> Result<Self>[src]

Makes (computes) the spline for given data and parameters

Errors

  • If the data or parameters are invalid
  • If reshaping Y data to 2-d view has failed

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

Evaluates the computed spline on the given data sites

Errors

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

pub fn smooth(&self) -> Option<T>[src]

Returns the smoothing parameter or None

pub fn spline(&self) -> Option<&NdSpline<'a, T>>[src]

Returns the ref to NdSpline struct with data of computed spline or None

Auto Trait Implementations

impl<'a, T, D> RefUnwindSafe for CubicSmoothingSpline<'a, T, D> where
    D: RefUnwindSafe,
    T: RefUnwindSafe

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

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

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

impl<'a, T, D> UnwindSafe for CubicSmoothingSpline<'a, T, D> where
    D: UnwindSafe,
    T: RefUnwindSafe + UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.