Skip to content

Conversation

@thisisamirv
Copy link

@thisisamirv thisisamirv commented Oct 28, 2025

Summary

This PR adds a new module kernel_weights providing common statistical kernel functions used in local regression and kernel density estimation.

Details

  • Implements five kernels:
    • tricube
    • epanechnikov
    • gaussian
    • triangular
    • quartic (biweight)
  • Adds corresponding types (Tricube, Gaussian, Epanechnikov, Triangular, Quartic) implementing a new KernelFn trait.
  • Allows fn(f64) -> f64 to be used directly as KernelFn.
  • Includes integration and behavioral tests ensuring normalization and symmetry.
  • Fully documented with Rustdoc examples and #[must_use] attributes.

Motivation

Kernel weighting functions are widely used in nonparametric statistics (LOESS, KDE, SVMs).
Adding them directly to ndarray-stats provides a reusable foundation for local regression and density estimation tools without external dependencies.

Checklist

  • Tests added and passing (cargo test --test kernel_weights)
  • cargo fmt and cargo clippy --all-targets -- -D warnings clean

tricube(u)
}
}
pub const TRICUBE: Tricube = Tricube;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you creating a constant version of those functions? Why can't the user use Tricube instead of TRICUBE?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback!
My goal with the constants was mainly to provide a small ergonomic convenience, letting users treat kernels as predeclared value singletons (e.g., smooth(TRICUBE, data)) instead of having to instantiate the unit structs directly. Although, I’m totally fine with removing them if the preference is to keep the API minimal and rely on the unit structs directly. I’ll update the PR accordingly if that’s the desired direction.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a maintainer here, I was just curious. Don't change anything for me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants