knnDE: k Nearest Neighbors Density Estimator over a Grid of Points

Description Usage Arguments Value Author(s) See Also Examples

View source: R/knnDE.R

Description

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

p_X (x) = k / (n * v_d * r_k^d(x)),

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

Usage

1
knnDE(X, Grid, k)

Arguments

X

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

Grid

an m by d matrix of coordinates, where m 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 m (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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## 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)

Example output



TDA documentation built on March 30, 2021, 5:10 p.m.