r - Sampling from high dimensional sphere with noise -


i want generate sample of vectors high dimensional sphere noise.

i.e. i'm trying create sample such vector x in r^n , holds ||x+epsilon||^2 = 1 epsilon iid vector in r^n of component epsilon_j distributed n(0,sigma^2).

does have idea how implement it? i'd prefer use r.

thank you!

i think should work. turned function.

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

i begin sampling random vectors should uniformly distributed on unit sphere. normalizing draws d-dimensional multivariate normal distribution. (there's more direct way step, i'll using rmvnorm again later convenient.) call them dirs because, since we're normalizing, we're doing in step sampling "directions".

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

now draw multivariate normal add noise.

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

to map variables used in question, define y = x + epsilon. dirs y, noise add -epsilon; adding them yields x asked for.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -