Skip to content

Instantly share code, notes, and snippets.

@lgatto
Created April 29, 2015 22:57
Show Gist options
  • Save lgatto/6479628cfbce942b5def to your computer and use it in GitHub Desktop.
Save lgatto/6479628cfbce942b5def to your computer and use it in GitHub Desktop.
Curse of dimensionality
import numpy
import pylab
def sample(d=2, N=1000):
return [[uniform(0., 1.) for i in range(d)] for _ in range(N)]
def corner_count(points):
return mean([any([(d < .01 or d > .99) for d in p]) for p in points])
def go(Ds=range(1,200)):
plot(Ds, [corner_count(sample(d)) for d in Ds])
d <- 1:200
N <- 1000
dat <- lapply(d, function(i) replicate(i, runif(N)))
nout <- function(m) mean(apply(m, 1, function(i) any(i < 0.01 | i > 0.99)))
res <- sapply(dat, nout)
plot(res, type = "l",
xlab = "Number of dimensions",
ylab = "Proportion of 1% outliers",
main = "Curse of Dimensionality")
grid()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment