如何随机均衡不相等的值? [英] How do I randomly equalize unequal values?

查看:105
本文介绍了如何随机均衡不相等的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有多个不相等的值a,b,c,d,e.仅通过使用随机数生成,是否可以将这些不相等的值转换为相等的值?

Say I have multiple unequal values a, b, c, d, e. Is it possible to turn these unequal values into equal values just by using random number generation?

示例:a = 100,b = 140,c = 200,d = 2,e = 1000.我希望算法随机地将这些集合作为目标,以使最大的价值成为最频繁的目标,而对于大多数部分而言,最小的价值则被搁置.

Example: a=100, b=140, c=200, d=2, e=1000. I want the algorithm to randomly target these sets such that the largest value is targeted most often and the smallest value is left alone for the most parts.

我遇到问题的区域:如果我仅使用非唯一随机数生成,则值e最终将落在其他值之下.如果使用唯一的数字生成,则即使绝对值不变,值之间的比率也不会改变.我尝试过使用一组值必须在一定范围内被击中一定次数才能更改值的集合.我还没有尝试使用唯一/非唯一随机数的组合.

Areas where I've run into problems: if I just use non-unique random number generation, then value e will end up going under the other values. If I use unique number generation, then the ration between the values doesn't change even if their absolute values do. I've tried using sets where a certain range of numbers have to be hit a certain number of times before the value changes. I haven't tried using a mix of unique/non-unique random numbers yet.

我希望算法运行时值之间的比率逐渐接近1.

I want the ratio between the values to gradually approach 1 as the algorithm runs.

思考问题的另一种方法:说这些值a,b,c,d,e都相等.如果我们随机选择一个,则每个选择的可能性与其他任何选择的可能性一样.选择一个后,我们向该值加1.然后,我们再次运行此过程.这次,上次选择的值比其他任何值大1,因此比其他任何一个值更容易被选择.这会产生滚雪球效应,在这种效应下,首先选择的值可能会继续被选择并实现失控的增长.我正在寻找与该算法相反的方法,该算法是在这些本来相等的值发生分歧之后才开始,然后将它们带回到本本相等的状态.

Another way to think about the problem: say these values a, b, c, d, e, are all equal. If we randomly choose one, each is as likely to be chosen as any other. After we choose one, we add 1 to that value. Then we run this process again. This time, the value that was picked last time is 1-larger than any other value so it's more likely to be picked than any one other value. This creates a snowball effect where the value picked first is likely to keep getting picked and achieve runaway growth. I'm looking for the opposite of this algorithm where we start after these originally-equal values have diverged and we bring them back to the originally-equal state.

由于熵和存在的固有单向性,我认为这个过程是不可能的.

I think this process is impossible because of entropy and the inherent one-way nature of existence.

推荐答案

好吧,有一种称为权重相反"的技术,您可以对与它们以前的外观成反比的项进行采样.每次采样a,b,c,d或e时,我们都会更新它们的出现次数并重新计算概率.简单的python代码,我将数字[0 ... 4]采样为a,b,c,d和e,并从您列出的外观开始. 100,000个样本后,它们看起来是均匀分布的

Well, there is a technique called Inverse Weights, where you sample items inverse proportional to their previous appearance. Each time we sample a, b, c, d or e, we update their appearance numbers and recalculate probabilities. Simple python code, I sample numbers [0...4] as a, b, c, d, e and start with what you listed as appearances. After 100,000 samples they looks to be equidistributed

import numpy as np

n = np.array([100, 140, 200, 2, 1000])

for k in range(1, 100000):

    p  = (1.0 / n) # make probabilities inverse to weights
    p /= np.sum(p) # normalization

    a = np.random.choice(5, p = p) # sampling numbers in the range [0...5)

    n[a] += 1 # update weights

print(n)

输出

[20260 20194 20290 20305 20392]

这篇关于如何随机均衡不相等的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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