kernel_density_estimation/kernel/mod.rs
1//! Kernel functions.
2
3pub mod cosine;
4pub mod epanechnikov;
5pub mod logistic;
6pub mod normal;
7pub mod quartic;
8pub mod sigmoid;
9pub mod silverman;
10pub mod triangular;
11pub mod tricube;
12pub mod triweight;
13pub mod uniform;
14
15use crate::float::KDEFloat;
16
17/// Shared behavior for kernel functions.
18///
19/// Well-behaved kernel functions exhibit three properties:
20/// 1) The function is non-negative and real-valued.
21/// 2) The function should integrate to 1.
22/// 3) The function should be symmetrical.
23pub trait Kernel<F: KDEFloat> {
24 /// Returns the probability density function for a value `x`.
25 fn pdf(&self, x: F) -> F;
26}
27
28impl<T, F> Kernel<F> for T
29where
30 T: Fn(F) -> F,
31 F: KDEFloat,
32{
33 fn pdf(&self, x: F) -> F {
34 self(x)
35 }
36}