Created
April 29, 2015 22:57
-
-
Save lgatto/6479628cfbce942b5def to your computer and use it in GitHub Desktop.
Curse of dimensionality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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