1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
//! Different [kernels][1] for [`crate::kde::KernelDensityEstimator`].
//!
//! These are used to model the «good» and «bad» parameter distributions.
//! One can always them separately, as well.
//!
//! [1]: https://en.wikipedia.org/wiki/Kernel_(statistics)
use fastrand::Rng;
pub mod continuous;
pub mod discrete;
pub mod universal;
/// Density function.
pub trait Density {
/// Parameter type.
type Param;
/// Output density value type.
type Output;
/// Calculate the density at the given point.
#[must_use]
fn density(&self, at: Self::Param) -> Self::Output;
}
/// Parameter sampler.
pub trait Sample {
/// Sampled value type.
///
/// It is called that because parameters are sampled for evaluation.
type Param;
/// Generate a random sample from the kernel.
#[must_use]
fn sample(&self, rng: &mut Rng) -> Self::Param;
}
/// A single kernel of a kernel density estimator.
///
/// Note that it does not directly correspond to the [mathematical definition][1],
/// as for example, it is responsible for its own shift and scaling.
/// This is useful for discrete kernels which do not normally have a bandwidth parameter `h`.
///
/// [1]: https://en.wikipedia.org/wiki/Kernel_(statistics)
pub trait Kernel {
type Param;
/// Construct a kernel with the given location and bandwidth.
#[must_use]
fn new(location: Self::Param, std: Self::Param) -> Self;
}