Package com.nr.ran

Examples of com.nr.ran.Ran


   

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

    Ran myran=new Ran(17);
    for (j=0;j<NPTS;j++) data1[j]=myran.doub();
    kstwo(data1,data1,d1,prob1);
//    System.out.printf(setw(17) << d1 << setw(17) << prob1);
    localflag = localflag || (d1.val != 0.0);
    globalflag = globalflag || localflag;
    if (localflag) {
View Full Code Here


    Quadvl quadvl = new Quadvl();

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

    Ran myran=new Ran(17);
    for (i=0;i<NTRIAL;i++) {
      for (j=1;j<NPT;j++)
        x[j]=2.0*myran.doub()-1.0;
      for (j=1;j<NPT;j++)
        y[j]=2.0*myran.doub()-1.0;
      ks2d1s(x,y,quadvl,dd,pprob);
      d[i]=dd.val;
      prob[i]=pprob.val;
    }
    // Note: It was observed that qualitatively if the probabilities
    // are ordered,and then g[i]=p[i]*(2=p[i]), the result is approximately
    // distributed uniformly from 0.0 to 1.0
    Sorter.sort2(d,prob);
    rms=0.0;
    for (i=0;i<NTRIAL;i++) {
      f[i]=(double)(NTRIAL-i)/NTRIAL;
      g[i]=prob[i]*(2.0-prob[i]);
      rms += SQR(f[i]-g[i]);
//      System.out.printf(prob[i] << " %f\n", f[i] << " %f\n", g[i]);
//      System.out.printf(i << " %f\n", d[i] << " %f\n", prob[i]);
    }
    rms=sqrt(rms/NTRIAL);
    System.out.printf("rms: %f\n", rms);

    sbeps = 0.08;
    localflag = rms > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** ks2d1s: Result deviated from a qualitative model");
     
    }

    // Distort the distribution
    factor=0.2;
    ave=0.0;
    for (i=0;i<NTRIAL;i++) {
      for (j=1;j<NPT;j++) {
        u=myran.doub();
        u=u*((1-factor)+u*factor);
        x[j]=2.0*u-1.0;
      }
      for (j=1;j<NPT;j++) {
        u=myran.doub();
        u=u*((1-factor)+u*factor);
        y[j]=2.0*myran.doub()-1.0;
      }
      ks2d1s(x,y,quadvl,dd,pprob);
      ave += pprob.val;
    }
    ave /= NTRIAL;
View Full Code Here

   

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

    Ran myran = new Ran(16);
    for (i=0;i<NTRIES;i++) {
      x=2.0*myran.doub()-1.0;
      y=2.0*myran.doub()-1.0;
      Quadvl quadvl = new Quadvl();
      quadvl.quadvl(x,y,faW,fbW,fcW,fdW);
      fa=faW.val;fb=fbW.val;fc=fcW.val;fd=fdW.val;

      sbeps=1.e-15;
View Full Code Here

   

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

    Ran myran=new Ran(17);
    j=0;
    for (i=0;i<N/4;i++) {
      xx[j]=myran.doub();   // Put a point in each x-y quadrant
      yy[j++]=myran.doub();
      xx[j]=-myran.doub();
      yy[j++]=myran.doub();
      xx[j]=-myran.doub();
      yy[j++]=-myran.doub();
      xx[j]=myran.doub();
      yy[j++]=-myran.doub();
    }  
    quadct(0.0,0.0,xx,yy,fa,fb,fc,fd);
//    System.out.printf(fa << " %f\n", fb << " %f\n", fc << " %f\n", fd);
    localflag = (fa.val != 0.25) || (fb.val != 0.25) || (fc.val != 0.25) || (fd.val != 0.25);
    globalflag = globalflag || localflag;
View Full Code Here

   

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

    Ran myran =new Ran(17);
    func1_ksone func1_ksone = new func1_ksone();
    for (j=0;j<NPTS;j++) data1[j]=myran.doub();
    ksone(data1,func1_ksone,d1,prob1);
//    System.out.printf(setw(17) << d1 << setw(17) << prob1);
    localflag = localflag || (prob1.val < 0.2);
    globalflag = globalflag || localflag;
    if (localflag) {
View Full Code Here

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

    // Test values against those of rj(x,y,z);
    Ran myran = new Ran(17);
   
    for (i=0;i<N;i++) {
      x=10.0*myran.doub();
      y=10.0*myran.doub();
      z=10.0*myran.doub();

      f1[i]=rd(x,y,z);
      f2[i]=rj(x,y,z,z);
    }
    System.out.printf("rd: Maximum discrepancy = %f\n", maxel(vecsub(f1,f2)));
View Full Code Here

    }

    // inverse cdf agrees with cdf
    df=100.;
    Chisqdist normc=new Chisqdist(df);
    Ran myran = new Ran(17);
    sbeps=2.0e-12; // XXX 1.0e-12 not pass.
    localflag=false;
    for (i=0;i<1000;i++) {
      chisq=df-3.0*sqrt(df)+6.0*sqrt(df)*myran.doub();
      a=normc.cdf(chisq);
      b=normc.invcdf(a);
      if (abs(chisq-b) > sbeps) {
        System.out.printf("%f %f  %f\n",chisq, b ,abs(chisq-b));
      }
View Full Code Here

    }

    // inverse cdf agrees with cdf
    m=0.5; s=1.5;
    Lognormaldist normc = new Lognormaldist(m,s);
    Ran myran = new Ran(17);
    sbeps=5.0e-14;
    localflag=false;
    for (i=0;i<1000;i++) {
      u=3.0*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));
