ParallelKDE Interface

This is the main module users interact with. It re-exports the essential tools to:

  • Define and configure estimators
  • Run KDEs on different devices (CPU, CUDA)
  • Access results and manipulate densities

Currently, the main objects for the estimation are:

ParallelKDE.AbstractDensityEstimationType
AbstractDensityEstimation

Supertype for all density estimation objects.

This is the base for all objects that intended to store the estimated density, and, optionally, the grid on which the density is estimated.

See also DensityEstimation for the concrete implementation.

ParallelKDE.DensityEstimationType
DensityEstimation{K<:AbstractKDE,G<:Union{Nothing,AbstractGrid}}

Concrete type for density estimation objects.

This type holds a kernel density estimation (KDE) object kde and an optional grid grid.

It is possible to initialize the estimation object with:

ParallelKDE.initialize_estimationFunction
initialize_estimation(data; kwargs...)

Initialize a density estimation object based on the provided data.

Arguments

  • data::Union{AbstractMatrix,AbstractVector{<:AbstractVector}}: The data to be used for density estimation.
  • grid::Union{Bool,G<:AbstractGrid}=false: Whether to create a grid for the density estimation.

If true, a grid will be created based on the data ranges. A grid can also be provided directly.

  • grid_ranges=nothing: The ranges for the grid coordinates if grid is true.

This has priority over other grid parameters.

  • dims=nothing: The dimensions of the grid if grid is true.
  • grid_bounds=nothing: The bounds for the grid if grid is true.
  • grid_padding=nothing: Padding for the grid if grid is true.
  • device=:cpu: The device to use for the density estimation. It should be compatible with the estimator to be used.

Examples

data = randn(1, 1000);
density_estimation = initialize_estimation(data; grid=true, grid_ranges=-5.0:0.1:5.0, device=:cpu);

Estimation objects are designed to support a grid for grid-based density estimation. However, this is not mandatory. To test if a grid is present and obtain a grid object, you can use:

ParallelKDE.has_gridFunction
has_grid(density_estimation::DensityEstimation)

Return true if the DensityEstimation object has a grid associated with it, false otherwise.

Examples

data = randn(1, 1000);
density_estimation = initialize_estimation(data; grid=true, grid_ranges=-5.0:0.1:5.0, device=:cpu);
has_grid(density_estimation)
ParallelKDE.get_gridFunction
get_grid(density_estimation::DensityEstimation)

Extract the grid from a DensityEstimation object.

Executing the estimation and obtaining the density is done with:

ParallelKDE.estimate_density!Function
estimate_density!(density_estimation::DensityEstimation, estimation_method::Symbol; kwargs...)

Estimate the density using the specified method and update the DensityEstimation object.

For a list of available estimation methods and their keywords, see the documentation for the specific estimator.

ParallelKDE.KDEs.get_densityMethod
get_density(density_estimation::DensityEstimation; normalize=false, dx=nothing)

Obtain the estimated density from a DensityEstimation object.

If the normalize argument is set to true, the density will be normalized. If density_estimation has a grid, its spacing will be used for normalization. Otherwise, dx must be provided to normalize the density.