随机元素的统计/加权/概率选择

发布于 2024-10-06 12:32:23 字数 147 浏览 0 评论 0原文

我正在创建一组项目,并计算每个项目在样本中出现的次数。后来我希望随机选择一个项目,但我希望选择任何特定项目的机会等于出现次数与所有项目的所有出现次数之和相比。

我相信我已经找到了一个很好的解决方案,但我感兴趣的是这个概念的标准术语是什么以及实现它的标准方法是什么。

I am creating a set of items and with each I am counting its number of occurrences in a sample. Later I wish to choose an item at random but I want the chance of choosing any particular item to be equal to the number of occurrences as compared to the total of all occurrences of all items.

I believe I have found a nice solution but I'm interested what the standard term for this concept is and what the standard methods of achieving it are.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟若柳尘 2024-10-13 12:32:23

这本身没有名称,但它是根据粒子过滤期间的证据更新您的信念的重要一步,这可能就是您正在寻找的术语。

从 0 到 n-1 中选择一个随机数 (r)(n 是所有项目出现的总次数)。然后迭代每个项目并从 r 中减去出现的次数。当您的值低于零时,选择最后一项。请注意,将相同的项目分组在同一位置并不重要。您可能会重复,但这仍然有效。

或者,如果您的出现次数单独存储在数组中(而不是直方图),则只需从数组中选择一个随机索引即可。

This doesn't have a name on it's own, but it's an important step in updating your beliefs based on evidence during PARTICLE FILTERING which is probably the term you're looking for.

Choose a random number (r) from 0 to n-1 (n is the total number of occurrences of all items). Then iterate over each item and subtract the number of occurrences from r. When you get below zero, select the last item. Note that it's not important to group the same item in the same place. You may have repeats and this will still work.

Alternatively, if your occurrences are stored individually in an array (rather than a histogram), simply select a random index from the array.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文