Changeset 64


Ignore:
Timestamp:
04/28/16 16:51:59 (9 years ago)
Author:
sherbold
Message:
  • added some new approaches
Location:
trunk/CrossPare/src/de/ugoe/cs/cpdp
Files:
7 added
3 edited

Legend:

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

    r52 r64  
    1515package de.ugoe.cs.cpdp.dataprocessing; 
    1616 
    17 import org.apache.commons.math3.ml.distance.EuclideanDistance; 
    18  
     17import de.ugoe.cs.cpdp.util.WekaUtils; 
     18import de.ugoe.cs.cpdp.util.WekaUtils.DistChar; 
    1919import weka.core.Instances; 
    2020 
     
    2222public class TCAPlusNormalization implements IProcessesingStrategy { 
    2323 
    24     private class DistChar { 
    25         private final double mean; 
    26         private final double std; 
    27         private final double min; 
    28         private final double max; 
    29         private int num; 
    30         private DistChar(double mean, double std, double min, double max, int num) { 
    31             this.mean = mean; 
    32             this.std = std; 
    33             this.min = min; 
    34             this.max = max; 
    35             this.num = num; 
    36         } 
    37     } 
    38      
    3924    /** 
    4025     * Does not have parameters. String is ignored. 
     
    5540     
    5641    private void applyTCAPlus(Instances testdata, Instances traindata) { 
    57         DistChar dcTest = datasetDistance(testdata); 
    58         DistChar dcTrain = datasetDistance(traindata); 
     42        DistChar dcTest = WekaUtils.datasetDistance(testdata); 
     43        DistChar dcTrain = WekaUtils.datasetDistance(traindata); 
    5944         
    6045        // RULE 1: 
     
    8671        } 
    8772    } 
    88      
    89     private DistChar datasetDistance(Instances data) { 
    90         double distance; 
    91         double sumAll = 0.0; 
    92         double sumAllQ = 0.0; 
    93         double min = Double.MAX_VALUE; 
    94         double max = Double.MIN_VALUE; 
    95         int numCmp = 0; 
    96         int l = 0; 
    97         double[] inst1 = new double[data.numAttributes()-1]; 
    98         double[] inst2 = new double[data.numAttributes()-1]; 
    99         EuclideanDistance euclideanDistance = new EuclideanDistance(); 
    100         for( int i=0; i<data.numInstances(); i++ ) { 
    101             l=0; 
    102             for( int k=0; k<data.numAttributes(); k++ ) { 
    103                 if( k!=data.classIndex() ) { 
    104                     inst1[l] = data.instance(i).value(k); 
    105                 } 
    106             } 
    107             for( int j=0; j<data.numInstances(); j++ ) { 
    108                 l=0; 
    109                 for( int k=0; k<data.numAttributes(); k++ ) { 
    110                     if( k!=data.classIndex() ) { 
    111                         inst2[l] = data.instance(j).value(k); 
    112                     } 
    113                 } 
    114                 distance = euclideanDistance.compute(inst1, inst2); 
    115                 sumAll += distance; 
    116                 sumAllQ += distance*distance; 
    117                 numCmp++; 
    118                 if( distance < min ) { 
    119                     min = distance; 
    120                 } 
    121                 if( distance > max ) { 
    122                     max = distance; 
    123                 } 
    124             } 
    125         } 
    126         double mean = sumAll / numCmp; 
    127         double std = Math.sqrt((sumAllQ-(sumAll*sumAll)/numCmp) * 
    128                                   (1.0d / (numCmp - 1))); 
    129         return new DistChar(mean, std, min, max, data.numInstances()); 
    130     } 
    131  
    13273} 
  • 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} 
  • trunk/CrossPare/src/de/ugoe/cs/cpdp/wekaclassifier/AbstractCODEP.java

    r56 r64  
    2727import weka.classifiers.functions.RBFNetwork; 
    2828import weka.classifiers.rules.DecisionTable; 
     29import weka.classifiers.trees.ADTree; 
    2930import weka.core.Attribute; 
    3031import weka.core.DenseInstance; 
     
    103104    /** 
    104105     * <p> 
    105      * Creates a CODEP instance using the classications of the internal classifiers. 
     106     * Creates a CODEP instance using the classifications of the internal classifiers. 
    106107     * </p> 
    107108     * 
     
    110111     * @return CODEP instance 
    111112     * @throws Exception 
    112      *             thrown if an exception occurs during classification with an internal classifer 
     113     *             thrown if an exception occurs during classification with an internal classifier 
    113114     */ 
    114115    private Instance createInternalInstance(Instance instance) throws Exception { 
     
    147148        // create training data with prediction labels 
    148149 
    149         // TODO ADTree missing?! 
     150        internalClassifiers.add(new ADTree()); 
    150151        internalClassifiers.add(new BayesNet()); 
    151152        internalClassifiers.add(new DecisionTable()); 
Note: See TracChangeset for help on using the changeset viewer.