Newer
Older
MagnetRON / src / org / ntlab / featureLocator / ScenarioBasedProbabilisticRanking.java
Aki Hongo on 3 Mar 2020 5 KB first commit
  1. package org.ntlab.featureLocator;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5.  
  6. import org.ntlab.trace.MethodExecution;
  7. import org.ntlab.trace.Trace;
  8.  
  9. public class ScenarioBasedProbabilisticRanking {
  10.  
  11. public static void main(String[] args) {
  12. Trace positiveTraces[] = new Trace[4];
  13. Trace negativeTraces[] = new Trace[4];
  14. long starts[] = new long[4];
  15. long ends[] = new long[4];
  16. positiveTraces[0] = new Trace("documents\\jEdit1578785TC1-2.trace");
  17. positiveTraces[1] = new Trace("documents\\jEdit1578785TC2-2.trace");
  18. positiveTraces[2] = new Trace("documents\\jEdit1578785TC3-2.trace");
  19. positiveTraces[3] = new Trace("documents\\jEdit1578785TC4-2.trace");
  20. negativeTraces[0] = new Trace("documents\\jEdit1578785TC1-1.trace");
  21. negativeTraces[1] = new Trace("documents\\jEdit1578785TC2-1.trace");
  22. negativeTraces[2] = new Trace("documents\\jEdit1578785TC3-1.trace");
  23. negativeTraces[3] = new Trace("documents\\jEdit1578785TC4-1.trace");
  24. starts[0] = 53110313578062L;
  25. ends[0] = 53114687756752L;
  26. starts[1] = 53656181043072L;
  27. ends[1] = 53662323812706L;
  28. starts[2] = 56259479424073L;
  29. ends[2] = 56263910205683L;
  30. starts[3] = 56003167357539L;
  31. ends[3] = 56009513891913L;
  32. HashMap<String, Integer> totalExecutionsInPositiveTraces = new HashMap<>();
  33. HashMap<String, Integer> totalExecutionsInNegativeTraces = new HashMap<>();
  34. HashMap<String, Integer> totalExecutionsInsideMark = new HashMap<>();
  35. HashMap<String, Integer> totalExecutionsOutsideMark = new HashMap<>();
  36. long insideMarkExecutions = 0L;
  37. long outsideMarkExecutions = 0L;
  38. for (int n = 0; n < positiveTraces.length; n++) {
  39. HashMap<String, ArrayList<MethodExecution>> positiveExecutions = positiveTraces[n].getAllMethodExecutions();
  40. for (String method: positiveExecutions.keySet()) {
  41. int positive = positiveExecutions.get(method).size();
  42. if (totalExecutionsInPositiveTraces.get(method) == null) {
  43. totalExecutionsInPositiveTraces.put(method, positive);
  44. } else {
  45. totalExecutionsInPositiveTraces.put(method, positive + totalExecutionsInPositiveTraces.get(method));
  46. }
  47. }
  48. HashMap<String, ArrayList<MethodExecution>> negativeExecutions = negativeTraces[n].getAllMethodExecutions();
  49. for (String method: negativeExecutions.keySet()) {
  50. int negatives = negativeExecutions.get(method).size();
  51. if (totalExecutionsInNegativeTraces.get(method) == null) {
  52. totalExecutionsInNegativeTraces.put(method, negatives);
  53. totalExecutionsOutsideMark.put(method, negatives);
  54. } else {
  55. totalExecutionsInNegativeTraces.put(method, negatives + totalExecutionsInNegativeTraces.get(method));
  56. totalExecutionsOutsideMark.put(method, negatives + totalExecutionsOutsideMark.get(method));
  57. }
  58. outsideMarkExecutions += negatives;
  59. }
  60. HashMap<String, ArrayList<MethodExecution>> positiveMarkedExecutions = positiveTraces[n].getMarkedMethodExecutions(starts[n], ends[n]);
  61. for (String method: positiveMarkedExecutions.keySet()) {
  62. int marked = positiveMarkedExecutions.get(method).size();
  63. if (totalExecutionsInsideMark.get(method) == null) {
  64. totalExecutionsInsideMark.put(method, marked);
  65. } else {
  66. totalExecutionsInsideMark.put(method, marked + totalExecutionsInsideMark.get(method));
  67. }
  68. insideMarkExecutions += marked;
  69. }
  70. HashMap<String, ArrayList<MethodExecution>> positiveUnmarkedExecutions = positiveTraces[n].getUnmarkedMethodExecutions(starts[n], ends[n]);
  71. for (String method: positiveUnmarkedExecutions.keySet()) {
  72. int unmarked = positiveUnmarkedExecutions.get(method).size();
  73. if (totalExecutionsOutsideMark.get(method) == null) {
  74. totalExecutionsOutsideMark.put(method, unmarked);
  75. } else {
  76. totalExecutionsOutsideMark.put(method, unmarked + totalExecutionsOutsideMark.get(method));
  77. }
  78. outsideMarkExecutions += unmarked;
  79. }
  80. }
  81. // An approach to feature location in distributed systems (Edwards‚ç, Journal of Systems and Software 2006)
  82. System.out.println("=== An approach to feature location in distributed systems ===");
  83. HashMap<String, Double> relevanceIndexes = new HashMap<>();
  84. for (String method: totalExecutionsInPositiveTraces.keySet()) {
  85. if (totalExecutionsInNegativeTraces.get(method) == null) continue;
  86. double positive = (double)totalExecutionsInPositiveTraces.get(method);
  87. double negative = (double)totalExecutionsInNegativeTraces.get(method);
  88. double relevanceIndex = positive / (positive + negative);
  89. relevanceIndexes.put(method, relevanceIndex);
  90. System.out.println(method + ":" + relevanceIndex);
  91. }
  92. // Scenario-Based Probabilistic Ranking (SPR, Antoniol‚ç, ICSM 2006)
  93. System.out.println("=== Scenario-Based Probabilistic Ranking ===");
  94. HashMap<String, Double> relevanceIndexesSPR = new HashMap<>();
  95. for (String method: totalExecutionsInsideMark.keySet()) {
  96. if (totalExecutionsOutsideMark.get(method) == null) continue;
  97. double mark = (double)totalExecutionsInsideMark.get(method) / (double)insideMarkExecutions;
  98. double unmark = (double)totalExecutionsOutsideMark.get(method) / (double)outsideMarkExecutions;
  99. double relevanceIndexSPR = mark / (mark + unmark);
  100. relevanceIndexesSPR.put(method, relevanceIndexSPR);
  101. System.out.println(method + ":" + relevanceIndexSPR);
  102. }
  103. }
  104.  
  105. }