我有偏态正态分布的概率密度函数。我想生成跟随matlab中偏斜正态分布的随机数。
答案 0 :(得分:1)
不能保证其性能/充足性,但http://azzalini.stat.unipd.it/SN/说明如下,并且链接到MATLAB函数的.zip文件:
图书馆由Nicola Sartori移植到Matlab。到目前为止,这指的是更新0.21;因此,不包括偏斜分布的设施。然而,可以通过a set of Matlab functions获得部分斜交分布设施,这些设施由Enrique Batiz(Enrique.Batiz [at] postgrad.mbs.ac.uk)编写并提供
另请参阅Visual Basic中的this code,但应该很容易移植。相关摘录如下所示。这使用RandNorm(也在链接的网页中),它是单位正态分布中的一对数字,在MATLAB中,您应该能够使用randn(2,1)
。
Function RandSkew(fAlpha As Single, _
Optional fLocation As Single = 0, _
Optional fScale As Single = 1, _
Optional bVolatile As Boolean = False) As Single
' shg 2008-0919
' http://azzalini.stat.unipd.it/SN/faq.html
' Returns a random variable with skewed distribution
' fAlpha = skew
' fLocation = location
' fScale > 0 = scale
Dim sigma As Single
Dim afRN() As Single
Dim u0 As Single
Dim v As Single
Dim u1 As Single
If bVolatile Then Application.Volatile
Randomize (Timer)
sigma = fAlpha / Sqr(1 + fAlpha ^ 2)
afRN = RandNorm()
u0 = afRN(1)
v = afRN(2)
u1 = sigma * u0 + Sqr(1 - sigma ^ 2) * v
RandSkew = IIf(u0 >= 0, u1, -u1) * fScale + fLocation
End Function