pub struct LocalPolynomialRegression<F>{ /* private fields */ }Expand description
Local Polynomial Regression model
This model fits a polynomial of specified degree locally around each prediction point using weighted least squares. The weights depend on the distance between the prediction point and the data points.
The implementation includes:
- Multiple weight function options
- Polynomial basis options (constant, linear, quadratic)
- Standard error estimates
- Optional confidence intervals
- Local R² and effective degrees of freedom
- Support for robust standard errors
§Examples
use scirs2_core::ndarray::{Array1, Array2, Axis};
use scirs2_interpolate::local::polynomial::{
LocalPolynomialRegression, LocalPolynomialConfig
};
use scirs2_interpolate::local::mls::{WeightFunction, PolynomialBasis};
// Create some 1D data with noise
let x = Array1::<f64>::linspace(0.0, 10.0, 50);
let mut y = Array1::<f64>::zeros(50);
for (i, x_val) in x.iter().enumerate() {
// y = sin(x) + some noise
y[i] = x_val.sin() + 0.1 * 0.3;
}
// Create a 2D array of points
let points = x.clone().insert_axis(Axis(1));
// Configure and create the local polynomial regression model
let config = LocalPolynomialConfig::<f64> {
bandwidth: 1.0,
weight_fn: WeightFunction::Gaussian,
basis: PolynomialBasis::Quadratic,
confidence_level: Some(0.95),
..LocalPolynomialConfig::default()
};
let loess = LocalPolynomialRegression::with_config(
points,
y,
config
).unwrap();
// Predict at a new point
let query = Array1::from_vec(vec![5.0]);
let result = loess.fit_at_point(&query.view()).unwrap();
// Access the fitted value
println!("Fitted value: {}", result.value);
// Access confidence interval
if let Some((lower, upper)) = result.confidence_interval {
println!("95% CI: ({}, {})", lower, upper);
}Implementations§
Source§impl<F> LocalPolynomialRegression<F>
impl<F> LocalPolynomialRegression<F>
Sourcepub fn response_sd(&self) -> F
pub fn response_sd(&self) -> F
Get the precomputed standard deviation of the response
Source§impl<F> LocalPolynomialRegression<F>
impl<F> LocalPolynomialRegression<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>
Create a new LocalPolynomialRegression with default configuration
§Arguments
points- Point coordinates with shape (n_points, n_dims)values- Values at each point with shape (n_points,)bandwidth- Bandwidth parameter controlling locality (larger = smoother)
§Returns
A new LocalPolynomialRegression model
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(
&self,
points: &ArrayView2<'_, F>,
) -> InterpolateResult<Array1<F>>
pub fn fit_multiple( &self, points: &ArrayView2<'_, F>, ) -> InterpolateResult<Array1<F>>
Sourcepub fn config(&self) -> &LocalPolynomialConfig<F>
pub fn config(&self) -> &LocalPolynomialConfig<F>
Get the configuration used by this local polynomial regression
Sourcepub fn select_bandwidth(&self, bandwidths: &[F]) -> InterpolateResult<F>
pub fn select_bandwidth(&self, bandwidths: &[F]) -> InterpolateResult<F>
Trait Implementations§
Source§impl<F> Clone for LocalPolynomialRegression<F>
impl<F> Clone for LocalPolynomialRegression<F>
Source§fn clone(&self) -> LocalPolynomialRegression<F>
fn clone(&self) -> LocalPolynomialRegression<F>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<F> Freeze for LocalPolynomialRegression<F>where
F: Freeze,
impl<F> RefUnwindSafe for LocalPolynomialRegression<F>where
F: RefUnwindSafe,
impl<F> Send for LocalPolynomialRegression<F>where
F: Send,
impl<F> Sync for LocalPolynomialRegression<F>where
F: Sync,
impl<F> Unpin for LocalPolynomialRegression<F>where
F: Unpin,
impl<F> UnwindSafe for LocalPolynomialRegression<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
Mutably borrows from an owned value. Read more
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>
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 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>
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 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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.