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


Java MachineAccuracy类代码示例

本文整理汇总了Java中beast.math.MachineAccuracy的典型用法代码示例。如果您正苦于以下问题:Java MachineAccuracy类的具体用法?Java MachineAccuracy怎么用?Java MachineAccuracy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testRandomWalkOperator

import beast.math.MachineAccuracy; //导入依赖的package包/类
@Test
public void testRandomWalkOperator() {
    Parameter parameter = new Parameter.Default("test", 0.5, 0.0, 1.0);
    RandomWalkOperator rwo = new RandomWalkOperator(parameter, 1.0, RandomWalkOperator.BoundaryCondition.reflecting, 1.0, CoercionMode.COERCION_OFF);
    
    double test1 = rwo.reflectValue(8.7654321, 3.14159265, Double.POSITIVE_INFINITY);
    double test2 = rwo.reflectValue(8.7654321, Double.NEGATIVE_INFINITY, 3.14159265);
    double test3 = rwo.reflectValue(1.2345678, 3.14159265, 2.0 * 3.14159265);
    double test4 = rwo.reflectValue(12345678.987654321, 3.14159265, 2.0 * 3.14159265);

    double test1b = rwo.reflectValueLoop(8.7654321, 3.14159265, Double.POSITIVE_INFINITY);
    double test2b = rwo.reflectValueLoop(8.7654321, Double.NEGATIVE_INFINITY, 3.14159265);
    double test3b = rwo.reflectValueLoop(1.2345678, 3.14159265, 2.0 * 3.14159265);
    double test4b = rwo.reflectValueLoop(12345678.987654321, 3.14159265, 2.0 * 3.14159265);

    assertEquals(test1, test1b, MachineAccuracy.EPSILON);
    assertEquals(test2, test2b, MachineAccuracy.EPSILON);
    assertEquals(test3, test3b, MachineAccuracy.EPSILON);
    assertTrue(Math.abs(test4 - test4b) < 0.001);

}
 
开发者ID:armanbilge,项目名称:B3,代码行数:22,代码来源:RandomWalkOperatorTest.java

示例2: likelihoodTester

import beast.math.MachineAccuracy; //导入依赖的package包/类
private void likelihoodTester(Tree tree, double birthRate, double deathRate, Variable<Double> origin, double logL) {

        Variable<Double> b = new Variable.D("b", birthRate);
        Variable<Double> d = new Variable.D("d", deathRate);
        Variable<Double> psi = new Variable.D("psi", this.psi);
        Variable<Double> p = new Variable.D("p", this.p);
        Variable<Double> r = new Variable.D("r", 0.5);
        Variable<Double> fTime = new Variable.D("time", 0.0);

        SpeciationModel speciationModel = new BirthDeathSerialSamplingModel(b, d, psi, p, false, r, true, origin, Units.Type.YEARS);
        Likelihood likelihood = new SpeciationLikelihood(tree, speciationModel, "bdss.like");

        assertEquals(logL, likelihood.getLogLikelihood(), MachineAccuracy.EPSILON);
    }
 
开发者ID:armanbilge,项目名称:B3,代码行数:15,代码来源:BirthDeathSSLikelihoodTest.java

示例3: testPdf

import beast.math.MachineAccuracy; //导入依赖的package包/类
@Test
public void testPdf() {

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

       Random random = new Random(37);

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

           final double scale = var / mean;
           final double shape = mean / scale;

           final GammaDistribution gamma = new GammaDistribution(shape,scale);

           final double value = gamma.nextGamma();

           final double mypdf = mypdf(value, shape, scale);
           final double pdf = gamma.pdf(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.cdf(value);
           UnivariateFunction f = new UnivariateFunction() {
               public double value(double v) {
                   return mypdf(v, shape, scale);
               }
           };
           final UnivariateIntegrator integrator = new RombergIntegrator(MachineAccuracy.SQRT_EPSILON, 1e-14, 1, 16);

           double x;
           try {
               x = integrator.integrate(16, f, 0.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);

               //System.out.println(shape + ","  + scale + " " + value);
           } catch(MaxCountExceededException e ) {
                // can't integrate , skip test
             //  System.out.println(shape + ","  + scale + " skipped");
           }

           final double q = gamma.quantile(cdf);
           qtotErr += q != 0 ? Math.abs(q-value)/q : value;
          // assertEquals("" + shape + "," + scale + "," + value + " " + Math.abs(q-value)/value, q, value, 1e-6);
       }
       //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 " + ptotErr/np, np > 0 ? (ptotErr/np < 1e-5) : true);
       assertTrue("failed " + qtotErr/numberOfTests , qtotErr/numberOfTests < 1e-7);
}
 
开发者ID:armanbilge,项目名称:B3,代码行数:68,代码来源:GammaDistributionTest.java

示例4: testBirthDeathLikelihoodP0

import beast.math.MachineAccuracy; //导入依赖的package包/类
@Test
public void testBirthDeathLikelihoodP0() {
    assertEquals(BirthDeathSerialSamplingModel.p0(birthRate, deathRate, p, psi, 1.0), 0.28236670080320814, MachineAccuracy.EPSILON);
}
 
开发者ID:armanbilge,项目名称:B3,代码行数:5,代码来源:BirthDeathSSLikelihoodTest.java

示例5: yuleLikelihoodTester

import beast.math.MachineAccuracy; //导入依赖的package包/类
private void yuleLikelihoodTester(Tree tree, double birthRate, double logL) {

        Parameter b = new Parameter.Default("b", birthRate, 0.0, Double.MAX_VALUE);
        Parameter d = new Parameter.Default("d", 0.0, 0.0, Double.MAX_VALUE);

        SpeciationModel speciationModel = new BirthDeathModel(b, d, null, null, BirthDeathModel.TreeType.TIMESONLY,
                Units.Type.YEARS);
        Likelihood likelihood = new SpeciationLikelihood(tree, speciationModel, "yule.like");

        assertEquals(likelihood.getLogLikelihood(), logL, MachineAccuracy.EPSILON);

    }
 
开发者ID:armanbilge,项目名称:B3,代码行数:13,代码来源:YuleLikelihoodTest.java


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