Changeset 64
- Timestamp:
- 04/28/16 16:51:59 (9 years ago)
- 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 15 15 package de.ugoe.cs.cpdp.dataprocessing; 16 16 17 import org.apache.commons.math3.ml.distance.EuclideanDistance;18 17 import de.ugoe.cs.cpdp.util.WekaUtils; 18 import de.ugoe.cs.cpdp.util.WekaUtils.DistChar; 19 19 import weka.core.Instances; 20 20 … … 22 22 public class TCAPlusNormalization implements IProcessesingStrategy { 23 23 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 39 24 /** 40 25 * Does not have parameters. String is ignored. … … 55 40 56 41 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); 59 44 60 45 // RULE 1: … … 86 71 } 87 72 } 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 132 73 } -
trunk/CrossPare/src/de/ugoe/cs/cpdp/dataprocessing/TransferComponentAnalysis.java
r55 r64 25 25 import org.ojalgo.array.Array1D; 26 26 27 import de.ugoe.cs.cpdp.util.SortUtils; 27 28 import de.ugoe.cs.util.console.Console; 28 29 import weka.core.Attribute; … … 89 90 Array1D<ComplexNumber> eigenvaluesArray = eigenvalueDecomposition.getEigenvalues(); 90 91 System.out.println(eigenvaluesArray.length); 91 final double[] eigenvalues = new double[(int) eigenvaluesArray.length];92 final Double[] eigenvalues = new Double[(int) eigenvaluesArray.length]; 92 93 final int[] index = new int[(int) eigenvaluesArray.length]; 93 94 // create kernel transformation matrix from eigenvectors … … 96 97 index[i] = i; 97 98 } 98 quicksort(eigenvalues, index);99 SortUtils.quicksort(eigenvalues, index); 99 100 100 101 final PrimitiveMatrix transformedKernel = kernelMatrix.multiplyRight(eigenvalueDecomposition … … 218 219 return muMatrix.build(); 219 220 } 220 221 // below is from http://stackoverflow.com/a/1040503222 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 < right236 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 swap241 ; // a[right] acts as sentinel242 while (less(a[right], a[--j])) // find item on right to swap243 if (j == left)244 break; // don't go out-of-bounds245 if (i >= j)246 break; // check if pointers cross247 exch(a, index, i, j); // swap two elements into place248 }249 exch(a, index, i, right); // swap with partition element250 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 }267 221 } -
trunk/CrossPare/src/de/ugoe/cs/cpdp/wekaclassifier/AbstractCODEP.java
r56 r64 27 27 import weka.classifiers.functions.RBFNetwork; 28 28 import weka.classifiers.rules.DecisionTable; 29 import weka.classifiers.trees.ADTree; 29 30 import weka.core.Attribute; 30 31 import weka.core.DenseInstance; … … 103 104 /** 104 105 * <p> 105 * Creates a CODEP instance using the classi cations of the internal classifiers.106 * Creates a CODEP instance using the classifications of the internal classifiers. 106 107 * </p> 107 108 * … … 110 111 * @return CODEP instance 111 112 * @throws Exception 112 * thrown if an exception occurs during classification with an internal classif er113 * thrown if an exception occurs during classification with an internal classifier 113 114 */ 114 115 private Instance createInternalInstance(Instance instance) throws Exception { … … 147 148 // create training data with prediction labels 148 149 149 // TODO ADTree missing?!150 internalClassifiers.add(new ADTree()); 150 151 internalClassifiers.add(new BayesNet()); 151 152 internalClassifiers.add(new DecisionTable());
Note: See TracChangeset
for help on using the changeset viewer.