可变数量集合之间的模糊选择
我想知道在以下情况下哪种是获取我需要的内容的最简单和最可配置的方法:
- 我有一个计数器,让我们称之为
X
,它将用于提取 - 我拥有的 集合之一可变数量的集合
S1,S2,..
,可以被视为总订购 在它们之间 - 我想混合这些集合以模糊的方式,这样对于
X = 0
它将给我S1
,对于,比方说,X = 20
它会给我 < code>S1 的概率为 70%,S2
的概率为 30% - 增加
X
会降低S1
的概率直至 0%,而增加S2
达到 100%,那么可能存在一个区域,在该区域中它将始终为我提供S2
直到一个新的阈值,其中S2
将开始减少,并且S3
将开始获得机会,依此类推,
我知道如何通过对所有内容进行硬编码来做到这一点,但因为它需要一些调整我想应用一个解决方案,它可以轻松地允许我配置我有多少组和单个阈值(增加概率的开始/结束和减少概率的开始/结束)。当然,我不需要超过 2 个集合之间有任何交集,概率的线性增加/减少就可以了..有什么好的线索吗?
提前致谢!
I was wondering which is the simplest and most configurable way to obtain what I need in the following situation:
- I have a counter, let's call it
X
that will be used to extract one of the sets - I have a variable number of sets
S1, S2, ..
which can be considered total ordered between themselves - I want to mix these sets in a fuzzy way so that for
X = 0
it will give meS1
, for, let's say,X = 20
it will give meS1
with 70% chance, andS2
with 30% chance - Increasing
X
will decrease probability ofS1
until 0% while increasingS2
up to 100%, then there can be a zone in which it will always give meS2
until a new threshold for whichS2
will start to decrease andS3
will start getting its chance and so on
I know how to do it by hardcoding everything, but since it will need some tweaking I would like to apply a solution which easily allows me to configure how many sets I have and the single thresholds (start/end of increasing probability and start/end of decreasing prob). Of course I don't need any intersection between more than 2 sets each and a linear increase/decrease of probability is ok.. any good clues?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要分配概率分布,您可以使用 Bernstein 多项式:
http://en.wikipedia.org/wiki /Bernstein_polynomial
这些可以使用 de Casteljau 算法有效地计算(基本上它以明显的方式在递归上进行 DP):
http://en.wikipedia.org/wiki/De_Casteljau's_algorithm
http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/Bezier/de-casteljau.html
你得到的结果将是一个集合分布上的权重。要选择其中一个集合,您只需在 [0,1] 中生成一个均匀随机变量,然后根据这些权重选择它所在的集合。
下面是 python 中的一些代码,它执行此操作:
To assign the distribution of your probabilities, you could use Bernstein polynomials:
http://en.wikipedia.org/wiki/Bernstein_polynomial
These can be efficiently computed using de Casteljau's algorithm (basically it does DP on the recursion in the obvious way):
http://en.wikipedia.org/wiki/De_Casteljau's_algorithm
http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/Bezier/de-casteljau.html
What you get as a result will be a set of weights on the distributions. To select one of your sets, you just generate a uniform random variable in [0,1] then choose the set it lands in based on these weights.
Here is some code in python which does this: