Sampling from a noisy high-dimensional sphere

I want to generate a sample of vectors from a high dimensional noisy sphere.

those. I am trying to create a pattern such that any vector X is in R ^ N and has || X + epsilon || ^ 2 = 1, where epsilon is the vector iid in R ^ N from which any component epsilon_j N (0 sigma ^ 2) is distributed.

Does anyone have any ideas how to implement it? I would rather use R.

Thank!

+3


source to share


1 answer


I think this should work. It can be easily turned into a function.

d = 5         # number of dimensions
n_draws = 100 # number of draws
sigma = 0.2   # standard deviation

      

I'll start by sampling random vectors that should be evenly distributed on the unit sphere. I do this by normalizing the draws from a d-dimensional multivariate normal distribution. (There is probably a more direct way to do this step, but I am using it again rmvnorm

, so it was convenient.) I call them dirs

because since we are normalizing, all we really do in this step is sampling "directions".

library(mvtnorm)
# sample
dirs = rmvnorm(n = n_draws, mean = rep(0, d))
# normalize
dirs = dirs / sqrt(rowSums(dirs^2))

      



Now we draw another inference from the multidimensional normal to add noise.

x = dirs + rmvnorm(n = n_draws, mean = rep(0, d), sigma = sigma * diag(d))

      

To map this to the variables you used in your question, define Y = X + epsilon. Mine dirs

is Y, then the noise I add is an exilon; adding them gives the X you asked for.

+1


source







All Articles