Changeset 21 for trunk/CrossPare/src/de/ugoe
- Timestamp:
- 11/05/14 11:56:16 (10 years ago)
- Location:
- trunk/CrossPare/src/de/ugoe/cs/cpdp/training
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CrossPare/src/de/ugoe/cs/cpdp/training/WekaClusterTraining2.java
r20 r21 5 5 import java.util.HashSet; 6 6 import java.util.Iterator; 7 import java.util.Map.Entry; 7 8 import java.util.Set; 8 9 import java.util.logging.Level; … … 146 147 cclassifier = new HashMap<Integer, Classifier>(); 147 148 ctraindata = new HashMap<Integer, Instances>(); 148 149 // 3. cluster data150 // use standard params for now151 clusterer = new EM();152 // we can set options like so:153 //String[] params = {"-N", "100"};154 //clusterer.setOptions(params);155 156 // set max num of clusters to train data size (although we do not want that)157 clusterer.setMaximumNumberOfClusters(train.size());158 149 159 // build clusterer 160 clusterer.buildClusterer(train); 161 162 Instances ctrain = new Instances(train); 163 164 // get train data per cluster 165 int cnumber; 166 for ( int j=0; j < ctrain.numInstances(); j++ ) { 167 cnumber = clusterer.clusterInstance(ctrain.get(j)); 168 169 // add training data to list of instances for this cluster number 170 if ( !ctraindata.containsKey(cnumber) ) { 171 ctraindata.put(cnumber, new Instances(traindata)); 172 ctraindata.get(cnumber).delete(); 150 Instances ctrain; 151 int maxNumClusters = train.size(); 152 boolean sufficientInstancesInEachCluster; 153 do { // while(onlyTarget) 154 sufficientInstancesInEachCluster = true; 155 clusterer = new EM(); 156 clusterer.setMaximumNumberOfClusters(maxNumClusters); 157 clusterer.buildClusterer(train); 158 159 // 4. get cluster membership of our traindata 160 //AddCluster cfilter = new AddCluster(); 161 //cfilter.setClusterer(clusterer); 162 //cfilter.setInputFormat(train); 163 //Instances ctrain = Filter.useFilter(train, cfilter); 164 165 ctrain = new Instances(train); 166 ctraindata = new HashMap<>(); 167 168 // get traindata per cluster 169 for ( int j=0; j < ctrain.numInstances(); j++ ) { 170 // get the cluster number from the attributes, subract 1 because if we clusterInstance we get 0-n, and this is 1-n 171 //cnumber = Integer.parseInt(ctrain.get(j).stringValue(ctrain.get(j).numAttributes()-1).replace("cluster", "")) - 1; 172 173 int cnumber = clusterer.clusterInstance(ctrain.get(j)); 174 // add training data to list of instances for this cluster number 175 if ( !ctraindata.containsKey(cnumber) ) { 176 ctraindata.put(cnumber, new Instances(traindata)); 177 ctraindata.get(cnumber).delete(); 178 } 179 ctraindata.get(cnumber).add(traindata.get(j)); 173 180 } 174 ctraindata.get(cnumber).add(traindata.get(j)); 175 } 181 182 for( Entry<Integer,Instances> entry : ctraindata.entrySet() ) { 183 Instances instances = entry.getValue(); 184 int[] counts = instances.attributeStats(instances.classIndex()).nominalCounts; 185 for( int count : counts ) { 186 sufficientInstancesInEachCluster &= count>0; 187 } 188 sufficientInstancesInEachCluster &= instances.numInstances()>=5; 189 } 190 maxNumClusters = clusterer.numberOfClusters()-1; 191 } while(!sufficientInstancesInEachCluster); 176 192 177 193 // train one classifier per cluster, we get the cluster number from the training data 178 194 Iterator<Integer> clusternumber = ctraindata.keySet().iterator(); 179 195 while ( clusternumber.hasNext() ) { 180 cnumber = clusternumber.next();196 int cnumber = clusternumber.next(); 181 197 cclassifier.put(cnumber,setupClassifier()); 182 198 cclassifier.get(cnumber).buildClassifier(ctraindata.get(cnumber)); -
trunk/CrossPare/src/de/ugoe/cs/cpdp/training/WekaLocalTraining2.java
r20 r21 271 271 dist = new EuclideanDistance(traindata2); 272 272 if( !this.ctraindata.containsKey(found_cnumber) ) { 273 double min_distance = 99999999;273 double min_distance = Double.MAX_VALUE; 274 274 clusternumber = ctraindata.keySet().iterator(); 275 275 while ( clusternumber.hasNext() ) { … … 353 353 // we need these for the sizes of the quadrants 354 354 double[] big = {0,0}; 355 double[] small = { 9999999,99999999};355 double[] small = {Double.MAX_VALUE,Double.MAX_VALUE}; 356 356 357 357 // set quadtree payload values and get max and min x and y values for size … … 581 581 */ 582 582 private int findFarthest(int index) { 583 double furthest = -1000000;583 double furthest = Double.MIN_VALUE; 584 584 int ret = 0; 585 585
Note: See TracChangeset
for help on using the changeset viewer.