當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。