Package com.nr.ran

Examples of com.nr.ran.Ran


    string3=new char[N2+1];
    string1[N1]='\0';
    string2[N2]='\0';
    string3[N2]='\0';

    Ran myran = new Ran(17);
    for (i=0;i<N1;i++)
      string1[i]=protein[3];
    for (i=0;i<N2;i++)
      string2[i]=protein[myran.int32p()%3];

//    System.out.printf(string1);
//    System.out.printf(string2 << endl);

    // Bury a needle in the haystack
View Full Code Here


      fail("*** Hashtable: iset() should use hash of penultimate erased key");
     
    }

    // Test multiple iset() on same keys. They should return same index.
    Ran myran = new Ran(17);
    int j;
    for (i=0;i<100;i++) {
      j=myran.int32p()%N;
      hash.iset(chart[j]);
    }

    // N keys should always use only the first N indices
    int[] expect =buildVector(N,1);
    int[] check = buildVector(N,0);
    for (i=0;i<N;i++) {
      j=hash.iget(chart[i]);
//      System.out.printf(j << " ";
      check[j]=1;
      hash.ierase(chart[i])// Clear away the hashes
    }
//    System.out.printf(endl;
    localflag = maxel(vecsub(check,expect)) != 0;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Hashtable: N stored keys should have used the first N indices");
     
    }

    // Test of ireserve()
    for (i=0;i<N;i++) {     // Reserve the first N indices
      j=hash.ireserve();
//      System.out.printf(j << " ";
    }
//    System.out.printf(endl;

    for (i=0;i<100;i++) {   // Now store N keys again
      j=myran.int32p()%N;
      hash.iset(chart[j]);
    }

    int[] expect2 = buildVector(2*N,1);
    for (i=0;i<N;i++) expect2[i]=0;
    int[] check2 = buildVector(2*N,0);
    for (i=0;i<N;i++) {
      j=hash.iget(chart[i]);
//      System.out.printf(j << " ";
      check2[j]=1;
      hash.ierase(chart[i]);
    }
