Grids Interface

Grids define the space over which the KDE is computed. The package supports:

  • Regular, Cartesian grids
  • User-defined bounds and resolution
  • Grid selection based on data distribution

There are currently two concrete grid types, one for CPU and one for CUDA devices. However, the interface is otherwise the same, so that it is possible to use the same code for both devices. It is also possible to create custom grids that conform to the interface.

ParallelKDE.Grids.AbstractGridType
AbstractGrid{N,T<:Real,M}

Supertype for all grid types, where N is the number of dimensions, T is the type of the coordinates (usually Float64 or Float32), and M is the number of dimensions in the underlying array (usually N + 1).

ParallelKDE.Grids.GridType
Grid{N,T<:Real,M}

CPU object for a grid with N dimensions, T type for coordinates, and M=N+1 dimensions for the underlying array.

ParallelKDE.Grids.CuGridType
CuGrid{N,T<:Real,M}

CUDA object for a grid with N dimensions, T type for coordinates, and M=N+1 dimensions for the underlying array.

There is a set of features that can be extracted from grid objects. This is done by the following methods:

Base.sizeMethod
size(grid::AbstractGrid)

Return the size of the grid, which is a tuple containing the number of points in each dimension.

Base.ndimsMethod
ndims(grid::AbstractGrid)

Return the number of dimensions of the grid.

ParallelKDE.Devices.get_deviceMethod
get_device(device::Any)

Obtain the device object for a given device type.

If the method is called with an unsupported type, it returns a DeviceNotSpecified object.

ParallelKDE.Grids.spacingsFunction
spacings(grid::AbstractGrid)

Return the spacings of the grid, which is a vector containing the spacing between points in each dimension.

ParallelKDE.Grids.boundsFunction
bounds(grid::AbstractGrid)

Return the bounds of the grid, which is a 2xN matrix containing the minimum and maximum values for each dimension.

ParallelKDE.Grids.low_boundsFunction
low_bounds(grid::AbstractGrid)

Return the lower bounds of the grid, which is a vector containing the minimum values for each dimension.

ParallelKDE.Grids.high_boundsFunction
high_bounds(grid::AbstractGrid)

Return the upper bounds of the grid, which is a vector containing the maximum values for each dimension.

ParallelKDE.Grids.initial_bandwidthFunction
initial_bandwidth(grid::AbstractGrid)

Return the initial bandwidth for the grid, which is half of the spacings in each dimension.

It is possible to create a grid with the desired ranges with

ParallelKDE.Grids.initialize_gridFunction
initialize_grid(ranges; device=:cpu, b32=false)
initialize_grid(ranges...; device=:cpu, b32=false)

Create a grid object based on the provided ranges of coordinates for each dimension.

device specifies the device type (default is :cpu but :cuda is also implemented), and, if a GPU is used, b32 determines whether to use Float32 or Float64 for the grid coordinates. For CPU grids, b32 is ignored and the data type matches the data type of ranges.

Examples

initialize_grid(0.0:0.1:1.0, 0.0:0.1:1.0, device=:cuda, b32=true)

as well as to create a grid appropriate for the data using

ParallelKDE.Grids.find_gridFunction
find_grid(data; kwargs...)

Find a grid based on the provided data, which can be a matrix or a vector of vectors.

Arguments

  • data: The input data, which can be an AbstractMatrix or an AbstractVector of vectors.
  • grid_bounds: Optional bounds for the grid. If not provided, bounds are calculated from the data.
  • grid_dims: Optional dimensions for the grid. If not provided, defaults to 300 points in each dimension.
  • grid_steps: Optional spacing steps for the grid to be used instead of dimensions. grid_dims takes precedence.
  • grid_padding: Optional padding for the grid bounds. If not provided, defaults to 10% of the range.

For convenience, the package includes a method to create a grid for Fourier space from a grid in direct space:

ParallelKDE.Grids.fftgridFunction
fftgrid(grid::AbstractGrid)

Calculate the Fourier grid based on the spacings of the input grid. The Fourier grid contains frequencies corresponding to the grid points in each dimension.