ParallelLocalPolynomialRegression

Struct ParallelLocalPolynomialRegression 

Source
pub struct ParallelLocalPolynomialRegression<F>
where F: Float + FromPrimitive + Debug + Send + Sync + 'static + PartialOrd + FloatCore,
{ /* private fields */ }
Expand description

Parallel Local Polynomial Regression model

This struct extends the standard LocalPolynomialRegression with parallel computation capabilities. It uses a spatial index (KD-tree) for efficient neighbor searching and distributes work across multiple CPU cores.

§Examples

use scirs2_core::ndarray::{Array1, Array2};
use scirs2_interpolate::parallel::{ParallelLocalPolynomialRegression, ParallelConfig};
use scirs2_interpolate::local::polynomial::LocalPolynomialConfig;
use scirs2_interpolate::local::mls::{WeightFunction, PolynomialBasis};

// Create sample 1D data
let x = Array1::<f64>::linspace(0.0, 10.0, 100);
let mut y = Array1::<f64>::zeros(100);
for (i, x_val) in x.iter().enumerate() {
    // y = sin(x) + noise
    y[i] = x_val.sin() + 0.1 * 0.3;
}

// Create 2D points array from 1D data
let points = x.clone().insert_axis(scirs2_core::ndarray::Axis(1));

// Configure LOESS model
let config = LocalPolynomialConfig {
    bandwidth: 0.3,
    weight_fn: WeightFunction::Gaussian,
    basis: PolynomialBasis::Quadratic,
    ..LocalPolynomialConfig::default()
};

// Create parallel LOESS model
let parallel_loess = ParallelLocalPolynomialRegression::with_config(
    points.clone(),
    y.clone(),
    config,
).unwrap();

// Create test points
let test_x = Array1::<f64>::linspace(0.0, 10.0, 50);
let testpoints = test_x.clone().insert_axis(scirs2_core::ndarray::Axis(1));

// Parallel evaluation
let parallel_config = ParallelConfig::new();
let results = parallel_loess.fit_multiple_parallel(
    &testpoints.view(),
    &parallel_config
).unwrap();

Implementations§

Source§

impl<F> ParallelLocalPolynomialRegression<F>
where F: Float + FromPrimitive + Debug + Send + Sync + 'static + PartialOrd + FloatCore,

Source

pub fn new( points: Array2<F>, values: Array1<F>, bandwidth: F, ) -> InterpolateResult<Self>

Create a new parallel local polynomial regression model

§Arguments
  • points - Point coordinates with shape (npoints, n_dims)
  • values - Values at each point with shape (npoints,)
  • bandwidth - Bandwidth parameter controlling locality
§Returns

A new ParallelLocalPolynomialRegression model

Source

pub fn with_config( points: Array2<F>, values: Array1<F>, config: LocalPolynomialConfig<F>, ) -> InterpolateResult<Self>

Create a new parallel local polynomial regression with custom configuration

§Arguments
  • points - Point coordinates with shape (npoints, n_dims)
  • values - Values at each point with shape (npoints,)
  • config - Configuration for the regression
§Returns

A new ParallelLocalPolynomialRegression model

Source

pub fn fit_at_point( &self, x: &ArrayView1<'_, F>, ) -> InterpolateResult<RegressionResult<F>>

Fit the model at a single point

§Arguments
  • x - Query point coordinates
§Returns

Regression result at the query point

Source

pub fn fit_multiple_parallel( &self, points: &ArrayView2<'_, F>, config: &ParallelConfig, ) -> InterpolateResult<Array1<F>>

Fit the model at multiple points in parallel

This method distributes the fitting of multiple points across available CPU cores, potentially providing significant speedup for large datasets or many query points.

§Arguments
  • points - Query points with shape (npoints, n_dims)
  • config - Parallel execution configuration
§Returns

Array of fitted values at the query points

Source

pub fn fit_with_kdtree( &self, points: &ArrayView2<'_, F>, config: &ParallelConfig, ) -> InterpolateResult<Array1<F>>

Fit the model at multiple points using KD-tree for neighbor search

This method uses the KD-tree to efficiently find nearest neighbors for each query point, which significantly accelerates the fitting process, especially for large datasets.

§Arguments
  • points - Query points with shape (npoints, n_dims)
  • config - Parallel execution configuration
§Returns

Array of fitted values at the query points

Trait Implementations§

Source§

impl<F> Clone for ParallelLocalPolynomialRegression<F>
where F: Float + FromPrimitive + Debug + Send + Sync + 'static + PartialOrd + FloatCore + Clone,

Source§

fn clone(&self) -> ParallelLocalPolynomialRegression<F>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F> Debug for ParallelLocalPolynomialRegression<F>
where F: Float + FromPrimitive + Debug + Send + Sync + 'static + PartialOrd + FloatCore + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F> ParallelEvaluate<F, ArrayBase<OwnedRepr<F>, Dim<[usize; 1]>>> for ParallelLocalPolynomialRegression<F>
where F: Float + FromPrimitive + Debug + Send + Sync + 'static + PartialOrd + FloatCore,

Source§

fn evaluate_parallel( &self, points: &ArrayView2<'_, F>, config: &ParallelConfig, ) -> InterpolateResult<Array1<F>>

Evaluate at multiple points in parallel

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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§

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V