Changeset 1919


Ignore:
Timestamp:
03/12/15 15:51:31 (9 years ago)
Author:
pharms
Message:
  • extended comparison for case study of INTERACT 2015 paper
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/usability/CMDgetTaskModelSimilarity.java

    r1895 r1919  
    8484        Map<ITaskModel, List<ISequence>> inputTaskModels = new IdentityHashMap<>(); 
    8585         
     86        ITaskModel firstModel = null; 
     87         
    8688        for (String inputTaskTreeName : inputTaskTreeNames) { 
    8789            Object dataObject = GlobalDataContainer.getInstance().getData(inputTaskTreeName); 
     
    104106             
    105107            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); 
    114115    } 
    115116 
     
    117118     * 
    118119     */ 
    119     private void getTaskModelSimilarity(Map<ITaskModel, List<ISequence>> inputTaskModels, 
    120                                         SimilarityStatistics             statistics) 
     120    private void getTaskModelSimilarity(ITaskModel                       modelToCompare, 
     121                                        Map<ITaskModel, List<ISequence>> inputTaskModels) 
    121122    { 
    122123        // create the indexes to not do too many comparisons 
     
    188189        List<ComparisonRunnable> runnables = new LinkedList<>(); 
    189190         
    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)); 
    201201            } 
    202202        } 
     
    250250         
    251251        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)"); 
    254255            runnable.getStatistics().dump(); 
    255             statistics.mergeWith(runnable.getStatistics()); 
    256256        } 
    257257    } 
     
    263263         
    264264        /**  */ 
    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; 
    269272         
    270273        /**  */ 
    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<>(); 
    272287         
    273288        /**  */ 
    274289        private Map<Integer, Map<Integer, Map<TaskEquality, Integer>>> equalityCounters = 
    275290            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        } 
    276316         
    277317        /** 
     
    284324                           TaskEquality equality) 
    285325        { 
    286             int coverageRatio1 = 
    287                 model.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE); 
     326            int coverageRatio1 = model.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE); 
    288327            int coverageRatio2 = 
    289328                otherModel.getTaskInfo(other).getMeasureValue(TaskMetric.EVENT_COVERAGE); 
    290329             
    291             addToMaps(coverageRatio1, 1); 
    292330            addToMaps(coverageRatio1, coverageRatio2, equality, 1); 
    293             taskCounter++; 
    294             maxCoverage = Math.max(maxCoverage, coverageRatio1); 
    295331        } 
    296332         
     
    299335         */ 
    300336        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             
    305339            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) { 
    339346            Integer counter = coverageCounters.get(ratio); 
    340347 
     
    382389            Console.println("========================"); 
    383390             
    384             int[][] bins = getBinsOfAlmostEqualSize(); 
     391            int[][] bins1 = getBinsOfAlmostEqualSize(coverageCounters1, taskCounter1, maxCoverage1); 
     392            int[][] bins2 = getBinsOfAlmostEqualSize(coverageCounters2, taskCounter2, maxCoverage2); 
    385393            int lowerBorder1; 
    386394            int higherBorder1; 
    387395            int lowerBorder2; 
    388396            int higherBorder2; 
    389             int allEqualitiesOfBin = 0; 
     397            int lexicalEqualitiesOfBin = 0; 
     398            int syntacticalEqualitiesOfBin = 0; 
     399            int semanticalEqualitiesOfBin = 0; 
     400            int similaritiesOfBin = 0; 
    390401            int allEqualities = 0; 
    391402             
    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--) { 
    393413                if (i <= 0) { 
    394414                    lowerBorder1 = 0; 
    395415                } 
    396416                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--) { 
    408437                    if (j <= 0) { 
    409438                        lowerBorder2 = 0; 
    410439                    } 
    411440                    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); 
    422449 
    423450                    int count1 = countEqualities(lowerBorder1, higherBorder1, lowerBorder2, 
    424451                                                 higherBorder2, TaskEquality.LEXICALLY_EQUAL); 
    425                      
    426                     dump(count1, allInBin, "LEX"); 
    427                     Console.print("\t| "); 
    428452 
    429453                    int count2 = countEqualities(lowerBorder1, higherBorder1, lowerBorder2, 
    430454                                                 higherBorder2, TaskEquality.SYNTACTICALLY_EQUAL); 
    431455 
    432                     dump(count2, allInBin, "SYN"); 
    433                     Console.print("\t| "); 
    434  
    435456                    int count3 = countEqualities(lowerBorder1, higherBorder1, lowerBorder2, 
    436457                                                 higherBorder2, TaskEquality.SEMANTICALLY_EQUAL); 
    437458                     
    438                     dump(count3, allInBin, "SEM"); 
    439                     Console.print("\t|| "); 
    440  
    441459                    int count4 = countEqualities(lowerBorder1, higherBorder1, lowerBorder2, 
    442460                                                 higherBorder2, null); 
    443461                     
    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        { 
    470589            int[][] result = new int[5][]; 
    471590             
     
    500619         * 
    501620         */ 
    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(); 
    506623            if (noOfAllTasks > 0) { 
    507624                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("%)"); 
    511629            } 
    512630            else { 
    513                 Console.print("n.a."); 
    514             } 
     631                result.append("n.a."); 
     632            } 
     633             
     634            return result.toString(); 
    515635        } 
    516636 
     
    550670         * 
    551671         */ 
    552         private int countAllInBin(int lowerBorder1, int higherBorder1) { 
     672        private int countAllInBin(int lowerBorder, int higherBorder) { 
    553673            int coverageCounter = 0; 
    554674             
    555             for (int i = lowerBorder1; i <= higherBorder1; i++) { 
    556                 Integer value = coverageCounters.get(i); 
     675            for (int i = lowerBorder; i <= higherBorder; i++) { 
     676                Integer value = coverageCounters1.get(i); 
    557677                 
    558678                if (value != null) { 
     
    631751            SimilarTasks similarity; 
    632752 
     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             
    633762            List<ISequence> tasksToCompareWith = new ArrayList<ISequence>(); 
    634763            StopWatch watch = new StopWatch(); 
Note: See TracChangeset for help on using the changeset viewer.