Index: trunk/CrossPare/src/de/ugoe/cs/cpdp/training/MetricMatchingTraining.java
===================================================================
--- trunk/CrossPare/src/de/ugoe/cs/cpdp/training/MetricMatchingTraining.java	(revision 47)
+++ trunk/CrossPare/src/de/ugoe/cs/cpdp/training/MetricMatchingTraining.java	(revision 48)
@@ -1,3 +1,3 @@
-// Copyright 2015 Georg-August-Universität Göttingen, Germany
+// Copyright 2015 Georg-August-Universit�t G�ttingen, Germany
 //
 //   Licensed under the Apache License, Version 2.0 (the "License");
@@ -85,5 +85,5 @@
 		this.traindataSet = traindataSet;
 
-		int rank = 5; // we want at least 5 matching attributes
+		int rank = 0; // we want at least 5 matching attributes
 		int num = 0;
 		int biggest_num = 0;
@@ -93,10 +93,11 @@
 			num++;
 			tmp = new MetricMatch(traindata, testdata);
-			//tmp.kolmogorovSmirnovTest(0.05);
-			
+
+			// metric selection may create error, continue to next training set
 			try {
 				tmp.attributeSelection();
 			}catch(Exception e) {
-				
+				e.printStackTrace();
+				throw new RuntimeException(e);
 			}
 			
@@ -127,5 +128,5 @@
 		this.mm = biggest;
 		Instances ilist = this.mm.getMatchedTrain();
-		Console.traceln(Level.INFO, "Chosing the trainingdata set num "+biggest_num +" with " + rank + " matching attributs, " + ilist.size() + " instances out of a possible set of " + traindataSet.size() + " sets");
+		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");
 		
 		// replace traindataSEt
@@ -206,6 +207,6 @@
 		 
 		 public MetricMatch(Instances train, Instances test) {
-			 this.train = train;
-			 this.test = test;
+			 this.train = new Instances(train);  // expensive! but we are dropping the attributes
+			 this.test = new Instances(test);
 			 
 			 // 1. convert metrics of testdata and traindata to later use in test
@@ -327,6 +328,10 @@
 		 */
 		public void attributeSelection() throws Exception {
+			//Console.traceln(Level.INFO, "Attribute Selection on Training Attributes ("+this.train.numAttributes()+")");
 			this.attributeSelection(this.train);
+			//Console.traceln(Level.INFO, "-----");
+			//Console.traceln(Level.INFO, "Attribute Selection on Test Attributes ("+this.test.numAttributes()+")");
 			this.attributeSelection(this.test);
+			//Console.traceln(Level.INFO, "-----");
 		}
 		
@@ -338,33 +343,48 @@
 			et.buildEvaluator(which);
 			//double tmp[] = new double[this.train.numAttributes()];
-			HashMap<Integer,Double> saeval = new HashMap<Integer,Double>();
+			HashMap<String,Double> saeval = new HashMap<String,Double>();
 			// evaluate all training attributes
 			// select top 15% of metrics
-			for(int i=0; i < which.numAttributes() - 1; i++) { 
-				//tmp[i] = et.evaluateAttribute(i);
-				saeval.put(i, et.evaluateAttribute(i));
+			for(int i=0; i < which.numAttributes(); i++) { 
+				if(which.classIndex() != i) {
+					saeval.put(which.attribute(i).name(), et.evaluateAttribute(i));
+				}
 				//Console.traceln(Level.SEVERE, "Significance Attribute Eval: " + tmp);
 			}
 			
-			HashMap<Integer, Double> sorted = sortByValues(saeval);
+			HashMap<String, Double> sorted = sortByValues(saeval);
 			
 			// die letzen 15% wollen wir haben
-			int last = (saeval.size() / 100) * 15;
-			int drop_first = saeval.size() - last;
-			
-			// drop attributes above last
+			float last = ((float)saeval.size() / 100) * 15;
+			int drop_first = saeval.size() - (int)last;
+			
+			//Console.traceln(Level.INFO, "Dropping "+ drop_first + " of " + sorted.size() + " attributes (we only keep the best 15% "+last+")");
+			/*
 			Iterator it = sorted.entrySet().iterator();
 		    while (it.hasNext()) {
 		    	Map.Entry pair = (Map.Entry)it.next();
-		    	if(drop_first > 0) {
-		    		which.deleteAttributeAt((int)pair.getKey());
-		    	}
-		    	drop_first--;
-		    }   
-		}
+		    	Console.traceln(Level.INFO, "key: "+(int)pair.getKey()+", value: " + (double)pair.getValue() + "");
+		    }*/
+			
+			// drop attributes above last
+			Iterator it = sorted.entrySet().iterator();
+		    while (drop_first > 0) {
+	    		Map.Entry pair = (Map.Entry)it.next();
+	    		if(which.attribute((String)pair.getKey()).index() != which.classIndex()) {
+	    			
+	    			which.deleteAttributeAt(which.attribute((String)pair.getKey()).index());
+	    			//Console.traceln(Level.INFO, "dropping attribute: "+ (String)pair.getKey());
+	    		}
+		    	drop_first-=1;
+		 
+		    
+		    }
+//		    //Console.traceln(Level.INFO, "Now we have " + which.numAttributes() + " attributes left (incl. class attribute!)");
+		}
+		
 		
 		private HashMap sortByValues(HashMap map) {
 	       List list = new LinkedList(map.entrySet());
-	       // Defined Custom Comparator here
+
 	       Collections.sort(list, new Comparator() {
 	            public int compare(Object o1, Object o2) {
@@ -374,6 +394,5 @@
 	       });
 
-	       // Here I am copying the sorted list in HashMap
-	       // using LinkedHashMap to preserve the insertion order
+
 	       HashMap sortedHashMap = new LinkedHashMap();
 	       for (Iterator it = list.iterator(); it.hasNext();) {
