Package com.nr.ran

Examples of com.nr.ran.Ran


   

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

    Ran myran = new Ran(17);
   
    // Test rj(x,x,x,x) = 1/x^(3/2)
    for (i=0;i<N;i++) {
      x=myran.doub();
      f1[i]=rj(x,x,x,x);
      f2[i]=1.0/pow(x,3.0/2.0);
    }

    System.out.printf("rj: Maximum discrepancy = %f\n", maxel(vecsub(f1,f2)));
    sbeps=2.e-11// XXX 1.e-12 not pass
    localflag = maxel(vecsub(f1,f2)) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** rj: Function rj(x,x,x,x) is not equal to 1/x^(3/2)");
     
    }

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

      f1[i]=rj(x,y,z,p);
      f2[i]=rj(y,x,z,p);
      f3[i]=rj(x,z,y,p);
    }

    // Symmetry of x and y
    System.out.printf("rj: maximum discrepance with swap of x,y = %f\n", maxel(vecsub(f1,f2)));
    sbeps=1.e-14;
    localflag = maxel(vecsub(f1,f2)) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** rj: Function rj(x,y,z,p) is not equal to rj(y,x,z,p)");
     
    }

    // Symmetry of y and z
    System.out.printf("rj: maximum discrepance with swap of y,z = %f\n", maxel(vecsub(f1,f3)));

    sbeps=1.e-14;
    localflag = maxel(vecsub(f1,f3)) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** rj: Function rj(x,y,z,p) is not equal to rj(x,z,y,p)");
     
    }

    // Test symmetry with respect to p
    for (i=0;i<N;i++) {
      x=myran.doub();
      z=myran.doub();
      p=myran.doub();

      f1[i]=rj(x,x,z,p);
      f2[i]=rj(p,p,z,x);
    }

    // Symmetry of x,y and p
    System.out.printf("rj: maximum discrepance with x,y,p symmetry = %f\n", maxel(vecsub(f1,f2)));

    sbeps=1.e-12;
    localflag = maxel(vecsub(f1,f2)) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** rj: Function rj(x,x,z,p) is not equal to rj(p,p,z,x)");
     
    }

    // Test symmetry with respect to p
    for (i=0;i<N;i++) {
      x=myran.doub();
      y=myran.doub();
      p=myran.doub();

      f1[i]=rj(x,y,y,p);
      f2[i]=rj(x,p,p,y);
    }

View Full Code Here


    for (i=0;i<N;i++) {
      x[i]=(double)(i);
      y[i]=2.0*(double)(i);
    }
    Linear_interp z = new Linear_interp(x,y);
    Ran myran = new Ran(17);
    for (i=0;i<N;i++) {
      xx[i]=(N-1)*myran.doub();
      yy[i]=z.interp(xx[i]);    // interpolated values
      zz[i]=2.0*xx[i];      // Correct values
    }
    localflag = maxel(vecsub(zz,yy)) > sbeps;
    globalflag = globalflag || localflag;
View Full Code Here

    for (i=0;i<N;i++) {
      x[i]=2.0*i/(N-1);
      y[i]=func_BaryRat(x[i]);
    }
    ymax=maxel(y);
    Ran myran = new Ran(17);
    for (j=0;j<M;j++) {
      BaryRat_interp z = new BaryRat_interp(x,y,j);
      for (i=0;i<N;i++) {
        xx[i]=2.0*myran.doub();
        yy[i]=z.interp(xx[i]);      // interpolated values
        zz[i]=func_BaryRat(xx[i]);    // Actual values
      }
      dy=maxel(vecsub(zz,yy));
      System.out.printf("     BaryRat_interp: Order: %d  Max. error:    %f\n", j, dy);
View Full Code Here

      y[i]=sin(x[i]);
    }
    yp1=1.0;
    ypn=-1.0;
    Spline_interp z = new Spline_interp(x,y,yp1,ypn);
    Ran myran = new Ran(17);
    for(i=0;i<N;i++) {
      xx[i]=pi*myran.doub();
      yy[i]=z.interp(xx[i]);
      zz[i]=sin(xx[i]);
    }
    System.out.printf("     Spline_interp: Max. actual error:    %f\n", maxel(vecsub(zz,yy)));
    sbeps=1.e-5*maxel(y);
 
View Full Code Here

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

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

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

   

    // Test Laplace_interp
    System.out.println("Laplace_interp");
    Ran myran = new Ran(17);
    for (i=0;i<N;i++)
      for (j=0;j<M;j++)
        actual[i][j]=cos((double)(i)/20.0)*cos((double)(j)/20.0);
    double[][] mat = buildMatrix(actual);
    for (i=0;i<NBAD;i++) {  // insert "missing" data
      p=myran.int32p()%N;
      q=myran.int32p()%M;
      mat[p][q]=1.e99;
    }
    System.out.printf("     Initial discrepancy: %g\n", maxel(matsub(actual,mat)));
    Laplace_interp mylaplace = new Laplace_interp(mat);
    mylaplace.solve();
View Full Code Here

      fail("*** KSdist: Pks and Qks do not add to 1.0 in all cases");
     
    }

    // inverse of Pks agrees with Pks
    Ran myran = new Ran(17);
    localflag=false;
    sbeps=6.e-10// XXX 5.e-10 not pass
    for (i=0;i<10;i++) {
      z=0.3+3.0*myran.doub();
      a=norm.pks(z);
      b=norm.invpks(a);
//      if (abs(z-b) > sbeps) {
//        System.out.printf(setprecision(15) << z << " %f\n", b << " %f\n", abs(z-b));
//      }
      localflag = localflag || abs(z-b) > sbeps;
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** KSdist: invPks does not accurately invert the Pks");
     
    }

    // inverse of Qks agrees with Qks
    localflag=false;
    sbeps=5.e-10;
    for (i=0;i<1000;i++) {
      z=0.3+3.0*myran.doub();
      a=norm.qks(z);
      b=norm.invqks(a);
//      if (abs(z-b) > sbeps) {
//        System.out.printf(setprecision(15) << z << " %f\n", b << " %f\n", abs(z-b));
//      }
View Full Code Here

   

    // Test Krig (and Powvargram)
    System.out.println("Testing Krig (and Powvargram)");
    Ran myran = new Ran(17);
    double[][] pt = new double[M][2];
    for (i=0;i<M;i++) {
      pt[i][0]=(double)(N)*myran.doub();
      pt[i][1]=(double)(N)*myran.doub();
      actual[i]=cos(pt[i][0]/20.0)*cos(pt[i][1]/20.0);
    }
    for (i=0;i<N;i++) {
      for (j=0;j<N;j++) {
        k=N*i+j;
 
View Full Code Here

    }

    // inverse cdf agrees with cdf
    alpha=2.5; beta=1.5;
    Gammadist normc = new Gammadist(alpha,beta);
    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

    boolean localflag, globalflag=false;

   

    // Test RBF_interp
    Ran myran = new Ran(17);
    double[][] pt = new double[M][2];
    for (i=0;i<M;i++) {
      pt[i][0]=(double)(N)*myran.doub();
      pt[i][1]=(double)(N)*myran.doub();
      actual[i]=cos(pt[i][0]/20.0)*cos(pt[i][1]/20.0);
    }
    for (i=0;i<N;i++) {
      for (j=0;j<N;j++) {
        k=N*i+j;
 
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.