Package com.nr.sf

Examples of com.nr.sf.Betadist


    // Test Betadist
    System.out.println("Testing Betadist");

    // Test special cases
    alpha=1.0; beta=1.0; u=0.5;
    Betadist norm1 = new Betadist(alpha,beta);
    localflag = abs(norm1.p(u)-1.0) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Betadist: Special case #1 failed");
     
    }

    alpha=1.0; beta=2.0; u=0.5;
    Betadist norm2=new Betadist(alpha,beta);
    localflag = abs(norm2.p(u)-1.0) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Betadist: Special case #2 failed");
     
    }

    alpha=2.0; beta=1.0; u=0.5;
    Betadist norm3=new Betadist(alpha,beta);
    localflag = abs(norm3.p(u)-1.0) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Betadist: Special case #3 failed");
     
    }

    alpha=2.0; beta=2.0; u=0.5;
    Betadist norm4=new Betadist(alpha,beta);
    localflag = abs(norm4.p(u)-3.0/2.0) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Betadist: Special case #4 failed");
     
    }

    alpha=2.0; beta=2.0; u=1.0/3.0;
    Betadist norm5=new Betadist(alpha,beta);
    localflag = abs(norm5.p(u)-4.0/3.0) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Betadist: Special case #5 failed");
     
    }

    // integral of distribution is one
    sbeps=2.e-6;
    alpha=2.5; beta=1.5;
    func_Betadist dist = new func_Betadist(alpha,beta);
    Midpnt q2 = new Midpnt(dist,0.0,1.0);
    integral=qromo(q2);
    localflag = abs(1.0-integral) > sbeps;
//    System.out.printf(setprecision(15) << 1.0-integral);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Betadist: Distribution is not normalized to 1.0");
     
    }

    // cdf agrees with incomplete integral
    sbeps=5.e-6;
    alpha=2.5; beta=1.5;
    func_Betadist dist2 = new func_Betadist(alpha,beta);
    Betadist normcdf =new Betadist(alpha,beta);
    localflag=false;
    for (i=0;i<N;i++) {
      Midpnt qq2 = new Midpnt(dist2,0.0,x[i]);
      integral=qromo(qq2);
      c[i]=integral;
      d[i]=normcdf.cdf(x[i]);
//      System.out.printf(c[i]-d[i]);
      localflag = localflag || abs(c[i]-d[i]) > sbeps;
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Betadist: cdf does not agree with result of quadrature");
     
    }

    // inverse cdf agrees with cdf
    alpha=2.5; beta=1.5;
    Betadist normc = new Betadist(alpha,beta);
    Ran myran = new Ran(17);
    sbeps=5.0e-14;
    localflag=false;
    for (i=0;i<1000;i++) {
      u=myran.doub();
      a=normc.cdf(u);
      b=normc.invcdf(a);
//      if (abs(u-b) > sbeps) {
//        System.out.printf(setprecision(15) << u << " %f\n", b << " %f\n", abs(u-b));
//      }
      localflag = localflag || abs(u-b) > sbeps;
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Betadist: Inverse cdf does not accurately invert the cdf");
     
    }
     
    // Fingerprint test
    alpha=2.5; beta=1.5;
    Betadist normf = new Betadist(alpha,beta);
    for (i=0;i<N;i++) {
      p[i]=normf.p(x[i]);
//      System.out.printf(setprecision(17) << p[i] << " %f\n", pexp[i]);
    }
//    System.out.println("Betadist: Maximum discrepancy = %f\n", maxel(vecsub(p,pexp)));
    localflag = maxel(vecsub(p,pexp)) > sbeps;
    globalflag = globalflag || localflag;
View Full Code Here


    double alpha,beta;
    Betadist normi;
    func_Betadist(double aalpha, double bbeta) {
      alpha = aalpha;
      beta = bbeta;
      normi = new Betadist(alpha,beta);
    }
View Full Code Here

TOP

Related Classes of com.nr.sf.Betadist

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.