正方形上的随机均匀点分布(有捕获)
好的,均匀点分布的问题是通过一些众所周知的算法(Hammersley、Monte Carlo 等)解决的。但是,我的情况有点不同:假设我有一组值 (2, 8, 1, 5, 4, 7, 3, 6)。这些值通过索引(从 2 开始)顺序访问。如果它们映射在x轴上(通过访问模式,即在0处是2,在1处是8),我必须找到它们相应的y值,这样:
- 整个点集(同时考虑x和y坐标) 不是低差异序列;
- 任何一对 x 值(输入集)必须具有相应的 y 值,并且它们之间的距离最大;
结果是另一个集合 b ,其中混合整数 [1..8] 作为第一个,因此每个元组 (ai, bi) 都遵循上面的两个规则。
总结一下:我有一个轴上的分布(无论是哪一个轴),并且需要找到另一个轴上的分布,这样连续的点在访问时彼此远离,但总体而言,形成整体上的均匀分布正方形。
示例案例
给定 4 个元素的输入集 (3,1,4,2),一个好的结果集是(xy 合并):((3,1),(1,4), (4,2),(2,3)),这很好,因为当您访问这些点时(从 3,1 到结束),您访问的每个新点都会在两个 轴,这是总体平均分配的目标。相同输入集的错误结果情况是:((3,1),(1,2),(4,3),(2,4)),因为现在我们连续访问 y 值(尽管 x 值没问题) 。
这些都是填充用于采样的预先计算表所必需的,因此任何最终算法的速度并不重要(当然,只要不花 2 年)。任何帮助表示赞赏。
谢谢
Ok, so the problem of uniform point distribution is solved by some well known algorithms (Hammersley, Monte Carlo etc.). However, my situation is a bit different: lets say I have the set a of values (2, 8, 1, 5, 4, 7, 3, 6). Those values are accessed sequentially by index (starting with 2). If they are mapped on the x axis (by access pattern, ie. at 0 is 2, at 1 is 8), I have to find their corresponding y value, such that:
- the whole point set (both x and y coords considered) are not a low-discrepancy sequence;
- any pair of x values (the input set) must have their corresponding y values with a maximum distance between them;
Result is another set b with mixed integers [1..8] as the first, so every tuple (ai, bi) follows the two rules above.
To summarize: I have the distribution over one axis (no matter which one) and need to find the distribution over the other, such that consecutive points, when accessed, are far away from each other but overall, forming an uniform distribution on the whole square.
An example case
Given the input set of 4 elements (3,1,4,2), a good result set is (xy merged): ((3,1),(1,4),(4,2),(2,3)) and it is good because when you access the points (from 3,1 until end), with every new point you access you make a big leaps on both axes, which is the goal along with overall equal distribution. A bad result case for same input set is: ((3,1),(1,2),(4,3),(2,4)), since now we access y values consecutively (although x values are ok).
This is all required to fill a precomputed table which will be used for sampling, so the speed of any eventual algorithm does not matter (as long as it does not take 2 years, of course). Any help appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您也许可以使用分而治之的策略来实现这一目标。基本上,如果您想要 1:n 的排列,则创建 1:n/2 和 (n/2+1):n 的排列,并随机散布它们。
以下是如何随机散布它们:
我省略了对边界条件等的检查,如果您不知道如何处理该部分,请随时问我。
一旦你以上述方式获得了两个随机序列,反转其中一个并将它们配对,你就会得到你需要的配对序列。
You can probably use divide and conquer strategy to achieve this. Basically, if you want a permutation of 1:n, then create a permutation of 1:n/2 and (n/2+1):n, and intersperse them randomly.
Here is how you can intersperse them randomly:
I have left out checking for boundary conditions etc, feel free to ask me if you don't know how to take care of that part.
Once you get two random sequences in the above fashion, reverse one of those and pair them up, and you would get the pair sequence you need.