简体   繁体   English

来自Matlab中pdf的随机变量

[英]Random variable from pdf in matlab

I want to simulate some random variables distributed as a Variance Gamma. 我想模拟一些作为方差Gamma分布的随机变量。

I know the pdf ( http://en.wikipedia.org/wiki/Variance-gamma_distribution ) but I don't know the inverse of the cumulative function F: so I can't generate a random uniform variable U and compute x=F^(-1)(U). 我知道pdf( http://en.wikipedia.org/wiki/Variance-gamma_distribution ),但我不知道累积函数F的反函数:因此,我无法生成随机的统一变量U并计算x=F^(-1)(U). I have to do this in MATLAB. 我必须在MATLAB中执行此操作。

Thank you! 谢谢!

Stefano 斯特凡诺

The next natural alternative to look into is Von Neumann's "acceptance-rejection method". 接下来要考虑的另一种自然选择是冯·诺伊曼(Von Neumann)的“拒绝接受方法”。

If you can find a density g defined on the same space as your f such that 如果您发现在与f相同的空间上定义的密度g ,从而

  1. you know how to generate samples from g , and 您知道如何从g生成样本,以及
  2. f(x) <= cg(x), for some c, for all x, f(x)<= cg(x),对于某些c,对于所有x,

then you are good to go. 那你就好了

If you search the literature, people must have done this. 如果您搜索文献,人们一定已经做到了。 The VG is widely used in pricing options. VG在定价选项中广泛使用。

Following @Drake 's idea: for the first step you can use Marsaglia and Tsang's Method from here . 遵循@Drake的想法:第一步,可以从此处使用Marsaglia和Tsang的Method。

This is the code to generate gamma random numbers: 这是生成伽玛随机数的代码:

function x=gamrand(alpha,lambda)
% Gamma(alpha,lambda) generator using Marsaglia and Tsang method
% Algorithm 4.33
if alpha&gt;1
    d=alpha-1/3; c=1/sqrt(9*d); flag=1;
    while flag
        Z=randn;
        if Z&gt;-1/c
            V=(1+c*Z)^3; U=rand;
            flag=log(U)&gt;(0.5*Z^2+d-d*V+d*log(V));
        end
    end
    x=d*V/lambda;
else
    x=gamrand(alpha+1,lambda);
    x=x*rand^(1/alpha);
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM