Iterate over all vectors of length `L`
How can I iterate over all possible vectors of dimensions d
with a specified length (like unit length), where delta
is the step size.
Note that it delta
can be quite small, for example, 1e-3
for a unit vector. d
usually in range [0,5]
, but not a hard limit!
A dumb approach would be to use a list delta*i
for i in [0,N)
and generate all possible combos as in n, pick n and pick the ones that add up to 1
. But this seems to be quite inefficient and I am sure there are better approaches that I am not aware of.
The peaks should be at least close to evenly distributed over the surface.
source to share
Ok, I think I figured out what you need. Basically, if you choose
X=(X1, X2, ..., Xn)/norm(X)
where X1, X2,..., Xn
are usually distributed N(0,1)
(mean value 0 and standard deviation 1), and norm(X)
- norm L2 (Euclidean) X
, then uniform distribution of the vector X
through the surface of the n
-dimensional unit sphere is guaranteed .
Now, since you want to sample, just draw each Xi
of the binomial distribution (which at the limit is known to become a Poisson distribution, which converges to a Gaussian distribution by the Central Limit Theorem, see http://www.roe.ac.uk/japwww /teaching/astrostats/astrostats2012_part2.pdf ) and you 're done. Of course, you will get exponential scaling in dimension n
, but I don't think there is any other way, since the number of such vectors scales exponentially with dimension.
source to share