Changeset 48 for trunk/CrossPare
- Timestamp:
- 12/12/15 15:25:22 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CrossPare/src/de/ugoe/cs/cpdp/training/MetricMatchingTraining.java
r47 r48 1 // Copyright 2015 Georg-August-Universit ät Göttingen, Germany1 // Copyright 2015 Georg-August-Universit�t G�ttingen, Germany 2 2 // 3 3 // Licensed under the Apache License, Version 2.0 (the "License"); … … 85 85 this.traindataSet = traindataSet; 86 86 87 int rank = 5; // we want at least 5 matching attributes87 int rank = 0; // we want at least 5 matching attributes 88 88 int num = 0; 89 89 int biggest_num = 0; … … 93 93 num++; 94 94 tmp = new MetricMatch(traindata, testdata); 95 //tmp.kolmogorovSmirnovTest(0.05); 96 95 96 // metric selection may create error, continue to next training set 97 97 try { 98 98 tmp.attributeSelection(); 99 99 }catch(Exception e) { 100 100 e.printStackTrace(); 101 throw new RuntimeException(e); 101 102 } 102 103 … … 127 128 this.mm = biggest; 128 129 Instances ilist = this.mm.getMatchedTrain(); 129 Console.traceln(Level.INFO, "Chosing the trainingdata set num "+biggest_num +" with " + rank + " matching attribut s, " + ilist.size() + " instances out of a possible set of " + traindataSet.size() + " sets");130 Console.traceln(Level.INFO, "Chosing the trainingdata set num "+biggest_num +" with " + rank + " matching attributes, " + ilist.size() + " instances out of a possible set of " + traindataSet.size() + " sets"); 130 131 131 132 // replace traindataSEt … … 206 207 207 208 public MetricMatch(Instances train, Instances test) { 208 this.train = train;209 this.test = test;209 this.train = new Instances(train); // expensive! but we are dropping the attributes 210 this.test = new Instances(test); 210 211 211 212 // 1. convert metrics of testdata and traindata to later use in test … … 327 328 */ 328 329 public void attributeSelection() throws Exception { 330 //Console.traceln(Level.INFO, "Attribute Selection on Training Attributes ("+this.train.numAttributes()+")"); 329 331 this.attributeSelection(this.train); 332 //Console.traceln(Level.INFO, "-----"); 333 //Console.traceln(Level.INFO, "Attribute Selection on Test Attributes ("+this.test.numAttributes()+")"); 330 334 this.attributeSelection(this.test); 335 //Console.traceln(Level.INFO, "-----"); 331 336 } 332 337 … … 338 343 et.buildEvaluator(which); 339 344 //double tmp[] = new double[this.train.numAttributes()]; 340 HashMap< Integer,Double> saeval = new HashMap<Integer,Double>();345 HashMap<String,Double> saeval = new HashMap<String,Double>(); 341 346 // evaluate all training attributes 342 347 // select top 15% of metrics 343 for(int i=0; i < which.numAttributes() - 1; i++) { 344 //tmp[i] = et.evaluateAttribute(i); 345 saeval.put(i, et.evaluateAttribute(i)); 348 for(int i=0; i < which.numAttributes(); i++) { 349 if(which.classIndex() != i) { 350 saeval.put(which.attribute(i).name(), et.evaluateAttribute(i)); 351 } 346 352 //Console.traceln(Level.SEVERE, "Significance Attribute Eval: " + tmp); 347 353 } 348 354 349 HashMap< Integer, Double> sorted = sortByValues(saeval);355 HashMap<String, Double> sorted = sortByValues(saeval); 350 356 351 357 // die letzen 15% wollen wir haben 352 int last = (saeval.size() / 100) * 15; 353 int drop_first = saeval.size() - last; 354 355 // drop attributes above last 358 float last = ((float)saeval.size() / 100) * 15; 359 int drop_first = saeval.size() - (int)last; 360 361 //Console.traceln(Level.INFO, "Dropping "+ drop_first + " of " + sorted.size() + " attributes (we only keep the best 15% "+last+")"); 362 /* 356 363 Iterator it = sorted.entrySet().iterator(); 357 364 while (it.hasNext()) { 358 365 Map.Entry pair = (Map.Entry)it.next(); 359 if(drop_first > 0) { 360 which.deleteAttributeAt((int)pair.getKey()); 361 } 362 drop_first--; 363 } 364 } 366 Console.traceln(Level.INFO, "key: "+(int)pair.getKey()+", value: " + (double)pair.getValue() + ""); 367 }*/ 368 369 // drop attributes above last 370 Iterator it = sorted.entrySet().iterator(); 371 while (drop_first > 0) { 372 Map.Entry pair = (Map.Entry)it.next(); 373 if(which.attribute((String)pair.getKey()).index() != which.classIndex()) { 374 375 which.deleteAttributeAt(which.attribute((String)pair.getKey()).index()); 376 //Console.traceln(Level.INFO, "dropping attribute: "+ (String)pair.getKey()); 377 } 378 drop_first-=1; 379 380 381 } 382 // //Console.traceln(Level.INFO, "Now we have " + which.numAttributes() + " attributes left (incl. class attribute!)"); 383 } 384 365 385 366 386 private HashMap sortByValues(HashMap map) { 367 387 List list = new LinkedList(map.entrySet()); 368 // Defined Custom Comparator here 388 369 389 Collections.sort(list, new Comparator() { 370 390 public int compare(Object o1, Object o2) { … … 374 394 }); 375 395 376 // Here I am copying the sorted list in HashMap 377 // using LinkedHashMap to preserve the insertion order 396 378 397 HashMap sortedHashMap = new LinkedHashMap(); 379 398 for (Iterator it = list.iterator(); it.hasNext();) {
Note: See TracChangeset
for help on using the changeset viewer.