生成给定幅度的随机5d向量 [英] Generate random 5d vector of given magnitude

查看:155
本文介绍了生成给定幅度的随机5d向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定五维空间,我想生成100个向量,所有向量都具有固定的幅度= M,其中组件值是随机分布的。

Given a five dimensional space, I would like to generate 100 vectors, all with a fixed magnitude=M, where the components values are randomly distributed.

我是最初考虑从单位矢量开始,然后应用旋转矩阵,随机参数为10自由度......这会起作用吗?以及如何?

I was originally thinking of starting off with a unit vector and then applying a rotation matrix, with random parameters for the 10 degrees of freedom ... Would this work? and how?

在Javascript中执行此操作的任何好方法......?

Any nice way of doing this in Javascript...?

欢呼任何指针!

推荐答案

这是我将使用的蒙特卡罗算法(我不知道Javascript是否足以在顶部编码我的头脑):

Here is the Monte Carlo algorithm that I would use (I do not know Javascript well enough to code in it off the top of my head):


  1. 为五个维度中的每一个生成-1到1范围内的随机值。

  1. Generate random values in the range from -1 to 1 for each of the five dimensions.

计算幅度M,如果M = 0或M> 1则拒绝这些值并返回步骤#1。

Calculate the Magnitude M, if M=0 or M>1 then reject these values and return to step #1.

将矢量标准化为幅度为1(将每个维度除以M)。

Normalize the vector to have a Magnitude of 1 (divide each dimension by M).

这应该为你提供均匀分布在5维超球面上的随机单位向量。

That should give you random unit vectors evenly distributed over the 5-dimensional super-sphere surface.

有人提出这样的问题:如果M> 1,为什么拒绝向量?

答案:这样最终的向量将会均匀分布在单元5-sphe的表面上重新

Answer: So that the final vectors will be uniformly distributed across the surface of the unit 5-sphere.

推理:我们在第一步生成的是一组随机向量均匀分布在单元5立方体的体积内。这些矢量中的一些也在单位5球的体积内,并且其中一些在该体积之外。如果归一化,5球内的矢量均匀分布在其表面上,然而,其外部的矢量根本不均匀分布。

Reasoning: What we are generating in the first step is a set of random vectors that are uniformly distributed within the volume of the unit 5-cube. Some of those vectors are also within the volume of the unit 5-sphere and some of them are outside of that volume. If normalized, the vectors within the 5-sphere are evenly distributed across its surface, however, the ones outside it are not at all evenly distributed.

想象一下:就像普通的三维单位立方体和单位球,甚至单位正方形和单位圆一样,单位5球体完全包含在单位5立方体内,仅接触在五个正单位维度轴点:

Think about it like this: Just as with a normal 3-dimensional Unit Cube and Unit Sphere, or even the Unit Square and the Unit Circle, the Unit 5-Sphere is wholly contained within the Unit 5-Cube, which touches only at the five positive unit dimension axis points:

(1,0,0,0,0)
(0,1,0,0,0)
(0,0,1,0,0)
(0,0,0,1,0)
(0,0,0,0,1)

及其对应的负单位轴点。这是因为这些是立方体表面上的唯一点,其大小(距离原点的距离)为1,在所有其他点,5立方体的表面与原点的距离更大比1。

and their corresponding negative unit axis points. This is because these are the only points on the surface of the cube that have a magnitude (distance from the origin) of 1, at all other points, the 5-cube's surface has a distance from the origin that is greater than 1.

这意味着(0,0,0,0,0)和(1,1,1之间还有更多的点数, 1,1)比(0,0,0,0,0)和(1,0,0,0,0)之间的差距大。事实上关于SQRT(5)或aprx。 2.25倍以上。

And this means that there are many more points between (0,0,0,0,0) and (1,1,1,1,1) than there are between (0,0,0,0,0) and (1,0,0,0,0). In fact about SQRT(5) or aprx. 2.25 times more.

这意味着如果你在单位5-cube中包含了所有的向量,你最终会得到两倍以上的数量结果随机映射到约(0.44,0.44,0.44,0.44,0.44)而不是(1,0,0,0,0)。

And that means that if you included all of the vectors in the unit 5-cube, you would end up with more than twice as many results "randomly" mapping to about (0.44,0.44,0.44,0.44,0.44) than to (1,0,0,0,0).

对于那些挑战(没有基础,恕我直言)这导致5-D球体表面均匀分布的人,请参阅维基百科文章: http://en.wikipedia.org/wiki/N-sphere#Alternatives

For those who are challenging (without foundation, IMHO) that this results in a uniform distribution across the surface of the 5-D Sphere, please see the Wikipedia article: http://en.wikipedia.org/wiki/N-sphere#Alternatives

这篇关于生成给定幅度的随机5d向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