Changeset 1698
- Timestamp:
- 08/27/14 18:49:00 (10 years ago)
- Location:
- branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/DifferenceSubstitutionMatrix.java
r1580 r1698 3 3 */ 4 4 package de.ugoe.cs.autoquest.tasktrees.alignment.matrix; 5 6 import java.util.HashSet; 7 import java.util.LinkedList; 8 9 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 5 10 6 11 … … 50 55 51 56 @Override 52 public void generate() { 53 // TODO Auto-generated method stub 54 57 public void generate(HashSet<ITask> uniqueTasks) { 58 } 59 60 @Override 61 public void update(LinkedList<ITask> newlyGeneratedTasks) { 55 62 } 56 63 -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/DummySubstitutionMatrix.java
r1649 r1698 1 1 package de.ugoe.cs.autoquest.tasktrees.alignment.matrix; 2 3 import java.util.HashSet; 4 import java.util.LinkedList; 5 6 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 2 7 3 8 public class DummySubstitutionMatrix implements SubstitutionMatrix { … … 19 24 20 25 @Override 21 public void generate( ) {26 public void generate(HashSet<ITask> uniqueTasks) { 22 27 } 23 28 29 @Override 30 public void update(LinkedList<ITask> newlyGeneratedTasks) { 31 // TODO Auto-generated method stub 32 33 } 34 35 24 36 } -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/NearbySubstitutionMatrix.java
r1580 r1698 3 3 */ 4 4 package de.ugoe.cs.autoquest.tasktrees.alignment.matrix; 5 6 import java.util.HashSet; 7 import java.util.LinkedList; 8 9 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 5 10 6 11 /** … … 40 45 41 46 47 42 48 @Override 43 public void generate() { 44 // TODO Auto-generated method stub 45 49 public void generate(HashSet<ITask> uniqueTasks) { 50 } 51 52 @Override 53 public void update(LinkedList<ITask> newlyGeneratedTasks) { 46 54 } 47 55 -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/ObjectDistanceSubstitionMatrix.java
r1696 r1698 28 28 private double positiveThreshold; 29 29 30 public ObjectDistanceSubstitionMatrix( HashSet<ITask> uniqueTasks,30 public ObjectDistanceSubstitionMatrix( 31 31 float positiveThreshold, int gapPenalty, 32 32 boolean calculateNonTaskInstances) { 33 this.uniqueTasks = uniqueTasks;33 34 34 this.positiveThreshold = positiveThreshold; 35 35 idmapping = new HashMap<Integer, Integer>(); 36 36 etisOfTasks = new HashMap<Integer, LinkedList<IEventTaskInstance>>(); 37 matrix = new TriangleMatrix(uniqueTasks.size() + 1);38 37 this.gapPenalty = gapPenalty; 39 38 this.calculateNonTaskInstances = calculateNonTaskInstances; … … 65 64 66 65 } 67 68 public void generate() { 69 if (this.calculateNonTaskInstances) { 70 Console.traceln(Level.INFO, " searching EventTasks in Tasks"); 66 67 //Just Calculate the distance between the new tasks and the matrix. 68 public void update(LinkedList<ITask> newTasks) { 69 matrix.increaseSize(newTasks.size()); 70 if (this.calculateNonTaskInstances) { 71 Console.traceln(Level.INFO, "searching EventTasks in Tasks"); 71 72 searchEventTaskInstances(); 72 73 } 73 Console.traceln(Level.INFO, " calculating distances"); 74 int index1 = -1; 75 int index2 = -1; 76 float distance = 0; 77 int count = 0; 78 for (Iterator<ITask> it = uniqueTasks.iterator(); it.hasNext();) { 79 count++; 80 74 75 for(Iterator<ITask> it = newTasks.iterator();it.hasNext();) { 76 int index1 = -1; 77 int index2 = -1; 78 float distance = 0; 81 79 ITask task1 = it.next(); 82 80 for (Iterator<ITask> jt = uniqueTasks.iterator(); jt.hasNext();) { … … 130 128 } 131 129 } 130 131 public void generate(HashSet<ITask> uniqueTasks) { 132 this.uniqueTasks = uniqueTasks; 133 matrix = new TriangleMatrix(uniqueTasks.size() + 1); 134 matrix.initialize(0); 135 if (this.calculateNonTaskInstances) { 136 Console.traceln(Level.INFO, "searching EventTasks in Tasks"); 137 searchEventTaskInstances(); 138 } 139 Console.traceln(Level.INFO, "calculating distances"); 140 int index1 = -1; 141 int index2 = -1; 142 float distance = 0; 143 for (Iterator<ITask> it = uniqueTasks.iterator(); it.hasNext();) { 144 ITask task1 = it.next(); 145 for (Iterator<ITask> jt = uniqueTasks.iterator(); jt.hasNext();) { 146 ITask task2 = jt.next(); 147 ITaskInstance ti1 = null; 148 ITaskInstance ti2 = null; 149 // We just need to the first instance here 150 if (task1.getInstances().size() > 0) { 151 ti1 = (ITaskInstance) task1.getInstances().iterator() 152 .next(); 153 } 154 if (task2.getInstances().size() > 0) { 155 ti2 = (ITaskInstance) task2.getInstances().iterator() 156 .next(); 157 } 158 IEventTaskInstance eti1 = null; 159 IEventTaskInstance eti2 = null; 160 161 if (ti1 instanceof IEventTaskInstance 162 && ti2 instanceof IEventTaskInstance) { 163 eti1 = (IEventTaskInstance) ti1; 164 index1 = getIndex(eti1); 165 eti2 = (IEventTaskInstance) ti2; 166 index2 = getIndex(eti2); 167 distance = distanceBetweenInstances(eti1, eti2); 168 } else if (ti1 instanceof IEventTaskInstance 169 && !(ti2 instanceof IEventTaskInstance)) { 170 task1 = ((ITaskInstance) ti1).getTask(); 171 index2 = getIndex(task2); 172 eti1 = (IEventTaskInstance) ti1; 173 index1 = getIndex(eti1); 174 distance = distanceBetweenTaskAndInstance(task2, eti1); 175 } else if (!(ti1 instanceof IEventTaskInstance) 176 && ti2 instanceof IEventTaskInstance) { 177 index1 = getIndex(task1); 178 eti2 = (IEventTaskInstance) ti2; 179 index2 = getIndex(eti2); 180 distance = distanceBetweenTaskAndInstance(task1, eti2); 181 } else if (!(ti1 instanceof IEventTaskInstance) 182 && !(ti2 instanceof IEventTaskInstance)) { 183 index1 = getIndex(task1); 184 index2 = getIndex(task2); 185 distance = distanceBetweenTasks(task1, task2); 186 } else { 187 System.out.println("Unknown error"); 188 } 189 190 matrix.set(index1, index2, distance); 191 192 } 193 } 194 } 195 196 132 197 133 198 private float distanceBetweenTaskAndInstance(ITask task1, … … 157 222 158 223 public boolean scoreExists(int id, int id2) { 159 return idmapping.containsKey(id) && idmapping.containsKey(id2); 224 //return idmapping.containsKey(id) && idmapping.containsKey(id2); 225 return false; 160 226 } 161 227 -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/SubstitutionMatrix.java
r1578 r1698 1 1 package de.ugoe.cs.autoquest.tasktrees.alignment.matrix; 2 3 import java.util.HashSet; 4 import java.util.LinkedList; 5 6 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 2 7 3 8 … … 10 15 public double getGapPenalty(); 11 16 12 public void generate(); 17 public void generate(HashSet<ITask> uniqueTasks); 18 19 public void update(LinkedList<ITask> newlyGeneratedTasks); 13 20 14 21 -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/TriangleMatrix.java
r1697 r1698 1 1 package de.ugoe.cs.autoquest.tasktrees.alignment.matrix; 2 2 3 import java.util.ArrayList; 4 5 //Must be initialized! 3 6 public class TriangleMatrix { 4 7 5 private float[]matrix;8 private ArrayList<Float> matrix; 6 9 protected int size; 10 private float initalizationValue; 7 11 8 12 9 13 14 //Increases the size 15 public void increaseSize(int count) { 16 int oldsize = size; 17 this.size += count; 18 matrix.ensureCapacity(size*(size+1/2)); 19 for(int i=0;i<(oldsize*count)+(count*(count+1)/2);i++) { 20 matrix.add(this.initalizationValue); 21 } 22 } 23 24 10 25 public TriangleMatrix(int size) { 11 26 this.size = size; 12 matrix = new float [size*(size+1)/2]; 27 matrix = new ArrayList<Float>(); 28 matrix.ensureCapacity(size*(size+1/2)); 13 29 } 30 14 31 15 32 public float get(int first, int second) { 16 33 int row = Math.min(first, second); 17 34 int col = Math.max(first, second); 18 return matrix [row*size-(row*(row+1)/2 - (size-col))];35 return matrix.get(row*size-(row*(row+1)/2 - (size-col))); 19 36 20 37 } … … 23 40 int row = Math.min(first, second); 24 41 int col = Math.max(first, second); 25 matrix [row*size-(row*(row+1)/2 - (size-col))] = value;42 matrix.set(row*size-(row*(row+1)/2 - (size-col)),value); 26 43 } 27 44 28 45 public void initialize(float value) { 29 for (int i=0; i < matrix.length; i++) { 30 matrix[i] = value; 46 this.initalizationValue = value; 47 matrix.clear(); 48 for (int i=0; i < this.size*(this.size+1)/2; i++) { 49 matrix.add(value); 31 50 } 32 51 } -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
r1697 r1698 68 68 class SequenceForTaskDetectionRuleAlignment implements ISessionScopeRule { 69 69 70 private int iteration = 0;70 //private int iteration = 0; 71 71 /** 72 72 * <p> … … 139 139 140 140 harmonizeEventTaskInstancesModel(appData); 141 // Generate a substitution matrix between all occurring events. 142 Console.traceln(Level.INFO, "generating substitution matrix"); 143 appData.getSubmat().generate(appData.getUniqueTasks()); 144 141 145 do { 142 iteration++;146 //iteration++; 143 147 144 148 appData.detectedAndReplacedTasks = false; … … 146 150 detectAndReplaceIterations(appData); 147 151 appData.getStopWatch().start("task replacement"); 152 appData.updateSubstitutionMatrix(); 148 153 detectAndReplaceTasks(appData); // 149 154 appData.getStopWatch().stop("task replacement"); … … 168 173 return appData.getResult(); 169 174 } 175 170 176 171 177 private ArrayList<NumberSequence> createNumberSequences( … … 322 328 323 329 IIteration iteration = taskFactory.createNewIteration(); 324 appData.getUniqueTasks().add(iteration); 325 appData.getNumber2Task().put(iteration.getId(), iteration); 330 appData.newTaskCreated(iteration); 326 331 iterations.put(iteratedTask, iteration); 327 332 iterationInstances.put(iteration, … … 445 450 public ISequence matchAsSequence(RuleApplicationData appData, Match m) { 446 451 ISequence sequence = taskFactory.createNewSequence(); 447 appData.uniqueTasks.add(sequence); 448 appData.number2task.put(sequence.getId(), sequence); 452 appData.newTaskCreated(sequence); 449 453 450 454 int[] first = m.getFirstSequence().getSequence(); … … 469 473 else if (first[i] == -1 && second[i] != -1) { 470 474 IOptional optional = taskFactory.createNewOptional(); 471 appData.uniqueTasks.add(optional); 472 appData.number2task.put(optional.getId(), optional); 475 appData.newTaskCreated(optional); 473 476 taskBuilder.setMarkedTask(optional, appData.getNumber2Task() 474 477 .get(second[i])); … … 479 482 else if (first[i] != -1 && second[i] == -1) { 480 483 IOptional optional = taskFactory.createNewOptional(); 481 appData.uniqueTasks.add(optional); 482 appData.number2task.put(optional.getId(), optional); 484 appData.newTaskCreated(optional); 483 485 taskBuilder.setMarkedTask(optional, appData.getNumber2Task() 484 486 .get(first[i])); … … 494 496 495 497 ISelection selection = taskFactory.createNewSelection(); 496 appData.getUniqueTasks().add(selection); 497 appData.number2task.put(selection.getId(), selection); 498 appData.newTaskCreated(selection); 498 499 taskBuilder.addChild(selection, appData.getNumber2Task() 499 500 .get(first[i])); … … 504 505 boolean selectionfound = true; 505 506 ISelection selection = taskFactory.createNewSelection(); 506 appData.getUniqueTasks().add(selection); 507 appData.number2task.put(selection.getId(), selection); 507 appData.newTaskCreated(selection); 508 508 509 509 ISequence subsequence1 = taskFactory.createNewSequence(); 510 appData.uniqueTasks.add(subsequence1); 511 appData.number2task.put(subsequence1.getId(), subsequence1); 510 appData.newTaskCreated(subsequence1); 512 511 513 512 ISequence subsequence2 = taskFactory.createNewSequence(); 514 appData.uniqueTasks.add(subsequence2); 515 appData.number2task.put(subsequence2.getId(), subsequence2); 513 appData.newTaskCreated(subsequence2); 516 514 517 515 taskBuilder.addChild(selection, subsequence1); … … 542 540 543 541 ISelection selection = taskFactory.createNewSelection(); 544 appData.getUniqueTasks().add(selection); 545 appData.number2task.put(selection.getId(), selection); 542 appData.newTaskCreated(selection); 546 543 taskBuilder.addChild(selection, appData.getNumber2Task() 547 544 .get(first[i])); … … 568 565 // Create NumberSequences 569 566 appData.setNumberSequences(this.createNumberSequences(appData)); 570 571 // Generate a substitution matrix between all occurring events. 572 Console.traceln(Level.INFO, "generating substitution matrix"); 573 ObjectDistanceSubstitionMatrix submat = new ObjectDistanceSubstitionMatrix( 574 appData.getUniqueTasks(), 6, -3,true); 575 submat.generate(); 576 567 577 568 // Generate pairwise alignments 578 569 Console.traceln(Level.INFO, "generating pairwise alignments"); 579 570 LinkedList<Match> matchseqs = new LinkedList<Match>(); 580 571 PairwiseAlignmentStorage alignments = PairwiseAlignmentGenerator 581 .generate(appData.getNumberSequences(), submat, 9);572 .generate(appData.getNumberSequences(), appData.getSubmat(), 9); 582 573 583 574 // Retrieve all matches reached a specific threshold … … 729 720 alignments = null; 730 721 matchseqs = null; 731 submat = null;732 722 appData.getStopWatch().stop("replacing tasks"); 733 723 } … … 740 730 private HashMap<Integer, ITask> number2task; 741 731 742 // TODO: We Actually just need number2task here 732 // TODO: We Actually just need number2task here, this structure can be removed in the future. 743 733 private HashSet<ITask> uniqueTasks; 744 734 735 ObjectDistanceSubstitionMatrix submat; 736 737 745 738 private ArrayList<NumberSequence> numberseqs; 746 739 740 private LinkedList<ITask> newTasks; 741 747 742 /** 748 743 * … … 775 770 stopWatch = new StopWatch(); 776 771 result = new RuleApplicationResult(); 772 submat= new ObjectDistanceSubstitionMatrix(6,-3,true); 773 newTasks = new LinkedList<ITask>(); 774 } 775 776 private ObjectDistanceSubstitionMatrix getSubmat() { 777 return submat; 778 } 779 780 private void resetNewlyCreatedTasks() { 781 uniqueTasks.addAll(newTasks); 782 newTasks.clear(); 783 } 784 785 private void newTaskCreated(ITask task) { 786 number2task.put(task.getId(), task); 787 newTasks.add(task); 777 788 } 778 789 … … 788 799 } 789 800 790 // private void setUniqueTasks(SymbolMap<ITaskInstance, ITask> ut) {791 // this.uniqueTasks = ut;792 // }793 794 801 private void setNumberSequences(ArrayList<NumberSequence> numberseqs) { 795 802 this.numberseqs = numberseqs; … … 800 807 } 801 808 809 private void updateSubstitutionMatrix() { 810 submat.update(getNewTasks()); 811 resetNewlyCreatedTasks(); 812 } 813 814 802 815 /** 803 816 * … … 814 827 } 815 828 829 public LinkedList<ITask> getNewTasks() { 830 return newTasks; 831 } 832 816 833 /** 817 834 * @return the stopWatch
Note: See TracChangeset
for help on using the changeset viewer.