Changeset 1621 for branches/ralph/src/main/java/de/ugoe/cs
- Timestamp:
- 07/27/14 20:28:19 (10 years ago)
- Location:
- branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/Match.java
r1620 r1621 2 2 3 3 import java.util.ArrayList; 4 import java.util.Iterator; 4 5 import java.util.LinkedList; 5 6 6 7 public class Match { 7 8 private ArrayList<NumberSequence> matchseqs; 8 9 private LinkedList<MatchOccurence> occurences; 10 11 12 Match(){ 9 10 private LinkedList<MatchOccurence> occurences; 11 12 Match() { 13 13 matchseqs = new ArrayList<NumberSequence>(2); 14 14 occurences = new LinkedList<MatchOccurence>(); … … 16 16 matchseqs.add(null); 17 17 } 18 18 19 19 public NumberSequence getFirstSequence() { 20 20 return matchseqs.get(0); 21 21 } 22 22 23 23 public NumberSequence getSecondSequence() { 24 24 return matchseqs.get(1); 25 25 } 26 26 27 27 public void setFirstSequence(NumberSequence seq) { 28 28 matchseqs.set(0, seq); 29 29 } 30 30 31 31 public void setSecondSequence(NumberSequence seq) { 32 32 matchseqs.set(1, seq); 33 33 } 34 34 35 35 public void addOccurence(MatchOccurence occurence) { 36 36 occurences.add(occurence); 37 37 } 38 38 39 39 public int occurenceCount() { 40 40 return occurences.size(); 41 } 41 } 42 43 public boolean equals(Match m) { 44 if ((m.getFirstSequence().equals(this.getFirstSequence()) || m 45 .getFirstSequence().equals(this.getSecondSequence())) 46 && (m.getSecondSequence().equals(this.getFirstSequence()) || m 47 .getSecondSequence().equals(this.getSecondSequence()))) { 48 return true; 49 } 50 return false; 51 } 52 53 public LinkedList<MatchOccurence> getOccurences() { 54 return occurences; 55 } 56 57 public void setOccurences(LinkedList<MatchOccurence> occurences) { 58 this.occurences = occurences; 59 } 60 61 62 public void addOccurencesOf(Match m) { 63 LinkedList<MatchOccurence> occ = m.getOccurences(); 64 occurences.addAll(occ); 65 } 42 66 43 67 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/NumberSequence.java
r1620 r1621 2 2 3 3 import java.util.ArrayList; 4 import java.util.LinkedList; 4 5 import java.util.Random; 5 6 … … 61 62 } 62 63 63 64 public int containsPattern(Match pattern) { 64 //Searching occurences of 65 public LinkedList<Integer> containsPattern(Match pattern) { 66 LinkedList<Integer> result = new LinkedList<Integer>(); 65 67 int i = 0; 66 int count = 0;67 68 int[] pat1 = pattern.getFirstSequence().getSequence(); 68 69 int[] pat2 = pattern.getSecondSequence().getSequence(); … … 88 89 ipat2++; 89 90 } 90 count++;91 result.add(i); 91 92 } 92 93 i++; 93 94 } 94 return count;95 return result; 95 96 } 96 97 … … 119 120 this.id = id; 120 121 } 122 123 public boolean equals(NumberSequence n) { 124 int[] seq = n.getSequence(); 125 if(n.size() !=this.size()) { 126 return false; 127 } 128 for (int i=0; i<n.size();i++) { 129 if(seq[i] != this.sequence[i]) { 130 return false; 131 } 132 } 133 return true; 134 } 135 136 121 137 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
r1620 r1621 16 16 17 17 import java.util.ArrayList; 18 import java.util.Collections; 19 import java.util.Comparator; 18 20 import java.util.HashMap; 19 21 import java.util.HashSet; … … 27 29 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithmFactory; 28 30 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.Match; 31 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.MatchOccurence; 29 32 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NumberSequence; 30 33 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.PairwiseAlignmentGenerator; … … 154 157 SymbolMap<ITaskInstance, ITask> uniqueTasks = harmonizeEventTaskInstancesModel(appData); 155 158 156 Console.traceln(Level.INFO,"generating substitution matrix"); 159 // Generate a substitution matrix between all occuring events. 160 Console.traceln(Level.INFO, "generating substitution matrix"); 157 161 ObjectDistanceSubstitionMatrix submat = new ObjectDistanceSubstitionMatrix( 158 uniqueTasks, 6, -3);162 uniqueTasks, 6, -3); 159 163 submat.generate(); 160 164 161 Console.traceln(Level.INFO,"generating pairwise alignments"); 162 ArrayList<Match> matchseqs = new ArrayList<Match>(); 163 PairwiseAlignmentStorage alignments = PairwiseAlignmentGenerator.generate(numberseqs,submat,9); 164 165 Console.traceln(Level.INFO,"retrieving significant sequence pieces"); 166 for (int i=0; i< numberseqs.size();i++) { 167 Console.traceln(Level.FINEST,"retrieving significant sequence pieces: " + Math.round((float)i/(float)numberseqs.size()*100) + "%"); 168 for(int j=0; j< numberseqs.size();j++) { 169 if(i != j) { 165 // Generate pairwise alignments 166 Console.traceln(Level.INFO, "generating pairwise alignments"); 167 LinkedList<Match> matchseqs = new LinkedList<Match>(); 168 PairwiseAlignmentStorage alignments = PairwiseAlignmentGenerator 169 .generate(numberseqs, submat, 9); 170 171 // Retrieve all matches reached a specific threshold 172 Console.traceln(Level.INFO, "retrieving significant sequence pieces"); 173 for (int i = 0; i < numberseqs.size(); i++) { 174 Console.traceln( 175 Level.FINEST, 176 "retrieving significant sequence pieces: " 177 + Math.round((float) i / (float) numberseqs.size() 178 * 100) + "%"); 179 for (int j = 0; j < numberseqs.size(); j++) { 180 if (i != j) { 170 181 matchseqs.addAll(alignments.get(i, j).getMatches()); 171 } 172 } 173 } 174 Console.traceln(Level.FINEST, "retrieving significant sequence pieces: 100%");175 182 } 183 } 184 } 185 Console.traceln(Level.FINEST, 186 "retrieving significant sequence pieces: 100%"); 176 187 Console.traceln(Level.INFO, "searching for patterns occuring most"); 177 188 178 // search thismatch in every other sequence179 for (int i=0; i < matchseqs.size();i++) {189 // search each match in every other sequence 190 for (Iterator<Match> it = matchseqs.iterator(); it.hasNext();) { 180 191 int sequencecount = 0; 181 192 int totalcount = 0; 182 Match pattern = matchseqs.get(i); 193 Match pattern = it.next(); 194 195 // Skip sequences with more 0 events (scrolls) than other events. 196 // Both of the pattern sequences are equally long, so the added 0 197 // counts 198 // just need to be smaller than the length of one sequence 199 if (pattern.getFirstSequence().eventCount(0) 200 + pattern.getSecondSequence().eventCount(0) + 1 > pattern 201 .getFirstSequence().size()) 202 continue; 203 204 for (int j = 0; j < numberseqs.size(); j++) { 205 LinkedList<Integer> startpositions = numberseqs.get(j) 206 .containsPattern(pattern); 207 if (startpositions.size() > 0) { 208 sequencecount++; 209 totalcount += startpositions.size(); 210 for (Iterator<Integer> jt = startpositions.iterator(); jt 211 .hasNext();) { 212 pattern.addOccurence( 213 new MatchOccurence(jt.next(), j)); 214 } 215 216 } 217 } 218 } 219 220 Console.traceln(Level.INFO, "sorting results"); 221 // Sort results to get the most occuring results 222 Comparator<Match> comparator = new Comparator<Match>() { 223 public int compare(Match m1, Match m2) { 224 return m2.occurenceCount() - m1.occurenceCount(); // use your 225 // logic 226 } 227 }; 228 Collections.sort(matchseqs, comparator); 229 230 231 232 233 // Harmonize matches: finding double matches and merge them 234 /* 235 Console.traceln(Level.INFO, "harmonizing matches"); 236 int i=0; 237 238 while(i<matchseqs.size()) { 239 int j=i; 240 while(j<matchseqs.size()) { 241 if(i!=j) { 242 if(matchseqs.get(i).equals(matchseqs.get(j))) { 243 matchseqs.get(i).addOccurencesOf(matchseqs.get(j)); 244 matchseqs.remove(j); 245 246 //System.out.println("Sequence " + i); 247 //matchseqs.get(i).getFirstSequence().printSequence(); 248 //matchseqs.get(i).getSecondSequence().printSequence(); 249 //System.out.println("is equal to sequence " + j); 250 //matchseqs.get(j).getFirstSequence().printSequence(); 251 //matchseqs.get(j).getSecondSequence().printSequence(); 252 continue; 253 } 254 } 255 j++; 256 } 257 i++; 258 } 259 Collections.sort(matchseqs, comparator); 260 */ 261 262 183 263 184 264 185 186 //Skip sequences with more 0 events (scrolls) than other events. Both of the pattern sequences are equally long, so the added 0 counts 187 //just need to be smaller than the length of one sequence 188 if(pattern.getFirstSequence().eventCount(0) + pattern.getSecondSequence().eventCount(0) +1 > pattern.getFirstSequence().size()) 189 continue; 190 Console.traceln(Level.FINEST, "searching for patterns occuring most: " + Math.round((float)i/(float)matchseqs.size()*100) + "%"); 191 for(int j=0; j < numberseqs.size();j++) { 192 int tmpcount = numberseqs.get(j).containsPattern(pattern); 193 if(tmpcount > 0) { 194 sequencecount++; 195 totalcount+=tmpcount; 196 } 197 } 198 199 if(totalcount > 1) { 200 matchseqs.get(i).getFirstSequence().printSequence(); 265 266 267 268 // Just printing the results out 269 for (int i = 0; i < matchseqs.size(); i++) { 270 // Every pattern consists of 2 sequences, therefore the minimum 271 // occurences here is 2. 272 // We just need the sequences also occuring in other sequences as 273 // well 274 if (matchseqs.get(i).occurenceCount() > 2) { 201 275 matchseqs.get(i).getFirstSequence().printSequence(); 202 System.out.println("Found pattern in " + sequencecount +"/" + numberseqs.size() + " sequences, total of " + totalcount + " occurences"); 276 matchseqs.get(i).getSecondSequence().printSequence(); 277 System.out.println("Found pattern " 278 + matchseqs.get(i).occurenceCount() + " times"); 203 279 System.out.println(); 204 280 } 205 281 } 282 283 206 284 alignments = null; 207 208 // 209 //AlignmentAlgorithmFactory.setDefaultAlgorithm("de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NeedlemanWunsch"); 210 //PairwiseAlignmentStorage matchAlignments = PairwiseAlignmentGenerator.generate(matchseqs, submat); 211 //UPGMAAligningTree guidetree = new UPGMAAligningTree(matchseqs,matchAlignments,submat); 212 //System.out.println(alignments.getDistanceMatrix()); 213 214 //for(Iterator<NumberSequence> it = guidetree.getRoot().getSequences().iterator();it.hasNext();) { 215 // NumberSequence tmp = (NumberSequence) it.next(); 216 // tmp.printSequence(); 217 //} 218 219 285 220 286 /* 221 do { 222 223 // appData.getStopWatch().start("whole loop"); 224 // detectAndReplaceIterations(appData); 225 226 // appData.getStopWatch().start("task replacement"); 227 // detectAndReplaceTasks(appData); 228 // appData.getStopWatch().stop("task replacement"); 229 // appData.getStopWatch().stop("whole loop"); 230 231 // appData.getStopWatch().dumpStatistics(System.out); 232 // appData.getStopWatch().reset(); 233 234 } while (appData.detectedAndReplacedTasks()); */ 287 * do { 288 * 289 * // appData.getStopWatch().start("whole loop"); // 290 * detectAndReplaceIterations(appData); 291 * 292 * // appData.getStopWatch().start("task replacement"); // 293 * detectAndReplaceTasks(appData); // 294 * appData.getStopWatch().stop("task replacement"); // 295 * appData.getStopWatch().stop("whole loop"); 296 * 297 * // appData.getStopWatch().dumpStatistics(System.out); // 298 * appData.getStopWatch().reset(); 299 * 300 * } while (appData.detectedAndReplacedTasks()); 301 */ 235 302 236 303 Console.println("created "
Note: See TracChangeset
for help on using the changeset viewer.