Changeset 1919
- Timestamp:
- 03/12/15 15:51:31 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/usability/CMDgetTaskModelSimilarity.java
r1895 r1919 84 84 Map<ITaskModel, List<ISequence>> inputTaskModels = new IdentityHashMap<>(); 85 85 86 ITaskModel firstModel = null; 87 86 88 for (String inputTaskTreeName : inputTaskTreeNames) { 87 89 Object dataObject = GlobalDataContainer.getInstance().getData(inputTaskTreeName); … … 104 106 105 107 inputTaskModels.put((ITaskModel) dataObject, tasksToCompare); 106 } 107 108 SimilarityStatistics statistics = new SimilarityStatistics(); 109 110 getTaskModelSimilarity(inputTaskModels, statistics); 111 112 Console.println("\nsimilarity statistics of all comparisons"); 113 statistics.dump(); 108 109 if (firstModel == null) { 110 firstModel = (ITaskModel) dataObject; 111 } 112 } 113 114 getTaskModelSimilarity(firstModel, inputTaskModels); 114 115 } 115 116 … … 117 118 * 118 119 */ 119 private void getTaskModelSimilarity( Map<ITaskModel, List<ISequence>> inputTaskModels,120 SimilarityStatistics statistics)120 private void getTaskModelSimilarity(ITaskModel modelToCompare, 121 Map<ITaskModel, List<ISequence>> inputTaskModels) 121 122 { 122 123 // create the indexes to not do too many comparisons … … 188 189 List<ComparisonRunnable> runnables = new LinkedList<>(); 189 190 190 for (Map.Entry<ITaskModel, List<ISequence>> model1 : inputTaskModels.entrySet()) { 191 for (Map.Entry<ITaskModel, List<ISequence>> model2 : inputTaskModels.entrySet()) { 192 if (model1.getKey() != model2.getKey()) { 193 runnables.add(new ComparisonRunnable(model1.getKey(), model1.getValue(), 194 model2.getKey(), model2.getValue(), 195 Collections.unmodifiableMap 196 (index1.get(model2.getKey())), 197 Collections.unmodifiableMap(index2), 198 Collections.unmodifiableMap(index3), 199 runnables)); 200 } 191 for (Map.Entry<ITaskModel, List<ISequence>> model2 : inputTaskModels.entrySet()) { 192 if (modelToCompare != model2.getKey()) { 193 runnables.add(new ComparisonRunnable(modelToCompare, 194 inputTaskModels.get(modelToCompare), 195 model2.getKey(), model2.getValue(), 196 Collections.unmodifiableMap 197 (index1.get(model2.getKey())), 198 Collections.unmodifiableMap(index2), 199 Collections.unmodifiableMap(index3), 200 runnables)); 201 201 } 202 202 } … … 250 250 251 251 for (ComparisonRunnable runnable : runnables) { 252 Console.println("\n similarity statistics of comparison between " + runnable.model1 + 253 " and " + runnable.model2); 252 Console.println("\nsimilarity statistics of comparison between " + runnable.model1 + 253 " (" + runnable.tasks1.size() + " tasks) and " + runnable.model2 + 254 " (" + runnable.tasks2.size() + " tasks)"); 254 255 runnable.getStatistics().dump(); 255 statistics.mergeWith(runnable.getStatistics());256 256 } 257 257 } … … 263 263 264 264 /** */ 265 private int taskCounter = 0; 266 267 /** */ 268 private int maxCoverage = 0; 265 private int taskCounter1 = 0; 266 267 /** */ 268 private int maxCoverage1 = 0; 269 270 /** */ 271 private ITaskModel model1 = null; 269 272 270 273 /** */ 271 private Map<Integer, Integer> coverageCounters = new HashMap<>(); 274 private Map<Integer, Integer> coverageCounters1 = new HashMap<>(); 275 276 /** */ 277 private int taskCounter2 = 0; 278 279 /** */ 280 private int maxCoverage2 = 0; 281 282 /** */ 283 private ITaskModel model2 = null; 284 285 /** */ 286 private Map<Integer, Integer> coverageCounters2 = new HashMap<>(); 272 287 273 288 /** */ 274 289 private Map<Integer, Map<Integer, Map<TaskEquality, Integer>>> equalityCounters = 275 290 new HashMap<>(); 291 292 /** 293 * 294 */ 295 private void addCoverageCounter(ITask task, ITaskModel model) { 296 if (model1 == null) { 297 model1 = model; 298 } 299 else if (model2 == null) { 300 model2 = model; 301 } 302 303 int coverageRatio = model.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE); 304 305 if (model == model1) { 306 addToMaps(coverageCounters1, coverageRatio, 1); 307 taskCounter1++; 308 maxCoverage1 = Math.max(maxCoverage1, coverageRatio); 309 } 310 else { 311 addToMaps(coverageCounters2, coverageRatio, 1); 312 taskCounter2++; 313 maxCoverage2 = Math.max(maxCoverage2, coverageRatio); 314 } 315 } 276 316 277 317 /** … … 284 324 TaskEquality equality) 285 325 { 286 int coverageRatio1 = 287 model.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE); 326 int coverageRatio1 = model.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE); 288 327 int coverageRatio2 = 289 328 otherModel.getTaskInfo(other).getMeasureValue(TaskMetric.EVENT_COVERAGE); 290 329 291 addToMaps(coverageRatio1, 1);292 330 addToMaps(coverageRatio1, coverageRatio2, equality, 1); 293 taskCounter++;294 maxCoverage = Math.max(maxCoverage, coverageRatio1);295 331 } 296 332 … … 299 335 */ 300 336 private void store(ITask task, ITaskModel model) { 301 int coverageRatio1 = 302 model.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE); 303 304 addToMaps(coverageRatio1, 1); 337 int coverageRatio1 = model.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE); 338 305 339 addToMaps(coverageRatio1, 0, TaskEquality.UNEQUAL, 1); 306 taskCounter++; 307 maxCoverage = Math.max(maxCoverage, coverageRatio1); 308 } 309 310 /** 311 * 312 */ 313 private void mergeWith(SimilarityStatistics statistics) { 314 for (Map.Entry<Integer, Map<Integer, Map<TaskEquality, Integer>>> entry1 : 315 statistics.equalityCounters.entrySet()) 316 { 317 for (Map.Entry<Integer, Map<TaskEquality, Integer>> entry2 : 318 entry1.getValue().entrySet()) 319 { 320 for (Map.Entry<TaskEquality, Integer> entry3 : entry2.getValue().entrySet()) { 321 addToMaps 322 (entry1.getKey(), entry2.getKey(), entry3.getKey(), entry3.getValue()); 323 } 324 } 325 } 326 327 for (Map.Entry<Integer, Integer> entry : statistics.coverageCounters.entrySet()) { 328 addToMaps(entry.getKey(), entry.getValue()); 329 } 330 331 taskCounter += statistics.taskCounter; 332 maxCoverage = Math.max(maxCoverage, statistics.taskCounter); 333 } 334 335 /** 336 * 337 */ 338 private void addToMaps(int ratio, int increment) { 340 } 341 342 /** 343 * 344 */ 345 private void addToMaps(Map<Integer, Integer> coverageCounters, int ratio, int increment) { 339 346 Integer counter = coverageCounters.get(ratio); 340 347 … … 382 389 Console.println("========================"); 383 390 384 int[][] bins = getBinsOfAlmostEqualSize(); 391 int[][] bins1 = getBinsOfAlmostEqualSize(coverageCounters1, taskCounter1, maxCoverage1); 392 int[][] bins2 = getBinsOfAlmostEqualSize(coverageCounters2, taskCounter2, maxCoverage2); 385 393 int lowerBorder1; 386 394 int higherBorder1; 387 395 int lowerBorder2; 388 396 int higherBorder2; 389 int allEqualitiesOfBin = 0; 397 int lexicalEqualitiesOfBin = 0; 398 int syntacticalEqualitiesOfBin = 0; 399 int semanticalEqualitiesOfBin = 0; 400 int similaritiesOfBin = 0; 390 401 int allEqualities = 0; 391 402 392 for (int i = bins.length - 1; i >= 0 ; i--) { 403 String[][] outputs = new String[(bins1.length * (bins2.length + 3)) + 1][]; 404 int outputIndex = 0; 405 406 DecimalFormat percentFormat = new DecimalFormat("##0.0%"); 407 StringBuffer csvData = new StringBuffer(); 408 csvData.append(taskCounter1); 409 csvData.append(';'); 410 csvData.append(taskCounter2); 411 412 for (int i = bins1.length - 1; i >= 0 ; i--) { 393 413 if (i <= 0) { 394 414 lowerBorder1 = 0; 395 415 } 396 416 else { 397 lowerBorder1 = bins[i - 1][0] + 1; 398 } 399 400 higherBorder1 = bins[i][0]; 401 402 allEqualitiesOfBin = 0; 403 404 Console.println("similarities of " + bins[i][1] + " tasks with " + lowerBorder1 + 405 " to " + higherBorder1 + "‰ coverage"); 406 407 for (int j = bins.length - 1; j >= 0; j--) { 417 lowerBorder1 = bins1[i - 1][0] + 1; 418 } 419 420 higherBorder1 = bins1[i][0]; 421 422 int allInBin1 = countAllInBin(lowerBorder1, higherBorder1); 423 csvData.append(';'); 424 csvData.append(allInBin1); 425 426 lexicalEqualitiesOfBin = 0; 427 syntacticalEqualitiesOfBin = 0; 428 semanticalEqualitiesOfBin = 0; 429 similaritiesOfBin = 0; 430 431 outputs[outputIndex++] = new String[] 432 { "similarities of " + bins1[i][1] + " tasks with " + lowerBorder1 + 433 " to " + higherBorder1 + " covered events", "LEX", "SYN", "SEM", 434 "ALL EQUAL", "SIM", "ALL" }; 435 436 for (int j = bins2.length - 1; j >= 0; j--) { 408 437 if (j <= 0) { 409 438 lowerBorder2 = 0; 410 439 } 411 440 else { 412 lowerBorder2 = bins[j - 1][0] + 1; 413 } 414 415 higherBorder2 = bins[j][0]; 416 417 Console.print(" --> to " + bins[j][1] + " tasks with " + lowerBorder2 + 418 " to " + higherBorder2 + "‰ coverage"); 419 420 Console.print(" | "); 421 int allInBin = countAllInBin(lowerBorder1, higherBorder1); 441 lowerBorder2 = bins2[j - 1][0] + 1; 442 } 443 444 higherBorder2 = bins2[j][0]; 445 446 int allInBin2 = countAllInBin(lowerBorder2, higherBorder2); 447 csvData.append(';'); 448 csvData.append(allInBin2); 422 449 423 450 int count1 = countEqualities(lowerBorder1, higherBorder1, lowerBorder2, 424 451 higherBorder2, TaskEquality.LEXICALLY_EQUAL); 425 426 dump(count1, allInBin, "LEX");427 Console.print("\t| ");428 452 429 453 int count2 = countEqualities(lowerBorder1, higherBorder1, lowerBorder2, 430 454 higherBorder2, TaskEquality.SYNTACTICALLY_EQUAL); 431 455 432 dump(count2, allInBin, "SYN");433 Console.print("\t| ");434 435 456 int count3 = countEqualities(lowerBorder1, higherBorder1, lowerBorder2, 436 457 higherBorder2, TaskEquality.SEMANTICALLY_EQUAL); 437 458 438 dump(count3, allInBin, "SEM");439 Console.print("\t|| ");440 441 459 int count4 = countEqualities(lowerBorder1, higherBorder1, lowerBorder2, 442 460 higherBorder2, null); 443 461 444 dump(count4, allInBin, "SIM"); 445 Console.print("\t|| "); 446 447 dump(count1 + count2 + count3 + count4, allInBin, "ALL"); 448 Console.println(""); 449 450 allEqualitiesOfBin += count1 + count2 + count3 + count4; 451 } 452 453 Console.print(" --> to all other tasks\t"); 454 dump(allEqualitiesOfBin, taskCounter, "ALL"); 455 Console.println(""); 456 457 allEqualities += allEqualitiesOfBin; 458 } 459 460 Console.println(""); 461 Console.print("complete recall is "); 462 dump(allEqualities, taskCounter, "ALL"); 463 Console.println(""); 464 } 465 466 /** 467 * 468 */ 469 private int[][] getBinsOfAlmostEqualSize() { 462 outputs[outputIndex++] = new String[] 463 { "--> to " + allInBin2 + " tasks with " + lowerBorder2 + 464 " to " + higherBorder2 + " covered events", format(count1, allInBin1), 465 format(count2, allInBin1), format(count3, allInBin1), 466 format(count1 + count2 + count3, allInBin1), format(count4, allInBin1), 467 format(count1 + count2 + count3 + count4, allInBin1) 468 }; 469 470 lexicalEqualitiesOfBin += count1; 471 syntacticalEqualitiesOfBin += count2; 472 semanticalEqualitiesOfBin += count3; 473 similaritiesOfBin += count4; 474 475 csvData.append(';'); 476 csvData.append(percentFormat.format((double) count1 / allInBin1)); 477 csvData.append(';'); 478 csvData.append(percentFormat.format((double) count2 / allInBin1)); 479 csvData.append(';'); 480 csvData.append(percentFormat.format((double) count3 / allInBin1)); 481 csvData.append(';'); 482 csvData.append(percentFormat.format 483 ((double) (count1 + count2 + count3) / allInBin1)); 484 csvData.append(';'); 485 csvData.append(percentFormat.format((double) count4 / allInBin1)); 486 csvData.append(';'); 487 csvData.append(percentFormat.format 488 ((double) (count1 + count2 + count3 + count4) / allInBin1)); 489 } 490 491 outputs[outputIndex++] = new String[] 492 { "--> all recalls", format(lexicalEqualitiesOfBin, allInBin1), 493 format(syntacticalEqualitiesOfBin, allInBin1), 494 format(semanticalEqualitiesOfBin, allInBin1), 495 format(lexicalEqualitiesOfBin + syntacticalEqualitiesOfBin + 496 semanticalEqualitiesOfBin, allInBin1), 497 format(similaritiesOfBin, allInBin1), 498 format(lexicalEqualitiesOfBin + syntacticalEqualitiesOfBin + 499 semanticalEqualitiesOfBin + similaritiesOfBin, allInBin1) 500 }; 501 502 503 csvData.append(';'); 504 csvData.append(percentFormat.format((double) lexicalEqualitiesOfBin / allInBin1)); 505 csvData.append(';'); 506 csvData.append(percentFormat.format((double) syntacticalEqualitiesOfBin / allInBin1)); 507 csvData.append(';'); 508 csvData.append(percentFormat.format((double) semanticalEqualitiesOfBin / allInBin1)); 509 csvData.append(';'); 510 csvData.append(percentFormat.format 511 ((double) (lexicalEqualitiesOfBin + syntacticalEqualitiesOfBin + 512 semanticalEqualitiesOfBin) / allInBin1)); 513 csvData.append(';'); 514 csvData.append(percentFormat.format((double) similaritiesOfBin / allInBin1)); 515 csvData.append(';'); 516 csvData.append(percentFormat.format 517 ((double) (lexicalEqualitiesOfBin + syntacticalEqualitiesOfBin + 518 semanticalEqualitiesOfBin + similaritiesOfBin) / 519 allInBin1)); 520 521 allEqualities += lexicalEqualitiesOfBin + syntacticalEqualitiesOfBin + 522 semanticalEqualitiesOfBin + similaritiesOfBin; 523 524 outputIndex++; 525 } 526 527 outputs[outputIndex++] = new String[] 528 { "complete recall is", null, null, null, null, null, 529 format(allEqualities, taskCounter1) 530 }; 531 532 csvData.append(';'); 533 csvData.append(percentFormat.format((double) allEqualities / taskCounter1)); 534 535 dump(outputs); 536 Console.println("\nCSV: " + csvData); 537 } 538 539 /** 540 * 541 */ 542 private void dump(String[][] outputs) { 543 int[] lengths = new int[outputs[0].length]; 544 545 for (String[] line : outputs) { 546 if (line != null) { 547 for (int i = 0; i < line.length; i++) { 548 if (line[i] != null) { 549 lengths[i] = Math.max(lengths[i], line[i].length()); 550 } 551 } 552 } 553 } 554 555 for (String[] line : outputs) { 556 StringBuffer toWrite = new StringBuffer(); 557 558 if (line != null) { 559 for (int i = 0; i < line.length; i++) { 560 if (i > 0) { 561 toWrite.append(" | "); 562 } 563 564 String text = line[i]; 565 566 if (text == null) { 567 text = ""; 568 } 569 570 for (int j = 0; j < (lengths[i] - text.length()); j++) { 571 toWrite.append(' '); 572 } 573 574 toWrite.append(text); 575 } 576 } 577 578 Console.println(toWrite.toString()); 579 } 580 } 581 582 /** 583 * 584 */ 585 private int[][] getBinsOfAlmostEqualSize(Map<Integer, Integer> coverageCounters, 586 int taskCounter, 587 int maxCoverage) 588 { 470 589 int[][] result = new int[5][]; 471 590 … … 500 619 * 501 620 */ 502 private void dump(int noOfEqualTasks, int noOfAllTasks, String prefix) { 503 Console.print(prefix); 504 Console.print("\t: "); 505 621 private String format(int noOfEqualTasks, int noOfAllTasks) { 622 StringBuffer result = new StringBuffer(); 506 623 if (noOfAllTasks > 0) { 507 624 double value = ((double) (noOfEqualTasks * 100)) / noOfAllTasks; 508 Console.print(noOfEqualTasks + " ("); 509 Console.print(new DecimalFormat("###.#").format(value)); 510 Console.print("%)"); 625 result.append(noOfEqualTasks); 626 result.append(" ("); 627 result.append(new DecimalFormat("##0.0").format(value)); 628 result.append("%)"); 511 629 } 512 630 else { 513 Console.print("n.a."); 514 } 631 result.append("n.a."); 632 } 633 634 return result.toString(); 515 635 } 516 636 … … 550 670 * 551 671 */ 552 private int countAllInBin(int lowerBorder 1, int higherBorder1) {672 private int countAllInBin(int lowerBorder, int higherBorder) { 553 673 int coverageCounter = 0; 554 674 555 for (int i = lowerBorder 1; i <= higherBorder1; i++) {556 Integer value = coverageCounters .get(i);675 for (int i = lowerBorder; i <= higherBorder; i++) { 676 Integer value = coverageCounters1.get(i); 557 677 558 678 if (value != null) { … … 631 751 SimilarTasks similarity; 632 752 753 // store coverage infos for models 754 for (ISequence task : tasks1) { 755 statistics.addCoverageCounter(task, model1); 756 } 757 758 for (ISequence task : tasks2) { 759 statistics.addCoverageCounter(task, model2); 760 } 761 633 762 List<ISequence> tasksToCompareWith = new ArrayList<ISequence>(); 634 763 StopWatch watch = new StopWatch();
Note: See TracChangeset
for help on using the changeset viewer.