Ignore:
Timestamp:
04/28/16 16:51:59 (9 years ago)
Author:
sherbold
Message:
  • added some new approaches
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrossPare/src/de/ugoe/cs/cpdp/dataprocessing/TransferComponentAnalysis.java

    r55 r64  
    2525import org.ojalgo.array.Array1D; 
    2626 
     27import de.ugoe.cs.cpdp.util.SortUtils; 
    2728import de.ugoe.cs.util.console.Console; 
    2829import weka.core.Attribute; 
     
    8990        Array1D<ComplexNumber> eigenvaluesArray = eigenvalueDecomposition.getEigenvalues(); 
    9091        System.out.println(eigenvaluesArray.length); 
    91         final double[] eigenvalues = new double[(int) eigenvaluesArray.length]; 
     92        final Double[] eigenvalues = new Double[(int) eigenvaluesArray.length]; 
    9293        final int[] index = new int[(int) eigenvaluesArray.length]; 
    9394        // create kernel transformation matrix from eigenvectors 
     
    9697            index[i] = i; 
    9798        } 
    98         quicksort(eigenvalues, index); 
     99        SortUtils.quicksort(eigenvalues, index); 
    99100 
    100101        final PrimitiveMatrix transformedKernel = kernelMatrix.multiplyRight(eigenvalueDecomposition 
     
    218219        return muMatrix.build(); 
    219220    } 
    220  
    221     // below is from http://stackoverflow.com/a/1040503 
    222     private static void quicksort(double[] main, int[] index) { 
    223         quicksort(main, index, 0, index.length - 1); 
    224     } 
    225  
    226     // quicksort a[left] to a[right] 
    227     private static void quicksort(double[] a, int[] index, int left, int right) { 
    228         if (right <= left) 
    229             return; 
    230         int i = partition(a, index, left, right); 
    231         quicksort(a, index, left, i - 1); 
    232         quicksort(a, index, i + 1, right); 
    233     } 
    234  
    235     // partition a[left] to a[right], assumes left < right 
    236     private static int partition(double[] a, int[] index, int left, int right) { 
    237         int i = left - 1; 
    238         int j = right; 
    239         while (true) { 
    240             while (less(a[++i], a[right])) // find item on left to swap 
    241             ; // a[right] acts as sentinel 
    242             while (less(a[right], a[--j])) // find item on right to swap 
    243                 if (j == left) 
    244                     break; // don't go out-of-bounds 
    245             if (i >= j) 
    246                 break; // check if pointers cross 
    247             exch(a, index, i, j); // swap two elements into place 
    248         } 
    249         exch(a, index, i, right); // swap with partition element 
    250         return i; 
    251     } 
    252  
    253     // is x < y ? 
    254     private static boolean less(double x, double y) { 
    255         return (x < y); 
    256     } 
    257  
    258     // exchange a[i] and a[j] 
    259     private static void exch(double[] a, int[] index, int i, int j) { 
    260         double swap = a[i]; 
    261         a[i] = a[j]; 
    262         a[j] = swap; 
    263         int b = index[i]; 
    264         index[i] = index[j]; 
    265         index[j] = b; 
    266     } 
    267221} 
Note: See TracChangeset for help on using the changeset viewer.