//      }
View Full Code Here

    }

    // inverse cdf agrees with cdf
    m=0.5;s=1.5;
    Cauchydist normc=new Cauchydist(m,s);
    Ran myran = new Ran(17);
    sbeps=1.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);
//      System.out.printf(setprecision(15) << u << " %f\n", b << " %f\n", abs(u-b));
      localflag = localflag || abs(u-b) > sbeps;
    }
View Full Code Here

   

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

    Ran myran = new Ran(17);
   
    for (i=0;i<N;i++) {
      x=10.0*myran.doub();
      y=10.0*myran.doub();
      z=10.0*myran.doub();

      f1[i]=rf(x,y,z);
      lambda=sqrt(x*y)+sqrt(x*z)+sqrt(y*z);
      f2[i]=2.0*rf(x+lambda,y+lambda,z+lambda);
      f3[i]=rf((x+lambda)/4.0,(y+lambda)/4.0,(z+lambda)/4.0);
//      System.out.printf(f1[i] << " %f\n", f3[i]);
    }
    System.out.printf("rf: Rule 1, maximum discrepancy = %f\n", maxel(vecsub(f1,f2)));
    System.out.printf("rf: Rule 2, maximum discrepancy = %f\n", maxel(vecsub(f1,f3)));

    sbeps=1.e-14;
    localflag = maxel(vecsub(f1,f2)) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** rf: Function rf(x,y,z) does not follow duplication theorem rule 1");
     
    }

    sbeps=1.e-14;
    localflag = maxel(vecsub(f1,f3)) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** rf: Function rf(x,y,z) does not follow duplication theorem rule 2");
     
    }

    // Test rf(x,x,x) = 1/sqrt(x)
    for (i=0;i<N;i++) {
      x=myran.doub();
      f1[i]=rf(x,x,x);
      f2[i]=1.0/sqrt(x);
    }

    System.out.printf("rf: Rule 3: maximum discrepancy = %f\n", maxel(vecsub(f1,f2)));
    sbeps=1.e-14;
    localflag = maxel(vecsub(f1,f2)) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** rf: Function rf(x,x,x) is not equal to 1/sqrt(x)");
     
    }

    // Symmetry test
    for (i=0;i<N;i++) {
      x=10.0*myran.doub();
      y=10.0*myran.doub();
      z=10.0*myran.doub();

      f1[i]=rf(x,y,z);
      f2[i]=rf(y,x,z);
      f3[i]=rf(x,z,y);
    }
View Full Code Here

TOP

Related Classes of com.nr.ran.Ran

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.