//    System.out.printf(endl;
    localflag = maxel(vecsub(check2,expect2)) != 0;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Hashtable: N stored keys should have used the second N indices");
     
    }

    // Test of irelinquish()
    j=0;
    for (i=0;i<2*N;i++)
      j += hash.irelinquish(i);       // final value of j should be (N/2)(N-3)
    localflag = (j != (N/2)*(N-3));       // for N=10, j=5*7=35;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Hashtable: Sum of return values of irelinquish() was not correct");
     
    }

    // Now run original test on fully relinquished table
    for (i=0;i<100;i++) {
      j=myran.int32p()%N;
      hash.iset(chart[j]);
    }

    for (i=0;i<2*N;i++) {
      check2[i]=0;
View Full Code Here

   

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

    Ran myran=new Ran(17);
    for (i=0;i<N;i++) {
      x[i]=myran.doub();
      y[i]=myran.doub();
      iorder[i]=i;
    }
    Anneal anl=new Anneal();

    // Initial length
View Full Code Here

    System.out.println("Testing Ran");
    average=(double)(N)/(M);
    double[] ebins = buildVector(M,average);

    // Check fingerprint of int32()
    Ran myran1 = new Ran(17);
    localflag=false;
    for (i=0;i<10;i++)
      localflag=localflag || (myran1.int32() != fingerprint1[i]);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Ran: int32() does not match fingerprint");
     
    }

    // Check statistics
    for (i=0;i<N;i++) bins[myran1.int32p() % M] += 1;
    chsone(bins,ebins,df,chisq,prob);
    System.out.printf("     chisq,int32(): %f  prob: %f\n", chisq.val, prob.val);
    localflag = (prob.val < 0.05);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Ran: int32() does not give distribution with correct variance");
     
    }

    // Check fingerprint of int64()
    Ran myran2 = new Ran(17);
    localflag=false;
    for (i=0;i<10;i++)
      localflag=localflag || (myran2.int64() != fingerprint2[i]);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Ran: int64() does not match fingerprint");
     
    }

    // Check statistics
    for (i=0;i<M;i++) bins[i]=0;
    for (i=0;i<N;i++) bins[(int)(myran2.int64p()%M)] += 1;
    chsone(bins,ebins,df,chisq,prob);
    System.out.printf("     chisq,int64(): %f  prob: %f\n",chisq.val, prob.val);
    localflag = (prob.val < 0.05);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Ran: int64() does not give distribution with correct variance");
     
    }

    // Check fingerprint of doub()
    Ran myran3 = new Ran(17);
    localflag=false;
    for (i=0;i<10;i++) {
      double r = myran3.doub();
      localflag=localflag || abs(r-fingerprint3[i]) > sbeps;
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Ran: doub() does not match fingerprint");
    }

    // Check statistics
    for (i=0;i<M;i++) bins[i]=0;
    for (i=0;i<N;i++) bins[(int)(floor(M*myran3.doub()))] += 1;
    chsone(bins,ebins,df,chisq,prob);
    System.out.printf("     chisq,doub(): %f\n  prob: %f\n", chisq.val, prob.val);
    localflag = (prob.val < 0.05);
    globalflag = globalflag || localflag;
    if (localflag) {
View Full Code Here

    // With 2 points in each box

    Boxnode boxes2[]=new Boxnode[NBOX];
    Point[] points2=new Point[2*NBOX];

    Ran myran=new Ran(17);
    for (i=0;i<NBOX;i++) {
      Point plo=new Point(myran.doub(),myran.doub());
      Point phi=new Point(myran.doub(),myran.doub());
      d1=phi.x[0]-plo.x[0];
      d2=phi.x[1]-plo.x[1];
      points2[2*i]=new Point(plo.x[0]+0.3*d1,plo.x[1]+0.3*d2);
      points2[2*i+1]=new Point(plo.x[0]+0.6*d1,plo.x[1]+0.6*d2);
      boxes2[i]=new Boxnode(plo,phi,(i-1)/2,2*i+1,2*i+2,2*i,2*i+1);
 
View Full Code Here

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

    Daub4 d4=new Daub4();
    Ran myran = new Ran(17);
    nn[0]=N;
    nn[1]=M;
    for (i=0;i<NTRY;i++) {
      for (j=0;j<M*N;j++) a[j]=0.0;
      jj=myran.int32p() % (M*N);
      a[jj]=1.0;
      wtn(a,nn,-1,d4);
//      for (j=0;j<N;j++) System.out.printf(setw(8) << a[j] << " ";
//      System.out.printf(endl;
      sum=0;
View Full Code Here

//    System.out.printf(t.pts[t.p[2]].x[1] << " ";
//    System.out.printf(endl;


    // Test contains() method
    Ran myran=new Ran(17);
    for (i=0;i<N;i++) {
      Point z=new Point(2.0*myran.doub(),6.0*myran.doub());
      // Points in the range (0-2.0,0-6.0).  Only the ones
      // with x coordinate between 0 and 1 are inside a triangle
      test=false;   // Test if point is inside a triangle
      for (j=0;j<NTRI;j++)
        test = test || (triels[j].contains(z) > 0.0);
View Full Code Here

   

    // Test four1
    System.out.println("Testing four1");
    Ran myran = new Ran(17);

    // Round-trip test for reals
    for (i=0;i<N;i++) {
      data1[2*i]=myran.doub();
      data1[2*i+1]=0.0;
    }
    double[] data2=buildVector(data1);
    for (i=0;i<2*N;i++) data2[i] /= N;
    four1(data2,1);
    four1(data2,-1);
    localflag = localflag || maxel(vecsub(data1,data2)) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** four1: Round-trip test for random real values failed");
     
    }

    // Round-trip test for imaginaries
    for (i=0;i<N;i++) {
      data1[2*i]=0.0;
      data1[2*i+1]=myran.doub();
    }
    for (i=0;i<2*N;i++) data2[i]=data1[i]/N;
    four1(data2,1);
    four1(data2,-1);
    localflag = localflag || maxel(vecsub(data1,data2)) > sbeps;
View Full Code Here

   

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

    Ran myran=new Ran(17);
    for (i=0;i<N;i++) {
      pvec[i].x[0]=myran.doub();
      pvec[i].x[1]=myran.doub();
    }
    Voronoi vor=new Voronoi(pvec);

    int m,nsite,jfirst;
    Voronoi.Voredge edge; // = new Voronoi.Voredge();
    Point end1=new Point(2),end2=new Point(2);
    Triel tt;
    double dotprodi,dotprodj;

    for (mm=0;mm<M;mm++) {
      // Choose a random segment
      m=myran.int32p() % vor.nseg;
      edge=vor.segs[m];
      end1=edge.p[0];
      end2=edge.p[1];
      nsite=edge.nearpt;
View Full Code Here

   

    // Test rlft3, interface 1 (2 Dimensions)
    System.out.println("Testing rlft3, interface1");
    Ran myran = new Ran(17);
    for (i=0;i<2;i++) N *= nn[i];
    double[][] data1=new double[nn[0]][nn[1]];
    double[][] data2=new double[nn[0]][nn[1]];
    double[] speq1=new double[2*nn[0]];
    double[] speq2=new double[2*nn[0]];
    // Round-trip test for random numbers
    for (i=0;i<nn[0];i++) {
      for (j=0;j<nn[1];j++) {
        data1[i][j] = myran.doub();
        data2[i][j] = (2.0/N)*data1[i][j];
      }
    }
    rlft3(data2,speq2,1);
    rlft3(data2,speq2,-1);
//    System.out.printf(maxel(matsub(data1,data2)));
    localflag = localflag || maxel(matsub(data1,data2)) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** rlft3, interface1: Round-trip test for random real values failed");
     
    }


    // Test delta-function in to sine-wave out, forward transform
    for (i=0;i<nn[0];i++)
      for (j=0;j<nn[1];j++) data1[i][j]=0.0;
    data1[5][7]=1.0;
    rlft3(data1,speq1,1);
    for (i=0;i<nn[0];i++) {
      for (j=0;j<nn[1]/2;j++) {
        Complex r1 = Complex.I.mul(2.0*pi*5.0*i/nn[0]);
        Complex r2 = Complex.I.mul(2.0*pi*7.0*j/nn[1]);
        Complex r = r1.exp().mul(r2.exp());         
        data2[i][2*j] = r.re();
        data2[i][2*j+1]= r.im();
        /*
        data2[i][2*j]= real(exp(2.0*pi*Complex(0.0,1.0)*5.0*double(i)/double(nn[0]))
          *exp(2.0*pi*Complex(0.0,1.0)*7.0*double(j)/double(nn[1])));
        data2[i][2*j+1]= imag(exp(2.0*pi*Complex(0.0,1.0)*5.0*double(i)/double(nn[0]))
          *exp(2.0*pi*Complex(0.0,1.0)*7.0*double(j)/double(nn[1])));
          */
      }
      Complex r1 = Complex.I.mul(2.0*pi*5.0*i/nn[0]);
      Complex r2 = Complex.I.mul(pi*7.0);
      Complex r = r1.exp().mul(r2.exp());
      speq2[2*i]=r.re();
      speq2[2*i+1]=r.im();
      /*
      speq2[2*i]=real(exp(2.0*pi*Complex(0.0,1.0)*5.0*double(i)/double(nn[0]))*exp(pi*Complex(0.0,1.0)*7.0));
      speq2[2*i+1]=imag(exp(2.0*pi*Complex(0.0,1.0)*5.0*double(i)/double(nn[0]))*exp(pi*Complex(0.0,1.0)*7.0));
      */
    }
//    System.out.printf(maxel(matsub(data1,data2)));
    localflag = localflag || maxel(matsub(data1,data2)) > sbeps;
//    System.out.printf(maxel(vecsub(speq1,speq2)));
    localflag = localflag || maxel(vecsub(speq1,speq2)) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** rlft3: Forward transform of a chosen delta function did not give expected result");
     
    }


    // Test rlft3, interface 2 (3 Dimensions)
    System.out.println("Testing rlft3, interface2");
    N=1;
    for (i=0;i<3;i++) N *= nn[i];
    double[][][] data3=new double[nn[0]][nn[1]][nn[2]];
    double[][][] data4=new double[nn[0]][nn[1]][nn[2]];
    double[][] speq3=new double[nn[0]][2*nn[1]];
    double[][] speq4=new double[nn[0]][2*nn[1]];
    // Round-trip test for random numbers
    for (i=0;i<nn[0];i++) {
      for (j=0;j<nn[1];j++) {
        for (k=0;k<nn[2];k++) {
          data3[i][j][k] = myran.doub();
          data4[i][j][k] = (2.0/N)*data3[i][j][k];
        }
      }
    }
    rlft3(data4,speq4,1);
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.