Skip to content

Add support for multivariate KDEΒ #2

@seatonullberg

Description

@seatonullberg

Currently only univariate distributions are supported. A complete implementation would include seamless support for multivariate distributions. The only type that should be changed is the KernelDensityEstimator struct. Currently, the data structure is as follows:

pub struct KernelDensityEstimator<B, K> {
    observations: Vec<Float>,
    bandwidth: B,
    kernel: K,
}

The observations field will need to be converted to a nalgebra::DMatrix to support a multivariate distribution. The type should be hidden behind an alias so that end-users do not need to add nalgebra as a dependency in their own projects.

pub type Matrix2D = nalgebra::DMatrix<Float>;

pub struct KernelDensityEstimator<B, K> {
    observations: Matrix2D,
    bandwidth: B,
    kernel: K,
}

To prevent needless conversions for users working with univariate data, the data structure could instead add a generic parameter T representing the type of observations. For univariate data T could be concretely represented as Vec<Float> and for multivariate data T could be concretely represented as Matrix2D. However, this would require the introduction of two new traits UnivariateKDE and MultivariateKDE to mimic overloading of the method names pdf, cdf, and sample.

pub struct KernelDensityEstimator<T, B, K> {
    observations: T,
    bandwidth: B,
    kernel: K,
}

pub trait UnivariateKDE {
    // Unimplemented.
}

pub trait MultivariateKDE {
    // Unimplemented.
}

// Univariate case.
impl<B, K> UnivariateKDE for KernelDensityEstimator<Vec<Float>, B, K>
where
    B: Bandwidth,
    K: Kernel,
{
    // Unimplemented.
}

// Multivariate case.
impl<B, K> MultivariateKDE for KernelDensityEstimator<Matrix2D, B, K>
where
    B: Bandwidth,
    K: Kernel,
{
    // Unimplemented.
}

Lastly, the traits UnivariateKDE and MultivariateKDE should be sealed to prevent end-user implementations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions