本文介绍了从偏正态分布生成随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您在大多数语言中使用random(min,max)函数时,分布是什么样的?

when you use the random(min,max) function in most languages, what is the distribution like ?

如果我想在20%的时间内生成一个范围内的数字,而在80%的时间内生成另一个范围内的数字,我该如何生成紧随其后的一系列随机数呢?

what if i want to produce a range of numbers for 20% of the time, and another range of numbers for 80% of the time, how can i generate series of random number that follows that ?

ex)我应该获得随机频率,但是"1"的频率必须比"0"的频率高20%左右

ex) i should get random frequency but the frequency of "1" must be higher by around 20% than the frequency of "0"

推荐答案

就像任何人所说的那样,大多数语言上的伪随机数生成器实现了(0,1)上的统一分布.如果您有两个响应类别(0,1),p的概率为1,则您具有伯努利分布,并且可以用

Like anybody says, pseudo-random number generator on most languages implements the uniform distribution over (0,1).If you have two responses categories (0,1) with p probability for 1, you have a Bernoulli distribution and can be emulated with

#  returns 1 with p probability and 0 with (1-p) probability
def bernoulli(p)
rand()<p ? 1:0;
end

就这么简单.偏态正态分布是完全不同的野兽,由正态分布的pdf和cdf的联合"产生偏斜.您可以在此处阅读.使用宝石分布,您可以生成概率密度函数,

Simple as that.Skewed normal distribution is a entirely different beast, made by the 'union' of pdf and cdf of a normal distribution to create the skew. You can read Azzalini's work here. Using gem distribution, you can generate the probability density function, with

# require 'distribution'
def sn_pdf(x,alpha)
sp = 2*Distribution::Normal.pdf(x)*Distribution::Normal.cdf(x*alpha)
end

获得cdf很困难,因为没有解析解决方案,因此您应该进行集成.要从倾斜的法线获取随机数,可以使用接受拒绝算法.

Obtains the cdf is difficult, because there isn't an analytical solution, so you should integrate.To obtain random numbers from a skewed normal, you could use the acceptation-rejection algorithm.

这篇关于从偏正态分布生成随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 19:28