Package com.nr.sf

Examples of com.nr.sf.Poissondist


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

    // Test special cases
    lambda=1.0; ju=0;
    Poissondist norm1 = new Poissondist(lambda);
    localflag = abs(norm1.p(ju)-exp(-1.0)) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Poissondist: Special case #1 failed");
     
    }

    lambda=1.0; ju=1;
    Poissondist norm2 = new Poissondist(lambda);
    localflag = abs(norm2.p(ju)-exp(-1.0)) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Poissondist: Special case #2 failed");
     
    }

    lambda=2.0; ju=0;
    Poissondist norm3 = new Poissondist(lambda);
    localflag = abs(norm3.p(ju)-exp(-2.0)) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Poissondist: Special case #3 failed");
     
    }

    lambda=2.0; ju=1;
    Poissondist norm4 = new Poissondist(lambda);
    localflag = abs(norm4.p(ju)-2.0*exp(-2.0)) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Poissondist: Special case #4 failed");
     
    }

    lambda=1.0; ju=2;
    Poissondist norm5 = new Poissondist(lambda);
    localflag = abs(norm5.p(ju)-0.5*exp(-1.0)) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Poissondist: Special case #5 failed");
     
    }

    lambda=2.0; ju=2;
    Poissondist norm6 = new Poissondist(lambda);
    localflag = abs(norm6.p(ju)-2.0*exp(-2.0)) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Poissondist: Special case #6 failed");
     
    }

    // Sum over k is one
    sbeps=1.e-15;
    lambda=5.0;
    sum=0.0;
    Poissondist dist = new Poissondist(lambda);
    for (i=0;i<50;i++)
      sum += dist.p(i);
    localflag = abs(1.0-sum) > sbeps;
//    System.out.printf(setprecision(15) << 1.0-sum);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Poissondist: Distribution is not normalized to 1.0");
     
    }

    // cdf agrees with truncated sum
    sbeps=1.e-15;
    lambda=5.0;
    Poissondist dist2 = new Poissondist(lambda);
    localflag=false;
    sum=0.0;
    for (i=0;i<20;i++) {
      sum += dist2.p(i);
      c[i]=sum;
      d[i]=dist2.cdf(i+1);
//      System.out.printf(c[i]-d[i]);
      localflag = localflag || abs(c[i]-d[i]) > sbeps;
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Poissondist: cdf does not agree with result of quadrature");
     
    }

    // inverse cdf agrees with cdf
    lambda=10.0;
    Poissondist normc = new Poissondist(lambda);
    sbeps=1.0e-12;
    localflag=false;
    for (i=1;i<20;i++) {
      a=normc.cdf(i);
      b=normc.invcdf(a);
      localflag = localflag || (i-b != 0) && (i-b-1 != 0) ;
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Poissondist: Inverse cdf does not accurately invert the cdf");
     
    }

    // Fingerprint test
    lambda=10.0;
    Poissondist normf = new Poissondist(lambda);
    for (i=0;i<N;i++) {
      p[i]=normf.p(k[i]);
//      System.out.printf(setprecision(17) << p[i] << " %f\n", pexp[i]);
    }
//    System.out.println("Poissondist: Maximum discrepancy = %f\n", maxel(vecsub(p,pexp)));
    localflag = maxel(vecsub(p,pexp)) > sbeps;
    globalflag = globalflag || localflag;
View Full Code Here


      fail("*** Poissondev: dev() does not match fingerprint");
     
    }

    // Check statistics
    Poissondist expect = new Poissondist(lambda);
    for (i=0;i<M;i++) {
      ebins[i]=N*expect.p(i);
      bins[i]=0;
    }
    for (i=0;i<N;i++) {
      nbin=myran.dev();
      if ((nbin >= 0) && (nbin < M)) bins[nbin] += 1;
View Full Code Here

TOP

Related Classes of com.nr.sf.Poissondist

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.