knnDE {TDA}R Documentation

k Nearest Neighbors Density Estimator over a Grid of Points

Description

Given a point cloud X (nn points), The function knnDE computes the k Nearest Neighbors Density Estimator over a grid of points. For each xRdx \in R^d, the knn Density Estimator is defined by

pX(x)=kn  vd  rkd(x), p_X(x)=\frac{k}{n \; v_d \; r_k^d(x)},

where vnv_n is the volume of the Euclidean dd dimensional unit ball and rkd(x)r_k^d(x) is the Euclidean distance from point x to its kk'th closest neighbor.

Usage

knnDE(X, Grid, k)

Arguments

X

an nn by dd matrix of coordinates of points used in the density estimation process, where nn is the number of points and dd is the dimension.

Grid

an mm by dd matrix of coordinates, where mm is the number of points in the grid.

k

number: the smoothing paramter of the k Nearest Neighbors Density Estimator.

Value

The function knnDE returns a vector of length mm (the number of points in the grid) containing the value of the knn Density Estimator for each point in the grid.

Author(s)

Fabrizio Lecci

See Also

kde, kernelDist, distFct, dtm

Examples

## Generate Data from the unit circle
n <- 300
X <- circleUnif(n)

## Construct a grid of points over which we evaluate the function
by <- 0.065
Xseq <- seq(-1.6, 1.6, by = by)
Yseq <- seq(-1.7, 1.7, by = by)
Grid <- expand.grid(Xseq, Yseq)

## kernel density estimator
k <- 50
KNN <- knnDE(X, Grid, k)

[Package TDA version 1.9.1 Index]