这张来自维基百科的图片有一个很好的例子,说明了我理想中想要生成的函数类型:
现在我正在使用 Irwin-Hall 分布,它或多或少是高斯分布的多项式近似...基本上,您使用均匀随机数生成器并迭代它 x 次,然后取平均数。迭代次数越多,它就越像高斯分布。
相当不错;但是我希望能够有一个可以改变平均值的方法。例如,假设我想要一个介于 0 到 10 之间的数字,但大约 7。例如,平均值(如果我多次重复此函数)将是 7,但实际值范围是 0-10。
有没有我应该查找的,或者我应该用标准高斯分布做一些奇特的数学?
This picture from Wikipedia has a nice example of the sort of functions I'd ideally like to generate:
Right now I'm using the Irwin-Hall Distribution, which is more or less a polynomial approximation of the Gaussian distribution...basically, you use uniform random number generator and iterate it x times, and take the average. The more iterations, the more like a Gaussian Distribution it is.
It's pretty nice; however I'd like to be able to have one where I can vary the mean. For example, let's say I wanted a number between the range 0 and 10, but around 7. Like, the mean (if I repeated this function multiple times) would turn out to be 7, but the actual range is 0-10.
Is there one I should look up, or should I work on doing some fancy maths with standard Gaussian distributions?
发布评论
评论(3)
我发现你的问题有矛盾。从一侧来看,您希望正态分布本质上是对称,从另一侧来看,您希望范围不对称地设置为平均值。
我怀疑您应该尝试查看其他分布密度函数,其类似于钟形曲线但不对称。就像日志分布或测试版发行版。
I see a contradiction in your question. From one side you want normal distribution which is symmetrical by it's nature, from other side you want the range asymmetrically disposed to mean value.
I suspect you should try to look at other distributions density functions of which are like bell curve but asymmetrical. Like log distribution or beta distribution.
查看生成正态随机变量。您可以生成正态随机变量对 X = N(0,1) 并将其转换为任何正态随机变量 Y = N(m,s) (Y = m + s*X)。
Look into generating normal random variates. You can generate pairs of normal random variates X = N(0,1) and tranform it into ANY normal random variate Y = N(m,s) (Y = m + s*X).
听起来截断正态分布正是医生所要求的。它本身并不“计算简单”,但如果您有正态分布的现有实现,则很容易实现。
您可以根据需要的均值、标准差以及任意两端生成分布。您必须事先做一些工作来计算基础(未截断)正态分布的平均值和标准差,以获得所需的 TN 平均值,但您可以使用该文章中的公式。另请注意,您也可以使用此方法调整方差:)
我有两个 准确(较慢) 和 快速(不太准确) 实现此分布,具有 PDF、CDF 和采样。
Sounds like the Truncated Normal distribution is just what the doctor ordered. It is not "computationally simple" per se, but easy to implement if you have an existing implementation of a normal distribution.
You can just generate the distribution with the mean you want, standard deviation you want, and the two ends wherever you want. You'll have to do some work beforehand to compute the mean and standard deviation of the underlying (non-truncated) normal distribution to get the mean for the TN that you want, but you can use the formulae in that article. Also note that you can adjust the variance as well using this method :)
I have Java code (based on the Commons Math framework) for both an accurate (slower) and quick (less accurate) implementation of this distribution, with PDF, CDF, and sampling.