Package com.nr.sort

Examples of com.nr.sort.Indexx


        segb[n] = tt.p[k];
        segd[n] = dist(pts[sega[n]],pts[segb[n]]);
        n++;
      }
    }
    Indexx idx = new Indexx(segd);
    for (j=0; j<npts; j++) mo[j] = j;
    n = -1;
    for (i=0; i<nspan; i++) {
       for (;;) {
        jj = j = idx.el(sega,++n);
        kk = k = idx.el(segb,n)
        while (mo[jj] != jj) jj = mo[jj];
        while (mo[kk] != kk) kk = mo[kk];
        if (jj != kk) {
          minsega[i] = j;
          minsegb[i] = k;
View Full Code Here


    // Test Indexx
    System.out.println("Testing Indexx");
    Ran myran = new Ran(17);
    for (i=0;i<N;i++) x[i]=myran.doub()
    Indexx idx =new Indexx(x);      // Create the index
    double[] xx=buildVector(x);     // Copy of x
    idx.sort(xx);     // Test sort on x itself
    for (i=0;i<N-1;i++) localflag = localflag || (xx[i] > xx[i+1]);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Indexx: Array sorted according to index is incorrectly ordered");
     
    }

    // Test member function sort() on another array
    for (i=0;i<N;i++) yy[i] = 1.0-x[i]; // Invert the sorting order
    idx.sort(yy);   // yy sorted according to the sizes of x
    for (i=0;i<N-1;i++) localflag = localflag || (yy[i+1] > yy[i]);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Indexx: Independent array sorted according to index is incorrectly ordered");
     
    }

    // Test member function el()
    for (i=0;i<N;i++) z[i] = 1.0-x[i];
    for (i=0;i<N;i++) zz[i] = idx.el(z,i);
    localflag = localflag || (maxel(vecsub(vecsub(u,zz),xx)) > sbeps);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Indexx: Member function el() does not sort inverted array into reverse order");
     
    }

    // Test l-value version of member function el()
    for (i=0;i<N;i++) idx.setEl(zz,i, xx[i]);
    localflag = localflag || (maxel(vecsub(x,zz)) > sbeps);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Indexx: l-value version of member function el() does not sort inverted array into reverse order");
     
    }

    // Test member function rank()
    idx.rank(zi);
    idx.sort(zi);
    for (i=0;i<N;i++) localflag = localflag || (zi[i] != i);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Indexx: Sorting the rank table into element-size order does not give increasing integers");
    }

    // Test use of empty constructor and member function index() with pointers
    double a[][]={{3.0,2.0,1.0,5.0,4.0},{3.0,1.0,5.0,2.0,4.0},{5.0,2.0,4.0,1.0,3.0}}; // matrix with unsorted rows
    int b[][]={{2,1,0,4,3},{1,3,0,4,2},{3,1,4,2,0}};    // Hand-generated index array for each row
    Indexx myhack = new Indexx();
    for (i=0;i<3;i++) {
      myhack.index(a[i],5);
      for (j=0;j<5;j++) localflag = localflag || (myhack.indx[j] != b[i][j]);
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Indexx: Member function index() did not work on array passed by pointer");
View Full Code Here

      for (j=0; j<m; j++) alph[j] = 0.;
      alphinit = true;
    }
    alphold = alph;   // save old a's
    // here begins the relaxation pass over all the a's
    Indexx x = new Indexx(alph)// sort a's, then find first nonzero one
    for (fnz=0; fnz<m; fnz++) if (alph[x.indx[fnz]] != 0.) break;
    for (j=fnz; j<m-2; j++) {  // randomly permute all the nonzero a's
      k = j + (ran.int32p() % (m-j));
      swap(x.indx,j,k);
    }
    for (jj=0; jj<m; jj++) {   // Main loop over a's
      j = x.indx[jj];
      sum = 0.;
      for (kk=fnz; kk<m; kk++) {  // Sums start with first nonzero
        k = x.indx[kk];
        sum += (gker.ker[j][k] + 1.)*gker.y[k]*alph[k];
      }
      alph[j] = alph[j] - (om/(gker.ker[j][j]+1.))*(gker.y[j]*sum-1.);
      alph[j] = max(0.,min(lambda,alph[j]));   // Projection operator
      if (jj < fnz && alph[j]!=0) {
        --fnz;
        //SWAP(x.indx[--fnz],x.indx[jj]);
        swap(x.indx, fnz, jj);
      // (Above) MAke an \alpha active if it becomes nonzero
    }
   
    // Here begins the relaxation passes over the interior \alpha's
    Indexx y = new Indexx(alph);   // Sort. Identify interior \alpha's
    for (fnz=0; fnz<m; fnz++) if (alph[y.indx[fnz]] != 0.) break;
    for (fub=fnz; fub<m; fub++) if (alph[y.indx[fub]] == lambda) break;
    for (j=fnz; j<fub-2; j++) {  // Permute
      k = j + (ran.int32p() % (fub-j));
      swap(y.indx,j,k);
View Full Code Here

TOP

Related Classes of com.nr.sort.Indexx

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.