当前位置: 首页>>代码示例>>Java>>正文


Java Randomizer.nextGamma方法代码示例

本文整理汇总了Java中beast.util.Randomizer.nextGamma方法的典型用法代码示例。如果您正苦于以下问题:Java Randomizer.nextGamma方法的具体用法?Java Randomizer.nextGamma怎么用?Java Randomizer.nextGamma使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在beast.util.Randomizer的用法示例。


在下文中一共展示了Randomizer.nextGamma方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sample

import beast.util.Randomizer; //导入方法依赖的package包/类
@Override
public Double[][] sample(int size){
    double scaleVal = scale.getValue();
    Double[][] samples = new Double[size][1];
    try{

        for(int i =0; i < size;i++){
            Double[] dirichletSample = new Double[2];
            double sum = 0.0;
            for(int j  =0; j < 2;j++){
                dirichletSample[j] = Randomizer.nextGamma(alpha.getValue(j) * scaleVal, 1.0);
                sum += dirichletSample[j];
            }

            dirichletSample[0] = dirichletSample[0]/sum;
            samples[i][0] = dirichletSample[0];

        }
    }catch(Exception e){
        throw new RuntimeException(e);

    }
    return samples;

}
 
开发者ID:jessiewu,项目名称:substBMA,代码行数:26,代码来源:BetaDistribution.java

示例2: nextBetaScale

import beast.util.Randomizer; //导入方法依赖的package包/类
public static double nextBetaScale(Double[] alpha, double scaleVal){

        Double[] sample = new Double[alpha.length];
        double sum = 0.0;
        for(int j  = 0; j < sample.length;j++){
            sample[j] = Randomizer.nextGamma(alpha[j] * scaleVal, 1.0);
            sum += sample[j];
        }

        return sample[0]/sum;

    }
 
开发者ID:jessiewu,项目名称:substBMA,代码行数:13,代码来源:BetaDistribution.java

示例3: sample

import beast.util.Randomizer; //导入方法依赖的package包/类
@Override
public Double[][] sample(int size){
    double scaleVal = scale.getValue();
    int dim = alpha.getDimension();
    Double[][] samples = new Double[size][];
    try{

        for(int i =0; i < size;i++){
            Double[] dirichletSample = new Double[dim];
            double sum = 0.0;
            for(int j  =0; j < dim;j++){
                dirichletSample[j] = Randomizer.nextGamma(alpha.getValue(j)*scaleVal,1.0);
                sum += dirichletSample[j];
            }
            for(int j = 0; j < dim;j++){
                dirichletSample[j] = dirichletSample[j]/sum;
            }
            samples[i] = dirichletSample;

        }
    }catch(Exception e){
        throw new RuntimeException(e);

    }
    return samples;

}
 
开发者ID:jessiewu,项目名称:substBMA,代码行数:28,代码来源:DirichletDistribution.java

示例4: nextDirichletScale

import beast.util.Randomizer; //导入方法依赖的package包/类
public static Double[] nextDirichletScale(Double[] alpha, double scaleVal){

        Double[] sample = new Double[alpha.length];
        double sum = 0.0;
        for(int j  =0; j < sample.length;j++){
            sample[j] = Randomizer.nextGamma(alpha[j]*scaleVal,1.0);
            sum += sample[j];
        }

        for(int j = 0; j < sample.length;j++){
            sample[j] = sample[j]/sum;
        }
        return sample;

    }
 
开发者ID:jessiewu,项目名称:substBMA,代码行数:16,代码来源:DirichletDistribution.java

示例5: testPdf

import beast.util.Randomizer; //导入方法依赖的package包/类
public void testPdf() throws MathException  {

        final int numberOfTests = 300;
        double totErr = 0;
        double ptotErr = 0; int np = 0;
        double qtotErr = 0;

        Randomizer.setSeed(551);

        for(int i = 0; i < numberOfTests; i++){
            final double mean = .01 + (3-0.01) * Randomizer.nextDouble();
            final double var = .01 + (3-0.01) * Randomizer.nextDouble();

            double scale0 = var / mean;
            double shape = mean / scale0;

            final Gamma gamma = new Gamma();
            Gamma.mode mode = Gamma.mode.values()[Randomizer.nextInt(4)];
            
            double other = 0;
        	switch (mode) {
        	case ShapeScale: other = scale0; break;
        	case ShapeRate: other = 1/scale0; break;
        	case ShapeMean: other = scale0 * shape; break;
        	case OneParameter: other = 1/shape; scale0 = 1/shape; break;
        	}
            final double scale = scale0;

            gamma.initByName("alpha", shape +"", "beta", other +"", "mode", mode);

            final double value = Randomizer.nextGamma(shape, 1/scale);

            final double mypdf = mypdf(value, shape, scale);
            final double pdf = gamma.density(value);
            if ( Double.isInfinite(mypdf) && Double.isInfinite(pdf)) {
                continue;
            }

            assertFalse(Double.isNaN(mypdf));
            assertFalse(Double.isNaN(pdf));

            totErr +=  mypdf != 0 ? Math.abs((pdf - mypdf)/mypdf) : pdf;

            assertFalse("nan", Double.isNaN(totErr));
            //assertEquals("" + shape + "," + scale + "," + value, mypdf,gamma.pdf(value),1e-10);

            final double cdf = gamma.cumulativeProbability(value);
            UnivariateRealFunction f = new UnivariateRealFunction() {
                public double value(double v) throws FunctionEvaluationException {
                    return mypdf(v, shape, scale);
                }
            };
            final UnivariateRealIntegrator integrator = new RombergIntegrator();
            integrator.setAbsoluteAccuracy(1e-14);
            integrator.setMaximalIterationCount(16);  // fail if it takes too much time

            double x;
            try {
                x = integrator.integrate(f, 0, value);
                ptotErr += cdf != 0.0 ? Math.abs(x-cdf)/cdf : x;
                np += 1;
                //assertTrue("" + shape + "," + scale + "," + value + " " + Math.abs(x-cdf)/x + "> 1e-6", Math.abs(1-cdf/x) < 1e-6);

                final double q = gamma.inverseCumulativeProbability(cdf);
                qtotErr += q != 0 ? Math.abs(q-value)/q : value;
                //System.out.println(shape + ","  + scale + " " + value);
            } catch( ConvergenceException e ) {
                 // can't integrate , skip test
                 //System.out.print(" theta(" + shape + ","  + scale + ") skipped");
            }

           // assertEquals("" + shape + "," + scale + "," + value + " " + Math.abs(q-value)/value, q, value, 1e-6);
           // System.out.print("\n" + np + ": " + mode + " " + totErr/np + " " + qtotErr/np + " " + ptotErr/np);
        }
        //System.out.println( !Double.isNaN(totErr) );
       // System.out.println(totErr);
        // bad test, but I can't find a good threshold that works for all individual cases 
        assertTrue("failed " + totErr/numberOfTests, totErr/numberOfTests < 1e-7);
        assertTrue("failed " + qtotErr/numberOfTests , qtotErr/numberOfTests < 1e-10);
        assertTrue("failed " + ptotErr/np, np > 0 ? (ptotErr/np < 2e-7) : true);
	}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:82,代码来源:GammaTest.java


注:本文中的beast.util.Randomizer.nextGamma方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。