### curse of dimensionality ## Illustrate by simulation the following fact ## ----------------------------------------------------------------------- ## In high dimension d : Most points in Unit Cube are outside unit ball : ## ----------------------------------------------------------------------- n <- 100000 res <- numeric(20) set.seed(22) for(d in 1:20) { ## dimension 1, 2, ... , 20 ## random points in unit cube [-1, 1] ^ d: x <- matrix(runif(n*d, -1, 1), nrow = n, ncol = d) ## ratio of points falling inside the unit ball {x ; ||x|| <= 1 } : res[d] <- mean(rowSums(x^2) <= 1) } cbind(res) library("sfsmisc") ## -> 'mult.fig()', ps.do() ps.do(file = "curse.eps",height = 8) mult.fig(mfrow = c(1,2), main ="relative frequency of U[0,1] obs. in unit ball") plot(1:20,res,type = "b", xlab = "dimension d", ylab = "relative frequency") abline(h = 0.2, col="light blue") ## zoom in : plot(1:20,res,type = "b", ylim = c(0,0.2), xlab = "dimension d", ylab = "relative frequency") ps.end()