Changeset 1618 for branches/ralph/src
- Timestamp:
- 07/16/14 18:07:05 (10 years ago)
- Location:
- branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/NumberSequence.java
r1592 r1618 1 1 package de.ugoe.cs.autoquest.tasktrees.alignment.algorithms; 2 2 3 3 import java.util.ArrayList; 4 4 import java.util.Random; 5 5 6 public class NumberSequence 6 public class NumberSequence { 7 7 private int[] sequence; 8 8 private int signature; 9 9 10 10 public NumberSequence(int size) { 11 11 12 12 sequence = new int[size]; 13 13 } 14 14 15 15 public int[] getSequence() { 16 16 return sequence; 17 17 } 18 18 19 public void setSequence(int[] sequence) { 19 20 this.sequence = sequence; 20 21 } 22 21 23 public int getSignature() { 22 24 return signature; 23 25 } 26 24 27 public void setSignature(int signature) { 25 28 this.signature = signature; 26 29 } 27 28 public void printSequence() 29 { 30 31 public void printSequence() { 30 32 for (int i = 0; i < sequence.length; i++) { 31 33 System.out.format("%5d", sequence[i]); … … 33 35 System.out.println(); 34 36 } 35 36 public NumberSequence shuffle() {37 38 public NumberSequence shuffle() { 37 39 NumberSequence result = new NumberSequence(sequence.length); 38 40 result.setSequence(this.sequence); 39 41 Random rgen = new Random(); 40 41 for (int i =0; i<result.sequence.length; i++) {42 43 44 45 42 43 for (int i = 0; i < result.sequence.length; i++) { 44 int randomPosition = rgen.nextInt(result.sequence.length); 45 int temp = result.sequence[i]; 46 result.sequence[i] = result.sequence[randomPosition]; 47 result.sequence[randomPosition] = temp; 46 48 } 47 49 return result; 48 50 51 } 52 53 // TODO: This can be done faster 54 public int containsPattern(ArrayList<NumberSequence> pattern) { 55 int i = 0; 56 int count = 0; 57 int[] pat1 = pattern.get(0).getSequence(); 58 int[] pat2 = pattern.get(1).getSequence(); 59 notmatched: while (i < sequence.length - pat1.length) { 60 if (sequence[i] == pat1[0] || sequence[i] == pat2[0]) { 61 for (int j = 0; j < pat1.length; j++) { 62 if (sequence[i + j] != pat1[j] 63 && sequence[i + j] != pat2[j]) { 64 continue notmatched; 65 } 66 } 67 count++; 68 } 69 i++; 70 } 71 return count; 49 72 } 50 73 -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/SmithWatermanRepeated.java
r1612 r1618 375 375 } 376 376 377 377 //Console.traceln(Level.INFO,"Generating DP Matrix"); 378 378 buildMatrix(); 379 //Console.traceln(Level.INFO,"Doing traceback"); 379 380 traceback(); 380 381 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/PairwiseAlignmentGenerator.java
r1617 r1618 3 3 import java.util.ArrayList; 4 4 import java.util.Iterator; 5 import java.util.logging.Level; 5 6 6 7 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithm; 7 8 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithmFactory; 8 9 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NumberSequence; 10 import de.ugoe.cs.util.console.Console; 9 11 10 12 public class PairwiseAlignmentGenerator { … … 22 24 23 25 if (i != j) { 26 Console.traceln(Level.FINEST,"Aligning sequence " + i + " with sequence " + j); 24 27 int smithWatermanThreshold = 10; 25 28 AlignmentAlgorithm aa = AlignmentAlgorithmFactory.create(); -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
r1617 r1618 153 153 SymbolMap<ITaskInstance, ITask> uniqueTasks = harmonizeEventTaskInstancesModel(appData); 154 154 155 Console.traceln(Level.INFO,"generating substitution matrix"); 155 156 ObjectDistanceSubstitionMatrix submat = new ObjectDistanceSubstitionMatrix( 156 157 uniqueTasks, 5); 157 158 submat.generate(); 158 159 159 ArrayList<NumberSequence> matchseqs = new ArrayList<NumberSequence>(); 160 Console.traceln(Level.INFO,"generating pairwise alignments"); 161 ArrayList<ArrayList<NumberSequence>> matchseqs = new ArrayList<ArrayList<NumberSequence>>(); 160 162 PairwiseAlignmentStorage alignments = PairwiseAlignmentGenerator.generate(numberseqs,submat); 161 163 164 Console.traceln(Level.INFO,"retrieving significant sequence pieces"); 162 165 for (int i=0; i< numberseqs.size();i++) { 163 166 for(int j=0; j< numberseqs.size();j++) { 164 167 if(i != j) { 165 168 ArrayList<ArrayList<NumberSequence>> tmp = alignments.get(i, j).getMatches(); 166 int count = 0; 167 for(Iterator<ArrayList<NumberSequence>> it = tmp.iterator();it.hasNext();) { 168 System.out.println("Match number " + count); 169 ArrayList<NumberSequence> tmp2 = it.next(); 170 tmp2.get(0).printSequence(); 171 tmp2.get(1).printSequence(); 172 System.out.println(); 173 count++; 174 matchseqs.addAll(tmp2); 169 matchseqs.addAll(tmp); 170 } 171 } 172 } 173 174 Console.traceln(Level.INFO, "searching for patterns occuring most"); 175 //search this match in every other sequence 176 for(int i=0; i < matchseqs.size();i++) { 177 for(int j=0; j < matchseqs.size();j++) { 178 if(i>j) { 179 if(matchseqs.get(j).get(0).containsPattern(matchseqs.get(i)) > 0 || matchseqs.get(j).get(1).containsPattern(matchseqs.get(i)) > 0) { 180 System.out.println("Found something!"); 175 181 } 176 System.out.println(); 177 } 178 } 179 } 180 181 AlignmentAlgorithmFactory.setDefaultAlgorithm("de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NeedlemanWunsch"); 182 } 183 } 184 185 } 182 186 183 187 184 PairwiseAlignmentStorage matchAlignments = PairwiseAlignmentGenerator.generate(numberseqs, submat);185 UPGMAAligningTree guidetree = new UPGMAAligningTree(matchseqs,matchAlignments,submat);186 System.out.println(alignments.getDistanceMatrix());187 //UPGMAAligningTree guidetree = new UPGMAAligningTree(numberseqs, alignments,submat);188 188 189 for(Iterator<NumberSequence> it = guidetree.getRoot().getSequences().iterator();it.hasNext();) { 190 NumberSequence tmp = (NumberSequence) it.next(); 191 tmp.printSequence(); 192 } 189 alignments = null; 190 191 // 192 //AlignmentAlgorithmFactory.setDefaultAlgorithm("de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NeedlemanWunsch"); 193 //PairwiseAlignmentStorage matchAlignments = PairwiseAlignmentGenerator.generate(matchseqs, submat); 194 //UPGMAAligningTree guidetree = new UPGMAAligningTree(matchseqs,matchAlignments,submat); 195 //System.out.println(alignments.getDistanceMatrix()); 196 197 //for(Iterator<NumberSequence> it = guidetree.getRoot().getSequences().iterator();it.hasNext();) { 198 // NumberSequence tmp = (NumberSequence) it.next(); 199 // tmp.printSequence(); 200 //} 193 201 194 202
Note: See TracChangeset
for help on using the changeset viewer.