Package com.nr.sf

Examples of com.nr.sf.Logisticdist


    pio4sqrt3=pi/4.0/sqrt(3.0);

    // Test special cases
    m=0; s=1; u=0;
    Logisticdist norm1 = new Logisticdist(m,s);
    localflag = abs(norm1.p(u)-pio4sqrt3/s) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Logisticdist: Special case #1 failed");
     
    }

    m=1; s=1; u=m;
    Logisticdist norm2 = new Logisticdist(m,s);
    localflag = abs(norm2.p(u)-pio4sqrt3) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Logisticdist: Special case #2 failed");
     
    }

    m=1; s=1; u=0;
    Logisticdist norm3 = new Logisticdist(m,s);
//    System.out.printf(abs(norm3.p(u) - pio4sqrt3*SQR(1.0/cosh(2.0*pio4sqrt3))));
    localflag = abs(norm3.p(u)-pio4sqrt3*SQR(1.0/cosh(2.0*pio4sqrt3))) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Logisticdist: Special case #3 failed");
     
    }

    m=1; s=2; u=1;
    Logisticdist norm4 = new Logisticdist(m,s);
    localflag = abs(norm4.p(u)-pio4sqrt3/s) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Logisticdist: Special case #4 failed");
     
    }

    m=1; s=2; u=0;
    Logisticdist norm5 = new Logisticdist(m,s);
    localflag = abs(norm5.p(u)-pio4sqrt3/s/SQR(cosh(pio4sqrt3))) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Logisticdist: Special case #5 failed");
     
    }

    // integral of distribution is one
    sbeps=1.e-8;
    m=1.0;s=2.0;
    func_Logisticdist dist = new func_Logisticdist(m,s);
    Midinf q1 = new Midinf(dist,-1.0e99,-1.0);
    Midpnt q2 = new Midpnt(dist,-1.0,1.0);
    Midinf q3 = new Midinf(dist,1.0,1.0e99);
    integral=qromo(q1)+qromo(q2)+qromo(q3);
    localflag = abs(1.0-integral) > sbeps;
//    System.out.printf(setprecision(15) << 1.0-integral);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Logisticdist: Distribution is not normalized to 1.0");
     
    }

    // cdf agrees with incomplete integral
    sbeps=1.e-7;
    m=0.5;s=1.5;
    func_Logisticdist dist2 = new func_Logisticdist(m,s);
    Logisticdist normcdf = new Logisticdist(m,s);
    localflag=false;
    for (i=0;i<N;i++) {
      if (x[i] < 0.0) {
        q1 = new Midinf(dist2,-1.e99,x[i]);
        integral=qromo(q1);
      } else {
        q1 = new Midinf(dist2,-1.e99,-1.0);
        q2 = new Midpnt(dist2,-1.0,x[i]);
        integral=qromo(q1)+qromo(q2);
      }
      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("*** Logisticdist: cdf does not agree with result of quadrature");
     
    }

    // inverse cdf agrees with cdf
    m=0.5;s=1.5;
    Logisticdist normc = new Logisticdist(m,s);
    Ran myran = new Ran(17);
    sbeps=5.0e-14;
    localflag=false;
    for (i=0;i<1000;i++) {
      u=m-3.0*s+6.0*s*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("*** Logisticdist: Inverse cdf does not accurately invert the cdf");
     
    }
     
    // Fingerprint test
    m=0.5;s=1.5;
    Logisticdist normf = new Logisticdist(m,s);
    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("Logisticdist: Maximum discrepancy = %f\n", maxel(vecsub(p,pexp)));
    localflag = maxel(vecsub(p,pexp)) > sbeps;
    globalflag = globalflag || localflag;
View Full Code Here


    double m,s;
    Logisticdist normi;
    func_Logisticdist(double mm, double ss) {
      m = mm;
      s = ss;
      normi = new Logisticdist(m,s);
    }
View Full Code Here

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

    // Check statistics
    Logisticdist expect = new Logisticdist(mu,sig);
    xl=mu-range/2.0;
    xu=mu+range/2.0;
    binsize=range/M;
    for (i=0;i<M;i++) {
      x[i]=xl+binsize*i;
      ebins[i]=N*binsize*expect.p(x[i]+0.5*binsize);
      bins[i]=0;
    }
    for (i=0;i<N;i++) {
      nbin=(int)(floor((0.5*range+myran.dev())/binsize));
      if ((nbin >= 0) && (nbin < M)) bins[nbin] += 1;
View Full Code Here

TOP

Related Classes of com.nr.sf.Logisticdist

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.