Changeset 1933
- Timestamp:
- 03/27/15 13:26:18 (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
r1919 r1933 31 31 import de.ugoe.cs.autoquest.tasktrees.temporalrelation.TaskComparator; 32 32 import de.ugoe.cs.autoquest.tasktrees.temporalrelation.utils.SimilarTasks; 33 import de.ugoe.cs.autoquest.tasktrees.temporalrelation.utils.TaskTraversal; 33 34 import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskTraversingVisitor; 34 35 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 35 36 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; 37 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 38 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 36 39 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 37 40 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; … … 125 128 new IdentityHashMap<>(); 126 129 127 Map<ISequence, Integer> index2 = new HashMap<>(); 128 Map<ISequence, IEventTarget> index3 = new HashMap<>(); 130 Map<ISequence, Integer> lengthIndex = new HashMap<>(); 131 Map<ISequence, IEventTarget> firstTargetIndex = new HashMap<>(); 132 Map<ISequence, TaskTraversal> taskTraversalIndex = new HashMap<>(); 129 133 130 134 final List<IEventTask> terminalNodes = new ArrayList<>(); … … 181 185 182 186 compareList.add(sequence); 183 index2.put(sequence, length); 184 index3.put(sequence, firstTarget); 187 lengthIndex.put(sequence, length); 188 firstTargetIndex.put(sequence, firstTarget); 189 taskTraversalIndex.put(sequence, TaskTraversal.getTraversal(sequence, null)); 185 190 } 186 191 } … … 196 201 Collections.unmodifiableMap 197 202 (index1.get(model2.getKey())), 198 Collections.unmodifiableMap(index2), 199 Collections.unmodifiableMap(index3), 203 Collections.unmodifiableMap(lengthIndex), 204 Collections.unmodifiableMap(firstTargetIndex), 205 Collections.unmodifiableMap(taskTraversalIndex), 200 206 runnables)); 201 207 } … … 395 401 int lowerBorder2; 396 402 int higherBorder2; 403 int identicalEqualitiesOfBin = 0; 397 404 int lexicalEqualitiesOfBin = 0; 398 405 int syntacticalEqualitiesOfBin = 0; … … 410 417 csvData.append(taskCounter2); 411 418 412 for (int i = bins1.length - 1; i >= 0 ; i--) {413 if (i <= 0) {414 lowerBorder1 = 0;419 for (int i = 0; i < bins1.length; i++) { 420 if (i == 0) { 421 higherBorder1 = maxCoverage1; 415 422 } 416 423 else { 417 lowerBorder1 = bins1[i - 1][0] +1;418 } 419 420 higherBorder1 = bins1[i][0];421 422 int allInBin1 = countAllInBin(lowerBorder1, higherBorder1); 424 higherBorder1 = bins1[i - 1][0] - 1; 425 } 426 427 lowerBorder1 = bins1[i][0]; 428 int allInBin1 = bins1[i][1]; 429 423 430 csvData.append(';'); 424 431 csvData.append(allInBin1); 425 432 433 identicalEqualitiesOfBin = 0; 426 434 lexicalEqualitiesOfBin = 0; 427 435 syntacticalEqualitiesOfBin = 0; … … 431 439 outputs[outputIndex++] = new String[] 432 440 { "similarities of " + bins1[i][1] + " tasks with " + lowerBorder1 + 433 " to " + higherBorder1 + " covered events", " LEX", "SYN", "SEM",441 " to " + higherBorder1 + " covered events", "IDENT", "LEX", "SYN", "SEM", 434 442 "ALL EQUAL", "SIM", "ALL" }; 435 443 436 for (int j = bins2.length - 1; j >= 0; j--) {437 if (j <= 0) {438 lowerBorder2 = 0;444 for (int j = 0; j < bins2.length; j++) { 445 if (j == 0) { 446 higherBorder2 = maxCoverage2; 439 447 } 440 448 else { 441 lowerBorder2 = bins2[j - 1][0] +1;442 } 443 444 higherBorder2 = bins2[j][0];445 446 int allInBin2 = countAllInBin(lowerBorder2, higherBorder2);449 higherBorder2 = bins2[j - 1][0] - 1; 450 } 451 452 lowerBorder2 = bins2[j][0]; 453 int allInBin2 = bins2[j][1]; 454 447 455 csvData.append(';'); 448 456 csvData.append(allInBin2); 449 457 450 458 int count1 = countEqualities(lowerBorder1, higherBorder1, lowerBorder2, 459 higherBorder2, TaskEquality.IDENTICAL); 460 461 int count2 = countEqualities(lowerBorder1, higherBorder1, lowerBorder2, 451 462 higherBorder2, TaskEquality.LEXICALLY_EQUAL); 452 463 453 int count 2= countEqualities(lowerBorder1, higherBorder1, lowerBorder2,464 int count3 = countEqualities(lowerBorder1, higherBorder1, lowerBorder2, 454 465 higherBorder2, TaskEquality.SYNTACTICALLY_EQUAL); 455 466 456 int count 3= countEqualities(lowerBorder1, higherBorder1, lowerBorder2,467 int count4 = countEqualities(lowerBorder1, higherBorder1, lowerBorder2, 457 468 higherBorder2, TaskEquality.SEMANTICALLY_EQUAL); 458 469 459 int count 4= countEqualities(lowerBorder1, higherBorder1, lowerBorder2,470 int count5 = countEqualities(lowerBorder1, higherBorder1, lowerBorder2, 460 471 higherBorder2, null); 461 472 … … 464 475 " to " + higherBorder2 + " covered events", format(count1, allInBin1), 465 476 format(count2, allInBin1), format(count3, allInBin1), 466 format(count1 + count2 + count3, allInBin1), format(count4, allInBin1), 467 format(count1 + count2 + count3 + count4, allInBin1) 477 format(count4, allInBin1), 478 format(count1 + count2 + count3 + count4, allInBin1), 479 format(count5, allInBin1), 480 format(count1 + count2 + count3 + count4 + count5, allInBin1) 468 481 }; 469 482 470 lexicalEqualitiesOfBin += count1; 471 syntacticalEqualitiesOfBin += count2; 472 semanticalEqualitiesOfBin += count3; 473 similaritiesOfBin += count4; 483 identicalEqualitiesOfBin += count1; 484 lexicalEqualitiesOfBin += count2; 485 syntacticalEqualitiesOfBin += count3; 486 semanticalEqualitiesOfBin += count4; 487 similaritiesOfBin += count5; 474 488 475 489 csvData.append(';'); … … 480 494 csvData.append(percentFormat.format((double) count3 / allInBin1)); 481 495 csvData.append(';'); 482 csvData.append(percentFormat.format483 ((double) (count1 + count2 + count3) / allInBin1));484 csvData.append(';');485 496 csvData.append(percentFormat.format((double) count4 / allInBin1)); 486 497 csvData.append(';'); 487 498 csvData.append(percentFormat.format 488 499 ((double) (count1 + count2 + count3 + count4) / allInBin1)); 500 csvData.append(';'); 501 csvData.append(percentFormat.format((double) count5 / allInBin1)); 502 csvData.append(';'); 503 csvData.append(percentFormat.format 504 ((double) (count1 + count2 + count3 + count4 + count5) / allInBin1)); 489 505 } 490 506 491 507 outputs[outputIndex++] = new String[] 492 { "--> all recalls", format(lexicalEqualitiesOfBin, allInBin1), 508 { "--> all recalls", format(identicalEqualitiesOfBin, allInBin1), 509 format(lexicalEqualitiesOfBin, allInBin1), 493 510 format(syntacticalEqualitiesOfBin, allInBin1), 494 511 format(semanticalEqualitiesOfBin, allInBin1), 495 format( lexicalEqualitiesOfBin + syntacticalEqualitiesOfBin +496 s emanticalEqualitiesOfBin, allInBin1),512 format(identicalEqualitiesOfBin + lexicalEqualitiesOfBin + 513 syntacticalEqualitiesOfBin + semanticalEqualitiesOfBin, allInBin1), 497 514 format(similaritiesOfBin, allInBin1), 498 format(lexicalEqualitiesOfBin + syntacticalEqualitiesOfBin + 499 semanticalEqualitiesOfBin + similaritiesOfBin, allInBin1) 515 format(identicalEqualitiesOfBin + lexicalEqualitiesOfBin + 516 syntacticalEqualitiesOfBin + semanticalEqualitiesOfBin + 517 similaritiesOfBin, allInBin1) 500 518 }; 501 519 502 520 521 csvData.append(';'); 522 csvData.append(percentFormat.format((double) identicalEqualitiesOfBin / allInBin1)); 503 523 csvData.append(';'); 504 524 csvData.append(percentFormat.format((double) lexicalEqualitiesOfBin / allInBin1)); … … 509 529 csvData.append(';'); 510 530 csvData.append(percentFormat.format 511 ((double) (lexicalEqualitiesOfBin + syntacticalEqualitiesOfBin + 512 semanticalEqualitiesOfBin) / allInBin1)); 531 ((double) (identicalEqualitiesOfBin + lexicalEqualitiesOfBin + 532 syntacticalEqualitiesOfBin + semanticalEqualitiesOfBin) 533 / allInBin1)); 513 534 csvData.append(';'); 514 535 csvData.append(percentFormat.format((double) similaritiesOfBin / allInBin1)); 515 536 csvData.append(';'); 516 537 csvData.append(percentFormat.format 517 ((double) ( lexicalEqualitiesOfBin + syntacticalEqualitiesOfBin +518 s emanticalEqualitiesOfBin + similaritiesOfBin) /519 allInBin1));520 521 allEqualities += lexicalEqualitiesOfBin + syntacticalEqualitiesOfBin +522 s emanticalEqualitiesOfBin + similaritiesOfBin;538 ((double) (identicalEqualitiesOfBin + lexicalEqualitiesOfBin + 539 syntacticalEqualitiesOfBin + semanticalEqualitiesOfBin + 540 similaritiesOfBin) / allInBin1)); 541 542 allEqualities += identicalEqualitiesOfBin + lexicalEqualitiesOfBin + 543 syntacticalEqualitiesOfBin + semanticalEqualitiesOfBin + similaritiesOfBin; 523 544 524 545 outputIndex++; … … 597 618 598 619 int index = 0; 599 600 for (int i = 0; i < maxCoverage; i++) { 620 int allCoverageCounterSum = 0; 621 622 for (int i = maxCoverage; i > 0; i--) { 601 623 if (result[index][1] > aimedBinSize) { 602 // try to compensate, if the previous bin was a little too large 603 aimedBinSize = averageBinSize + averageBinSize - result[index][1]; 624 if ((index + 2) < result.length) { 625 // try to compensate, if the previous bin was a little too large 626 aimedBinSize = averageBinSize + averageBinSize - result[index][1]; 627 } 628 else { 629 // put all remaining in the last bin 630 aimedBinSize = Integer.MAX_VALUE; 631 } 604 632 index++; 605 633 } … … 610 638 result[index][0] = i; 611 639 result[index][1] += value; 612 } 640 allCoverageCounterSum += value; 641 } 642 } 643 644 if (taskCounter != allCoverageCounterSum) { 645 throw new RuntimeException("bins do not cover all tasks"); 613 646 } 614 647 … … 666 699 return counter; 667 700 } 668 669 /**670 *671 */672 private int countAllInBin(int lowerBorder, int higherBorder) {673 int coverageCounter = 0;674 675 for (int i = lowerBorder; i <= higherBorder; i++) {676 Integer value = coverageCounters1.get(i);677 678 if (value != null) {679 coverageCounter += value;680 }681 }682 683 return coverageCounter;684 }685 701 } 686 702 … … 710 726 /** */ 711 727 private Map<ISequence, IEventTarget> firstTargetIndex; 728 729 /** */ 730 private Map<ISequence, TaskTraversal> traversalIndex; 712 731 713 732 /** */ … … 716 735 /** */ 717 736 private SimilarityStatistics statistics = new SimilarityStatistics(); 718 737 738 /** */ 739 private TaskEqualityRuleManager equalityRuleManager = TaskEqualityRuleManager.getInstance(); 740 719 741 /** 720 742 * … … 727 749 Map<ISequence, Integer> lengthIndex2, 728 750 Map<ISequence, IEventTarget> firstTargetIndex, 751 Map<ISequence, TaskTraversal> traversalIndex, 729 752 Object semaphore) 730 753 { … … 736 759 this.lengthIndex2 = lengthIndex2; 737 760 this.firstTargetIndex = firstTargetIndex; 761 this.traversalIndex = traversalIndex; 738 762 this.semaphore = semaphore; 739 763 } … … 744 768 @Override 745 769 public void run() { 746 TaskEqualityRuleManager equalityRuleManager = TaskEqualityRuleManager.getInstance();747 770 TaskComparator comparator = new TaskComparator(TaskEquality.SEMANTICALLY_EQUAL); 748 771 TaskEquality mostCommonEquality; 749 I TaskmostSimilarTask;772 ISequence mostSimilarTask; 750 773 TaskEquality equality; 751 774 SimilarTasks similarity; … … 764 787 watch.start("all comparisons "); 765 788 int count = 0; 789 int taskNo = 0; 790 int nextPercent = 10; 766 791 for (ISequence task : tasks1) { 767 792 int length = lengthIndex2.get(task); … … 795 820 mostSimilarTask = null; 796 821 797 for (I TasktaskToCompare : tasksToCompareWith) {822 for (ISequence taskToCompare : tasksToCompareWith) { 798 823 count++; 799 824 watch.start("normal comparison"); … … 824 849 825 850 if (mostCommonEquality != null) { 826 statistics.store(task, model1, mostSimilarTask, model2, mostCommonEquality); 851 // check, if both tasks are identical 852 if (!identicalTasks(task, mostSimilarTask)) { 853 statistics.store(task, model1, mostSimilarTask, model2, mostCommonEquality); 854 } 855 else { 856 statistics.store 857 (task, model1, mostSimilarTask, model2, TaskEquality.IDENTICAL); 858 } 827 859 } 828 860 else { 829 861 int lowestDiffLevel = Integer.MAX_VALUE; 830 for (ITask taskToCompare : tasksToCompareWith) { 862 TaskTraversal traversal1 = traversalIndex.get(task); 863 864 for (ISequence taskToCompare : tasksToCompareWith) { 831 865 count++; 832 866 watch.start("similarity comparison"); 833 similarity = SimilarTasks.compareTasks(task, taskToCompare, comparator); 867 TaskTraversal traversal2 = traversalIndex.get(taskToCompare); 868 similarity = 869 SimilarTasks.compareTraversals(traversal1, traversal2, comparator); 834 870 watch.stop("similarity comparison"); 835 871 … … 860 896 } 861 897 } 862 } 863 864 System.out.println("performed " + count + " comparisons"); 898 899 taskNo++; 900 901 if (((taskNo * 100) / tasks1.size()) > nextPercent) { 902 System.out.println("compared " + nextPercent + "% (" + taskNo + " tasks) of " + 903 model1 + " with " + tasks2.size() + " tasks of " + model2); 904 nextPercent += 10; 905 } 906 } 907 908 System.out.println("performed " + count + " comparisons for comparing " + model1 + 909 " with " + model2); 865 910 866 911 watch.stop("all comparisons "); … … 873 918 874 919 /** 920 * 921 */ 922 private boolean identicalTasks(ISequence sequence1, ISequence sequence2) { 923 if (sequence1.getChildren().size() != sequence2.getChildren().size()) { 924 return false; 925 } 926 927 for (int i = 0; i < sequence1.getChildren().size(); i++) { 928 if (!identicalTasks(sequence1.getChildren().get(i), sequence2.getChildren().get(i))) 929 { 930 return false; 931 } 932 } 933 934 return true; 935 } 936 937 /** 938 * 939 */ 940 private boolean identicalTasks(IIteration iteration1, IIteration iteration2) { 941 return identicalTasks(iteration1.getMarkedTask(), iteration2.getMarkedTask()); 942 } 943 944 /** 945 * 946 */ 947 private boolean identicalTasks(IOptional optional1, IOptional optional2) { 948 return identicalTasks(optional1.getMarkedTask(), optional2.getMarkedTask()); 949 } 950 951 /** 952 * 953 */ 954 private boolean identicalTasks(ISelection selection1, ISelection selection2) { 955 if (selection1.getChildren().size() != selection2.getChildren().size()) { 956 return false; 957 } 958 959 FIRST_SELECTION_CHILDREN: 960 for (ITask child1 : selection1.getChildren()) { 961 for (ITask child2 : selection2.getChildren()) { 962 if (identicalTasks(child1, child2)) { 963 continue FIRST_SELECTION_CHILDREN; 964 } 965 } 966 967 return false; 968 } 969 970 return true; 971 } 972 973 /** 974 * 975 */ 976 private boolean identicalTasks(IEventTask eventTask1, IEventTask eventTask2) { 977 return equalityRuleManager.compare(eventTask1, eventTask2).isAtLeast 978 (TaskEquality.SEMANTICALLY_EQUAL); 979 } 980 981 /** 982 * 983 */ 984 private boolean identicalTasks(ITask task1, ITask task2) { 985 if ((task1 instanceof ISequence) && (task2 instanceof ISequence)) { 986 return identicalTasks((ISequence) task1, (ISequence) task2); 987 } 988 else if ((task1 instanceof IIteration) && (task2 instanceof IIteration)) { 989 return identicalTasks((IIteration) task1, (IIteration) task2); 990 } 991 else if ((task1 instanceof IOptional) && (task2 instanceof IOptional)) { 992 return identicalTasks((IOptional) task1, (IOptional) task2); 993 } 994 else if ((task1 instanceof ISelection) && (task2 instanceof ISelection)) { 995 return identicalTasks((ISelection) task1, (ISelection) task2); 996 } 997 else if ((task1 instanceof IEventTask) && (task2 instanceof IEventTask)) { 998 return identicalTasks((IEventTask) task1, (IEventTask) task2); 999 } 1000 else { 1001 return false; 1002 } 1003 } 1004 1005 /** 875 1006 * @return the statistics 876 1007 */
Note: See TracChangeset
for help on using the changeset viewer.