- Timestamp:
- 05/25/14 16:51:10 (11 years ago)
- Location:
- branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/SmithWaterman.java
r1554 r1555 69 69 this.submat = submat; 70 70 71 System.out.println("Starting SmithWaterman algorithm with a "72 + submat.getClass() + " Substitution Matrix: " + submat.getClass().getCanonicalName());71 //System.out.println("Starting SmithWaterman algorithm with a " 72 // + submat.getClass() + " Substitution Matrix: " + submat.getClass().getCanonicalName()); 73 73 scoreThreshold = 20; 74 74 score = new double[length1 + 1][length2 + 1]; … … 90 90 private double similarity(int i, int j) { 91 91 if (i == 0 || j == 0) { 92 // it's a gap (indel)92 // it's a gap 93 93 return submat.getGapPenalty(); 94 94 } … … 97 97 // return (input1[i - 1] == input2[j - 1]) ? MATCH_SCORE : 98 98 // MISMATCH_SCORE; 99 return submat.getDistance(i - 1, j - 1);99 return submat.getDistance(input1[i - 1], input2[j - 1]); 100 100 } 101 101 … … 279 279 */ 280 280 public void printDPMatrix() { 281 System.out.print(" ");281 System.out.print(" "); 282 282 for (int j = 1; j <= length2; j++) 283 System.out. print(" " +input2[j - 1]);283 System.out.format("%5d", input2[j - 1]); 284 284 System.out.println(); 285 285 for (int i = 0; i <= length1; i++) { 286 286 if (i > 0) 287 System.out.print(input1[i - 1] + " "); 288 else 289 System.out.print(" "); 287 System.out.format("%5d ",input1[i - 1]); 288 else{ 289 System.out.print(" "); 290 } 290 291 for (int j = 0; j <= length2; j++) { 291 System.out. print(score[i][j] + " ");292 System.out.format("%4.1f ",score[i][j]); 292 293 } 293 294 System.out.println(); -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/substitution/ObjectDistanceSubstitionMatrix.java
r1554 r1555 26 26 private TriangleMatrix matrix; 27 27 private SymbolMap<ITaskInstance, ITask> uniqueTasks; 28 28 private float gapPenalty; 29 private float positiveThreshold; 30 29 31 public ObjectDistanceSubstitionMatrix( 30 32 SymbolMap<ITaskInstance, ITask> uniqueTasks) { … … 32 34 idmapping = new HashMap<Integer, Integer>(); 33 35 matrix = new TriangleMatrix(uniqueTasks.size()+1); 36 gapPenalty = -10; 37 //Todo: Calculate this value (the mean distance between every element) before 38 positiveThreshold =7; 34 39 } 35 40 36 41 @Override 37 42 public float getGapPenalty() { 38 // TODO Auto-generated method stub 39 return 0; 43 return gapPenalty; 40 44 } 41 45 42 46 @Override 43 47 public void generate() { 44 int i = 0; 48 int index = 0; 49 float meandistance = 0; 45 50 for (Iterator<ITaskInstance> it = uniqueTasks.getSymbols().iterator(); it 46 51 .hasNext();) { … … 50 55 eti1 = (IEventTaskInstance) obj1; 51 56 } 52 int j = 0;57 53 58 for (Iterator<ITaskInstance> jt = uniqueTasks.getSymbols() 54 59 .iterator(); jt.hasNext();) { … … 60 65 IGUIElement first = (IGUIElement) eti1.getEvent().getTarget(); 61 66 IGUIElement second = (IGUIElement) eti2.getEvent().getTarget(); 62 idmapping.put(eti1.getTask().getId(), i); 63 idmapping.put(eti2.getTask().getId(), j); 64 matrix.set(i, j, AlignmentHelpers.distanceBetween(first, second)); 65 j++; 67 int tempindex1 = -1; 68 int tempindex2 = -1; 69 if(!idmapping.containsKey(eti1.getTask().getId())) 70 { 71 idmapping.put(eti1.getTask().getId(), index); 72 tempindex1 = index; 73 index++; 74 } 75 else 76 { 77 tempindex1 = idmapping.get(eti1.getTask().getId()); 78 } 79 if(!idmapping.containsKey(eti2.getTask().getId())) 80 { 81 idmapping.put(eti2.getTask().getId(), index); 82 tempindex2 = index; 83 index++; 84 } 85 else 86 { 87 tempindex2 = idmapping.get(eti2.getTask().getId()); 88 } 89 float distance = AlignmentHelpers.distanceBetween(first, second); 90 meandistance += distance; 91 92 if (distance > positiveThreshold) { 93 distance = -1*distance; 94 } 95 matrix.set(tempindex1, tempindex2,distance); 96 66 97 } 67 i++;68 98 } 99 System.out.println(meandistance/(uniqueTasks.size()*uniqueTasks.size())); 100 //System.out.println(idmapping.toString()); 101 //System.out.println(matrix.toString()); 102 //System.out.println(idmapping.keySet().toString()); 103 //System.out.println(idmapping.values().toString()); 104 69 105 } 70 106 71 107 @Override 72 108 public float getDistance(int taskId1, int taskId2) { 109 //System.out.println("Taskid1: " + taskId1 + " Taskid2: " + taskId2 + " Idmapping1: " + idmapping.get(taskId1) + " Idmapping2: " + idmapping.get(taskId2)); 110 73 111 return matrix.get(idmapping.get(taskId1),idmapping.get(taskId2)); 74 112 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/substitution/TriangleMatrix.java
r1554 r1555 8 8 public TriangleMatrix(int size) { 9 9 this.size = size; 10 matrix = new float [size*(size+1)/2];10 matrix = new float [size*(size+1)/2]; 11 11 } 12 12 … … 24 24 } 25 25 26 27 26 28 27 29 //Note: String just looks good for small. testing matrices -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
r1554 r1555 123 123 this.preparationTaskHandlingStrategy = new TaskHandlingStrategy(minimalTaskEquality); 124 124 this.identityTaskHandlingStrategy = new TaskHandlingStrategy(TaskEquality.IDENTICAL); 125 numberseqs = new ArrayList<NumberSequence>(); 125 126 126 127 } … … 140 141 public RuleApplicationResult apply(List<IUserSession> sessions) { 141 142 RuleApplicationData appData = new RuleApplicationData(sessions); 142 numberseqs = new ArrayList<NumberSequence>();143 143 144 144 145 145 146 146 147 // this is the real rule application. Loop while something is replaced. 147 SymbolMap<ITaskInstance, ITask> uniqueTasks = harmonizeEventTaskInstancesModel(appData ,numberseqs);148 SymbolMap<ITaskInstance, ITask> uniqueTasks = harmonizeEventTaskInstancesModel(appData); 148 149 ObjectDistanceSubstitionMatrix submat = new ObjectDistanceSubstitionMatrix(uniqueTasks); 149 150 submat.generate(); 150 151 151 152 SmithWaterman sm = new SmithWaterman(numberseqs.get(0).getSequence(), numberseqs.get(0).getSequence(), submat); 152 SmithWaterman sm = new SmithWaterman(numberseqs.get(1).getSequence(), numberseqs.get(1).getSequence(), submat); 153 153 sm.printDPMatrix(); 154 154 … … 201 201 * @return Returns the unique tasks symbol map 202 202 */ 203 private SymbolMap<ITaskInstance, ITask> harmonizeEventTaskInstancesModel(RuleApplicationData appData , ArrayList<NumberSequence> numberseqs) {203 private SymbolMap<ITaskInstance, ITask> harmonizeEventTaskInstancesModel(RuleApplicationData appData) { 204 204 Console.traceln(Level.INFO, "harmonizing task model of event task instances"); 205 205 appData.getStopWatch().start("harmonizing event tasks");
Note: See TracChangeset
for help on using the changeset viewer.