pub struct ParallelLocalPolynomialRegression<F>{ /* 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(),
¶llel_config
).unwrap();
Implementations§
Source§impl<F> ParallelLocalPolynomialRegression<F>
impl<F> ParallelLocalPolynomialRegression<F>
Sourcepub fn new(
points: Array2<F>,
values: Array1<F>,
bandwidth: F,
) -> InterpolateResult<Self>
pub fn new( points: Array2<F>, values: Array1<F>, bandwidth: F, ) -> InterpolateResult<Self>
Sourcepub fn with_config(
points: Array2<F>,
values: Array1<F>,
config: LocalPolynomialConfig<F>,
) -> InterpolateResult<Self>
pub fn with_config( points: Array2<F>, values: Array1<F>, config: LocalPolynomialConfig<F>, ) -> InterpolateResult<Self>
Sourcepub fn fit_at_point(
&self,
x: &ArrayView1<'_, F>,
) -> InterpolateResult<RegressionResult<F>>
pub fn fit_at_point( &self, x: &ArrayView1<'_, F>, ) -> InterpolateResult<RegressionResult<F>>
Sourcepub fn fit_multiple_parallel(
&self,
points: &ArrayView2<'_, F>,
config: &ParallelConfig,
) -> InterpolateResult<Array1<F>>
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
Sourcepub fn fit_with_kdtree(
&self,
points: &ArrayView2<'_, F>,
config: &ParallelConfig,
) -> InterpolateResult<Array1<F>>
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>
impl<F> Clone for ParallelLocalPolynomialRegression<F>
Source§fn clone(&self) -> ParallelLocalPolynomialRegression<F>
fn clone(&self) -> ParallelLocalPolynomialRegression<F>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<F> Debug for ParallelLocalPolynomialRegression<F>
impl<F> Debug for ParallelLocalPolynomialRegression<F>
Source§impl<F> ParallelEvaluate<F, ArrayBase<OwnedRepr<F>, Dim<[usize; 1]>>> for ParallelLocalPolynomialRegression<F>
impl<F> ParallelEvaluate<F, ArrayBase<OwnedRepr<F>, Dim<[usize; 1]>>> for ParallelLocalPolynomialRegression<F>
Source§fn evaluate_parallel(
&self,
points: &ArrayView2<'_, F>,
config: &ParallelConfig,
) -> InterpolateResult<Array1<F>>
fn evaluate_parallel( &self, points: &ArrayView2<'_, F>, config: &ParallelConfig, ) -> InterpolateResult<Array1<F>>
Auto Trait Implementations§
impl<F> Freeze for ParallelLocalPolynomialRegression<F>where
F: Freeze,
impl<F> RefUnwindSafe for ParallelLocalPolynomialRegression<F>where
F: RefUnwindSafe,
impl<F> Send for ParallelLocalPolynomialRegression<F>
impl<F> Sync for ParallelLocalPolynomialRegression<F>
impl<F> Unpin for ParallelLocalPolynomialRegression<F>where
F: Unpin,
impl<F> UnwindSafe for ParallelLocalPolynomialRegression<F>where
F: UnwindSafe + RefUnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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
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.