Package com.nr.ran

Examples of com.nr.ran.Ran


    System.out.println("Testing Poly_interp");
    for (i=0;i<N;i++) {
      x[i]=(double)(i)/(N-1);
      y[i]=1.0+x[i]*(1.0+x[i]*(1.0+x[i]*(1.0+x[i])));
    }
    Ran myran = new Ran(17);
    Poly_interp z = new Poly_interp(x,y,3);
    for (i=0;i<N;i++) {
      xx[i]=myran.doub();
      yy[i]=z.interp(xx[i]);    // interpolated values
      dyy[i]=z.dy;        // Estimated errors
      zz[i]=1.0+xx[i]*(1.0+xx[i]*(1.0+xx[i]*(1.0+xx[i])))// Actual Values
    }
    System.out.printf("     Poly_interp: Max. estimated error: %f\n", maxel(dyy));
View Full Code Here


   

    // Test Shep_interp
    System.out.println("Testing Shep_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

    }

    // inverse cdf agrees with cdf
    n=2.0;m=0.5;s=1.5;
    Studenttdist normc = new Studenttdist(n,m,s);
    Ran myran = new Ran(17);
    sbeps=1.0e-13;
    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;
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Studenttdist: Inverse cdf does not accurately invert the cdf");
     
    }

    // Function aa() agrees with incomplete integral
    sbeps=1.e-7;
    n=2.0;m=0.0;s=1.0;
    func_Studenttdist dist3 = new func_Studenttdist(n,m,s);
    Studenttdist normaa = new Studenttdist(n,m,s);
    localflag=false;
    for (i=0;i<10;i++) {
      u = 0.5*i;
      Midpnt qq1 = new Midpnt(dist3,-u,u);
      c[i]=qromo(qq1);
      d[i]=normaa.aa(u);
//      System.out.printf(setprecision(6) << c[i] << " %f\n", d[i] << " %f\n", c[i]-d[i]);
      localflag = localflag || abs(c[i]-d[i]) > sbeps;
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Studenttdist: aa() does not agree with result of direct quadrature");
     
    }

    // inverse invaa() agrees with aa()
    n=2.0;m=0.5;s=1.5;
    Studenttdist normaa2 = new Studenttdist(n,m,s);
    sbeps=1.0e-13;
    localflag=false;
    for (i=0;i<1000;i++) {
      u=m+3.0*s*myran.doub();
      a=normaa2.aa(u);
      b=normaa2.invaa(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

    System.out.println("Testing Rat_interp");
    for (i=0;i<N;i++) {
      x[i]=(double)(i)/(N-1);
      y[i]=(1.0-x[i]*(0.5-0.1*x[i]))/(1.0+(x[i]-2.0)*(x[i]-2.0));
    }
    Ran myran = new Ran(17);
    Rational_interp z = new Rational_interp(x,y,3);
    for (i=0;i<N;i++) {
      xx[i]=myran.doub();
      yy[i]=z.interp(xx[i]);      // interpolated values
      dyy[i]=z.dy;          // Estimated error
      zz[i]=(1.0-xx[i]*(0.5-0.1*xx[i]))/(1.0+(xx[i]-2.0)*(xx[i]-2.0)); // Actual values
    }
    System.out.printf("     Rat_interp: Max. estimated error: %f\n", maxel(dyy));
View Full Code Here

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

    // Create two disjoint sets of points
    Ran myran=new Ran(17);
    for (i=0;i<M/2;i++) {
      y[i]=1.0;
      a=myran.doub();
      b=2.0*myran.doub()-1.0;
      data[i][0]=1.0+(a-b);
      data[i][1]=1.0+(a+b);
    }

    for (i=M/2;i<M;i++) {
      y[i]=-1.0;
      a=myran.doub();
      b=2.0*myran.doub()-1.0;
      data[i][0]=-1.0-(a-b);
      data[i][1]=-1.0-(a+b);
    }
   
    // Linear kernel
View Full Code Here

   

    // Test fourn
    System.out.println("Testing fourn");
    Ran myran=new Ran(17);
    for (i=0;i<nn.length;i++) N *= nn[i];
    N *= 2;
    double[] data1=new double[N],data2=new double[N];
    // Round-trip test for random numbers
    for (i=0;i<N;i++) data1[i] = myran.doub();
    for (i=0;i<N;i++) data2[i] = (2.0/N)*data1[i];
    fourn(data2,nn,1);
    fourn(data2,nn,-1);
//    System.out.printf(maxel(vecsub(data1,data2)));
    localflag = localflag || maxel(vecsub(data1,data2)) > sbeps;
View Full Code Here

   

    // Test sort
    System.out.println("Testing sort");
    localflag=false;
    Ran myran = new Ran(17);
    for (i=0;i<N;i++) x[i]=myran.doub();
    Sorter.sort(x);
    for (i=0;i<N-1;i++) localflag = localflag || (x[i] > x[i+1]);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** sort: Sorted values are not correctly ordered");
View Full Code Here

   

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

    Ran myran=new Ran(17);
    Point[] points=new Point[NPTS];
    for (i=0;i<NPTS;i++)
      points[i]=new Point(myran.doub(),myran.doub());

    Voronoi.Voredge v = new Voronoi.Voredge(points[0],points[1],2);

    localflag = dist(v.p[0],points[0]) > sbeps;
    globalflag = globalflag || localflag;
View Full Code Here

   

    // Test piksr2
    System.out.println("Testing piksr2");
    Ran myran = new Ran(17);
    for (i=0;i<N;i++) {
      x[i]=myran.doub();
      y[i]=1.0-x[i];    // y is in opposite order of x
    }
    Sorter.piksr2(x,y);
    for (i=0;i<N-1;i++) localflag = localflag || (x[i] > x[i+1]);
    globalflag = globalflag || localflag;
View Full Code Here

   

    // Test sort2
    System.out.println("Testing sort2");
    Ran myran = new Ran(17);
    for (i=0;i<N;i++) {
      x[i]=myran.doub();
      y[i]=1.0-x[i];    // y is in opposite order of x
    }
    Sorter.sort2(x,y);
    for (i=0;i<N-1;i++) localflag = localflag || (x[i] > x[i+1]);
    globalflag = globalflag || localflag;
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.