Generate random points on 10-dimensional unit sphere

纵饮孤独 提交于 2020-12-26 04:21:48

问题


I need to generate a vector sampled uniformly with 10 directions (a collection of 10 random numbers) which lies over a unit sphere. So, the sum of the squares of the 10 values should be 1.

This is the exact question for which I need to generate those points:

Implement the Perceptron algorithm and run it on the following synthetic data sets in ℝ10: pick 𝑤∗ = [1,0,0,…,0]; generate 1000 points 𝑥 by sampling uniformly at random over the unit sphere and then removing those that have margin 𝛾 smaller than 0.1; generate label 𝑦 = sign((𝑤∗)T𝑥).


回答1:


As @Andrex suggested, here is the right solution:

import numpy as np
import math

s = np.random.normal(0, 1, 10)

norm=math.sqrt(sum(s*s))
result=s/norm

where result is the answer. You can evaluate the result:

sum([x*x for x in result])
1.0



回答2:


There is a math theorem saying that if X = (X1,...,XN) is a vector with Xi the standard normal distribution, then X/NORM(X) is uniform in the unit sphere, where NORM is the euclidean norm. So you have to sample 10 points from a standard normal distribution (using numpy?) and then normalize the result.



来源:https://stackoverflow.com/questions/59954810/generate-random-points-on-10-dimensional-unit-sphere

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!