condense: Sample points based on distance matrix

Description Usage Arguments Value Examples

Description

Sample points based on distance matrix so that distance between any pair is not less than a fixed radius. This will not preserve density, but does preserve local outliers.

Usage

1
condense(d, radius, seed = 1, ...)

Arguments

d

object of class 'dist'

radius

(numeric) radius around a point

seed

(positive integer) A seed. Default is 1.

...

Arguments for frNN

Value

Index of condensed points

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
library("magrittr")
dataset <- rbind(
  MASS::mvrnorm(1000, mu = c(0, 0), Sigma = matrix(c(1, 0.3, 0.3, 1), 2))
  , MASS::mvrnorm(100, mu = c(10, 10), Sigma = matrix(c(1, 0.3, 0.3, 1), 2))
  , MASS::mvrnorm(10, mu = c(5, 5), Sigma = matrix(c(1, 0.3, 0.3, 1), 2))
  , MASS::mvrnorm(10, mu = c(0, 8), Sigma = matrix(c(1, 0.3, 0.3, 1), 2))
  , MASS::mvrnorm(10, mu = c(7, 0), Sigma = matrix(c(1, 0.3, 0.3, 1), 2))
  )
plot(dataset)
do <- dist(dataset)
dbscan::kNNdist(do, 4) %>% apply(1, median) %>% summary()

ci <- condense(do, 0.103)
dataset[ci, ] %>% plot()
dataset[condense(do, 0.68), ] %>% plot()

talegari/sidekicks documentation built on May 30, 2019, 8:40 a.m.