Changeset 132 for trunk/CrossPare/src/de/ugoe
- Timestamp:
- 06/28/16 12:01:39 (8 years ago)
- Location:
- trunk/CrossPare/src/de/ugoe/cs/cpdp
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CrossPare/src/de/ugoe/cs/cpdp/eval/AbstractWekaEvaluation.java
r118 r132 92 92 Instances traindata, 93 93 List<ITrainer> trainers, 94 List<Double> efforts, 94 95 boolean writeHeader, 95 96 List<IResultStorage> storages) … … 150 151 eval.numFalsePositives(1) / (eval.numFalsePositives(1) + eval.numTrueNegatives(1)); 151 152 double gmeasure = 2 * eval.recall(1) * (1.0 - pf) / (eval.recall(1) + (1.0 - pf)); 152 double aucec = calculateReviewEffort(testdata, classifier );153 double aucec = calculateReviewEffort(testdata, classifier, efforts); 153 154 double succHe = eval.recall(1) >= 0.7 && eval.precision(1) >= 0.5 ? 1.0 : 0.0; 154 155 double succZi = eval.recall(1) >= 0.7 && eval.precision(1) >= 0.7 ? 1.0 : 0.0; … … 208 209 output.flush(); 209 210 } 210 211 212 private double calculateReviewEffort(Instances testdata, Classifier classifier, List<Double> efforts) { 213 if( efforts==null ) { 214 return 0; 215 } 216 217 final List<Integer> bugPredicted = new ArrayList<>(); 218 final List<Integer> nobugPredicted = new ArrayList<>(); 219 double totalLoc = 0.0d; 220 int totalBugs = 0; 221 for (int i = 0; i < testdata.numInstances(); i++) { 222 try { 223 if (Double.compare(classifier.classifyInstance(testdata.instance(i)), 0.0d) == 0) { 224 nobugPredicted.add(i); 225 } 226 else { 227 bugPredicted.add(i); 228 } 229 } 230 catch (Exception e) { 231 throw new RuntimeException( 232 "unexpected error during the evaluation of the review effort", 233 e); 234 } 235 if (Double.compare(testdata.instance(i).classValue(), 1.0d) == 0) { 236 totalBugs++; 237 } 238 totalLoc += efforts.get(i); 239 } 240 241 final List<Double> reviewLoc = new ArrayList<>(testdata.numInstances()); 242 final List<Double> bugsFound = new ArrayList<>(testdata.numInstances()); 243 244 double currentBugsFound = 0; 245 246 while (!bugPredicted.isEmpty()) { 247 double minLoc = Double.MAX_VALUE; 248 int minIndex = -1; 249 for (int i = 0; i < bugPredicted.size(); i++) { 250 double currentLoc = efforts.get(bugPredicted.get(i)); 251 if (currentLoc < minLoc) { 252 minIndex = i; 253 minLoc = currentLoc; 254 } 255 } 256 if (minIndex != -1) { 257 reviewLoc.add(minLoc / totalLoc); 258 259 currentBugsFound += testdata.instance(bugPredicted.get(minIndex)).classValue(); 260 bugsFound.add(currentBugsFound); 261 262 bugPredicted.remove(minIndex); 263 } 264 else { 265 throw new RuntimeException("Shouldn't happen!"); 266 } 267 } 268 269 while (!nobugPredicted.isEmpty()) { 270 double minLoc = Double.MAX_VALUE; 271 int minIndex = -1; 272 for (int i = 0; i < nobugPredicted.size(); i++) { 273 double currentLoc = efforts.get(nobugPredicted.get(i)); 274 if (currentLoc < minLoc) { 275 minIndex = i; 276 minLoc = currentLoc; 277 } 278 } 279 if (minIndex != -1) { 280 reviewLoc.add(minLoc / totalLoc); 281 282 currentBugsFound += testdata.instance(nobugPredicted.get(minIndex)).classValue(); 283 bugsFound.add(currentBugsFound); 284 nobugPredicted.remove(minIndex); 285 } 286 else { 287 throw new RuntimeException("Shouldn't happen!"); 288 } 289 } 290 291 double auc = 0.0; 292 for (int i = 0; i < bugsFound.size(); i++) { 293 auc += reviewLoc.get(i) * bugsFound.get(i) / totalBugs; 294 } 295 296 return auc; 297 } 298 299 @SuppressWarnings("unused") 300 @Deprecated 211 301 private double calculateReviewEffort(Instances testdata, Classifier classifier) { 212 302 -
trunk/CrossPare/src/de/ugoe/cs/cpdp/eval/IEvaluationStrategy.java
r86 r132 46 46 Instances traindata, 47 47 List<ITrainer> trainers, 48 List<Double> efforts, 48 49 boolean writeHeader, 49 50 List<IResultStorage> storages); -
trunk/CrossPare/src/de/ugoe/cs/cpdp/execution/AbstractCrossProjectExperiment.java
r123 r132 178 178 // Setup testdata and training data 179 179 Instances testdata = testVersion.getInstances(); 180 List<Double> efforts = testVersion.getEfforts(); 180 181 SetUniqueList<Instances> traindataSet = 181 182 SetUniqueList.setUniqueList(new LinkedList<Instances>()); … … 311 312 config.getExperimentName() + ".csv"); 312 313 } 313 evaluator.apply(testdata, traindata, allTrainers, writeHeader,314 evaluator.apply(testdata, traindata, allTrainers, efforts, writeHeader, 314 315 config.getResultStorages()); 315 316 writeHeader = false; -
trunk/CrossPare/src/de/ugoe/cs/cpdp/execution/ClassifierCreationExperiment.java
r86 r132 101 101 Instances testdata = testVersion.getInstances(); 102 102 Instances traindata = new Instances(testdata); 103 List<Double> efforts = testVersion.getEfforts(); 103 104 104 105 // Give the dataset a new name … … 168 169 config.getExperimentName() + ".csv"); 169 170 } 170 evaluator.apply(testdata, traindata, allTrainers, writeHeader, config.getResultStorages());171 evaluator.apply(testdata, traindata, allTrainers, efforts, writeHeader, config.getResultStorages()); 171 172 writeHeader = false; 172 173 } -
trunk/CrossPare/src/de/ugoe/cs/cpdp/execution/CrossValidationExperiment.java
r122 r132 166 166 // Setup testdata and training data 167 167 Instances testdata = testVersion.getInstances(); 168 List<Double> efforts = testVersion.getEfforts(); 168 169 169 170 for (ITrainingStrategy trainer : config.getTrainers()) { … … 205 206 config.getExperimentName() + ".csv"); 206 207 } 207 evaluator.apply(testdata, testdata, allTrainers, writeHeader,208 evaluator.apply(testdata, testdata, allTrainers, efforts, writeHeader, 208 209 config.getResultStorages()); 209 210 writeHeader = false; -
trunk/CrossPare/src/de/ugoe/cs/cpdp/loader/AbstractFolderLoader.java
r86 r132 16 16 17 17 import java.io.File; 18 import java.util.ArrayList; 18 19 import java.util.LinkedList; 19 20 import java.util.List; 20 21 22 import weka.core.Attribute; 21 23 import weka.core.Instances; 22 24 … … 66 68 Instances data = instancesLoader.load(versionFile); 67 69 String versionName = data.relationName(); 68 versions.add(new SoftwareVersion(projectName, versionName, data)); 70 List<Double> efforts = getEfforts(data); 71 versions.add(new SoftwareVersion(projectName, versionName, data, efforts)); 69 72 } 70 73 } … … 73 76 } 74 77 return versions; 78 } 79 80 private List<Double> getEfforts(Instances data) { 81 // attribute in the JURECZKO data and default 82 Attribute effortAtt = data.attribute("loc"); 83 if (effortAtt == null) { 84 // attribute in the NASA/SOFTMINE/MDP data 85 effortAtt = data.attribute("LOC_EXECUTABLE"); 86 } 87 if (effortAtt == null) { 88 // attribute in the AEEEM data 89 effortAtt = data.attribute("numberOfLinesOfCode"); 90 } 91 if (effortAtt == null) { 92 // attribute in the RELINK data 93 effortAtt = data.attribute("CountLineCodeExe"); 94 } 95 if( effortAtt == null ) { 96 return null; 97 } 98 List<Double> efforts = new ArrayList<>(data.size()); 99 for( int i=0; i<data.size(); i++ ) { 100 efforts.add(data.get(i).value(effortAtt)); 101 } 102 return efforts; 75 103 } 76 104 -
trunk/CrossPare/src/de/ugoe/cs/cpdp/loader/DecentFolderLoader.java
r86 r132 104 104 String versionName = versionFile.getName(); 105 105 Instances data = instancesLoader.load(versionFile); 106 versions.add(new SoftwareVersion(projectName, versionName, data ));106 versions.add(new SoftwareVersion(projectName, versionName, data, null)); 107 107 } 108 108 } -
trunk/CrossPare/src/de/ugoe/cs/cpdp/versions/SoftwareVersion.java
r86 r132 14 14 15 15 package de.ugoe.cs.cpdp.versions; 16 17 import java.util.List; 16 18 17 19 import weka.core.Instances; … … 38 40 */ 39 41 private final Instances instances; 42 43 /** 44 * Review effort per instance. 45 */ 46 private final List<Double> efforts; 40 47 41 48 /** … … 49 56 * data of the version 50 57 */ 51 public SoftwareVersion(String project, String version, Instances instances ) {58 public SoftwareVersion(String project, String version, Instances instances, List<Double> efforts) { 52 59 this.project = project; 53 60 this.version = version; 54 61 this.instances = instances; 62 this.efforts = efforts; 55 63 } 56 64 57 65 /** 58 66 * returns the project name … … 81 89 return new Instances(instances); 82 90 } 91 92 /** 93 * <p> 94 * returns the review effort of the version 95 * </p> 96 * 97 * @return 98 */ 99 public List<Double> getEfforts() { 100 return efforts; 101 } 83 102 84 103 /**
Note: See TracChangeset
for help on using the changeset viewer.