Changeset 1568
- Timestamp:
- 06/18/14 08:59:41 (10 years ago)
- Location:
- branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/MatrixEntry.java
r1559 r1568 2 2 3 3 public class MatrixEntry { 4 private floatscore;4 private double score; 5 5 private MatrixEntry previous; 6 6 private int xvalue; … … 15 15 } 16 16 17 public floatgetScore() {17 public double getScore() { 18 18 return score; 19 19 } 20 public void setScore( floatscore) {20 public void setScore(double score) { 21 21 this.score = score; 22 22 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/NumberSequence.java
r1559 r1568 3 3 import java.io.Serializable; 4 4 import java.util.ArrayList; 5 import java.util.Random; 5 6 6 7 public class NumberSequence implements Serializable { … … 33 34 System.out.println(); 34 35 } 36 37 public NumberSequence shuffle(){ 38 NumberSequence result = new NumberSequence(sequence.length); 39 result.setSequence(this.sequence); 40 Random rgen = new Random(); 41 42 for (int i=0; i<result.sequence.length; i++) { 43 int randomPosition = rgen.nextInt(result.sequence.length); 44 int temp = result.sequence[i]; 45 result.sequence[i] = result.sequence[randomPosition]; 46 result.sequence[randomPosition] = temp; 47 } 48 return result; 49 50 } 35 51 36 52 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/SmithWatermanRepeated.java
r1559 r1568 71 71 * @return Cost of substitution of the character in str1 by the one in str2 72 72 */ 73 private floatsimilarity(int i, int j) {73 private double similarity(int i, int j) { 74 74 return submat.getDistance(input1[i - 1], input2[j - 1]); 75 75 } … … 101 101 // F(i,0) = max { F(i-1,0), F(i-1,j)-T j=1,...,m 102 102 103 floatfirstRowLeftScore = matrix[i-1][0].getScore();103 double firstRowLeftScore = matrix[i-1][0].getScore(); 104 104 //for sequences of length 1 105 floattempMax;105 double tempMax; 106 106 int maxRowIndex; 107 107 if(length2 == 1) { … … 138 138 matrix[i][0].setXvalue(input1[i-1]); 139 139 matrix[i][0].setYvalue(-2); 140 141 140 } 142 141 else { … … 147 146 148 147 for (int j = 1; j < length2; j++) { 149 floatdiagScore = matrix[i - 1][j - 1].getScore() + similarity(i, j);150 floatupScore = matrix[i][j - 1].getScore() + submat.getGapPenalty();151 floatleftScore = matrix[i - 1][j].getScore() + submat.getGapPenalty();148 double diagScore = matrix[i - 1][j - 1].getScore() + similarity(i, j); 149 double upScore = matrix[i][j - 1].getScore() + submat.getGapPenalty(); 150 double leftScore = matrix[i - 1][j].getScore() + submat.getGapPenalty(); 152 151 153 152 matrix[i][j].setScore(Math.max(diagScore,Math.max(upScore, Math.max(leftScore,matrix[i][0].getScore())))); … … 207 206 * Get the alignment score between the two input strings. 208 207 */ 209 public floatgetAlignmentScore() {208 public double getAlignmentScore() { 210 209 return matrix[length1+1][0].getScore(); 211 210 } … … 213 212 214 213 215 216 /**217 * given the bottom right corner point trace back the top left conrner. at218 * entry: i, j hold bottom right (end of Aligment coords) at return: hold219 * top left (start of Alignment coords)220 */221 214 private int[] traceback(int i, int j) { 222 215 … … 225 218 } 226 219 227 public voidtraceback() {220 public List<Match> traceback() { 228 221 MatrixEntry tmp = matrix[length1+1][0]; 229 222 String aligned1 = ""; … … 266 259 System.out.println(aligned1); 267 260 System.out.println(aligned2); 261 return null; 268 262 } 269 263 -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/substitution/DifferenceSubstitutionMatrix.java
r1554 r1568 29 29 * @see de.ugoe.cs.autoquest.plugin.alignment.SubstitutionMatrix#getDistance(int, int) 30 30 */ 31 public floatgetDistance(int pos1, int pos2) {31 public double getDistance(int pos1, int pos2) { 32 32 return maxValue - (input1[pos1] - input2[pos2]); 33 33 } … … 49 49 50 50 @Override 51 public floatgetGapPenalty() {51 public double getGapPenalty() { 52 52 return -maxValue; 53 53 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/substitution/NearbySubstitutionMatrix.java
r1554 r1568 29 29 * @see de.ugoe.cs.autoquest.plugin.alignment.SubstitutionMatrix#getDistance(int, int) 30 30 */ 31 public floatgetDistance(int pos1, int pos2) {31 public double getDistance(int pos1, int pos2) { 32 32 int difference = Math.abs(input1[pos1]-input2[pos2]); 33 33 if(difference < range) { … … 41 41 42 42 @Override 43 public floatgetGapPenalty() {43 public double getGapPenalty() { 44 44 return -range-1; 45 45 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/substitution/ObjectDistanceSubstitionMatrix.java
r1559 r1568 26 26 private TriangleMatrix matrix; 27 27 private SymbolMap<ITaskInstance, ITask> uniqueTasks; 28 private floatgapPenalty;29 private floatpositiveThreshold;28 private double gapPenalty; 29 private double positiveThreshold; 30 30 31 31 public ObjectDistanceSubstitionMatrix( … … 40 40 41 41 @Override 42 public floatgetGapPenalty() {42 public double getGapPenalty() { 43 43 return gapPenalty; 44 44 } … … 48 48 int index = 0; 49 49 //TODO We need to determine this parameter before generating the matrix.. 50 float meandistance = 18;50 //float meandistance = 18; 51 51 //TODO We need to determine this parameter before generating the matrix.. 52 52 float maxDistance =34; … … 58 58 eti1 = (IEventTaskInstance) obj1; 59 59 } 60 //System.out.println(eti1.getTask().toString()); 60 61 61 62 for (Iterator<ITaskInstance> jt = uniqueTasks.getSymbols() … … 121 122 122 123 @Override 123 public floatgetDistance(int taskId1, int taskId2) {124 public double getDistance(int taskId1, int taskId2) { 124 125 //System.out.println("Taskid1: " + taskId1 + " Taskid2: " + taskId2 + " Idmapping1: " + idmapping.get(taskId1) + " Idmapping2: " + idmapping.get(taskId2)); 125 126 return matrix.get(idmapping.get(taskId1),idmapping.get(taskId2)); -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/substitution/SubstitutionMatrix.java
r1554 r1568 11 11 12 12 13 public floatgetDistance(int pos1, int pos2);13 public double getDistance(int pos1, int pos2); 14 14 15 public floatgetGapPenalty();15 public double getGapPenalty(); 16 16 17 17 public void generate(); -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/substitution/TriangleMatrix.java
r1558 r1568 3 3 public class TriangleMatrix { 4 4 5 private float[] matrix;5 private double[] matrix; 6 6 private int size; 7 7 8 8 public TriangleMatrix(int size) { 9 9 this.size = size; 10 matrix = new float[size*(size+1)/2];10 matrix = new double [size*(size+1)/2]; 11 11 } 12 12 13 public floatget(int first, int second) {13 public double get(int first, int second) { 14 14 int row = Math.min(first, second); 15 15 int col = Math.max(first, second); … … 18 18 } 19 19 20 public void set(int first, int second, floatvalue) {20 public void set(int first, int second, double value) { 21 21 int row = Math.min(first, second); 22 22 int col = Math.max(first, second); -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
r1559 r1568 30 30 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.SmithWatermanRepeated; 31 31 import de.ugoe.cs.autoquest.tasktrees.alignment.substitution.ObjectDistanceSubstitionMatrix; 32 import de.ugoe.cs.autoquest.tasktrees.alignment.substitution.TriangleMatrix; 32 33 import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality; 33 34 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; … … 156 157 // this is the real rule application. Loop while something is replaced. 157 158 SymbolMap<ITaskInstance, ITask> uniqueTasks = harmonizeEventTaskInstancesModel(appData); 159 158 160 ObjectDistanceSubstitionMatrix submat = new ObjectDistanceSubstitionMatrix( 159 161 uniqueTasks, 5); 160 162 submat.generate(); 161 163 162 // good tests: 7/8 20/24 164 TriangleMatrix sequenceDistances = new TriangleMatrix(numberseqs.size()); 165 163 166 for (int i = 0; i < numberseqs.size(); i++) { 167 NumberSequence ns1 = numberseqs.get(i); 168 //System.out.print("Sequence " + i + ": "); 169 //ns1.printSequence(); 164 170 for (int j = 0; j < numberseqs.size(); j++) { 171 NumberSequence ns2 = numberseqs.get(j); 172 173 if (i != j) { 174 int smithWatermanThreshold = 10; 175 176 SmithWatermanRepeated twoSequences = new SmithWatermanRepeated( 177 ns1.getSequence(), ns2.getSequence(), submat, 178 smithWatermanThreshold); 179 SmithWatermanRepeated sameSequence1 = new SmithWatermanRepeated( 180 ns1.getSequence(), ns1.getSequence(), submat, 181 smithWatermanThreshold); 182 SmithWatermanRepeated sameSequence2 = new SmithWatermanRepeated( 183 ns2.getSequence(), ns2.getSequence(), submat, 184 smithWatermanThreshold); 185 186 SmithWatermanRepeated randomSequence = new SmithWatermanRepeated( 187 ns1.shuffle().getSequence(),ns2.shuffle().getSequence(),submat,smithWatermanThreshold); 188 //randomSequence.printDPMatrix(); 189 //randomSequence.traceback(); 190 191 double score = twoSequences.getAlignmentScore(); 192 // Scores of the sequence beeing aligned to itself 193 double sSelf1 = sameSequence1.getAlignmentScore(); 194 double sSelf2 = sameSequence2.getAlignmentScore(); 195 196 double sRand = randomSequence.getAlignmentScore(); 197 198 double sMax = (sSelf1 + sSelf2) / 2; 199 double sEff = (score - sRand)/ (sMax - sRand); 200 double distance = -Math.log(sEff); 165 201 166 NumberSequence ns1 = numberseqs.get(i); 167 NumberSequence ns2 = numberseqs.get(j); 168 169 170 171 SmithWatermanRepeated sw = new SmithWatermanRepeated( 172 ns1.getSequence(), ns2.getSequence(), submat, 10); 173 174 if(sw.getAlignmentScore() > 0) 175 { 176 System.out.println("================================================="); 177 System.out.println("| Sequence " + String.format("%3d", i) +" Sequence " + String.format("%3d", j) + " |"); 178 System.out.println("================================================="); 179 //System.out.print("Sequence " + i + ": "); 180 //ns1.printSequence(); 181 //System.out.print("Sequence " + j + ": "); 182 //ns2.printSequence(); 183 //System.out.println("Max Scrore: " + sw.getMaxScore()); 184 System.out.println("Alignment Score: " + sw.getAlignmentScore()); 185 //sw.printDPMatrix(); 186 sw.traceback(); 187 System.out.println(); 188 System.out.println(); 189 } 190 } 191 } 192 202 System.out.println("Score: " + score + " sRand: " + sRand + " sMax: " + sMax + " sEff: " + sEff + " distance: " + distance); 203 204 sequenceDistances.set(i,j,distance ); 205 206 if (score > 0) { 207 /* 208 * System.out.println( 209 * "================================================="); 210 * System.out.println("| Sequence " + 211 * String.format("%3d", i) +" Sequence " + 212 * String.format("%3d", j) + " |"); 213 * System.out.println( 214 * "================================================="); 215 * System.out.print("Sequence " + i + ": "); 216 * ns1.printSequence(); System.out.print("Sequence " + j 217 * + ": "); ns2.printSequence(); System.out.println(); 218 * //System.out.println("Max Scrore: " + 219 * sw.getMaxScore()); 220 * System.out.println("Alignment Score: " + 221 * sw.getAlignmentScore()); //sw.printDPMatrix(); 222 * sw.traceback(); System.out.println(); 223 * System.out.println(); 224 */ 225 } 226 } 227 } 228 } 229 //System.out.println(sequenceDistances.toString()); 230 193 231 do { 194 232 System.out.println();
Note: See TracChangeset
for help on using the changeset viewer.