double cls_random::randomBeta(
    double alpha,
    double beta)
{
    /*Johnk's beta generator*/
    double u, v;
    double x, y;
    do 
    {
        u=cls_random::randomUniform();
        v=cls_random::randomUniform();
        x=pow(u,1/alpha);
        y=pow(v,1/beta);
    } while (x+y>1);
    return x/(x+y);
}

期望:\operatorname{E}[x] = \frac{\alpha}{\alpha+\beta}\!

方差:V=\frac{\alpha\beta}{(\alpha+\beta)^2(\alpha+\beta+1)}\!

 

wiki: http://en.wikipedia.org/wiki/Beta_distribution

posted on 2012-07-15 21:17  yeahgis  阅读(3865)  评论(6编辑  收藏  举报