Ignore:
Timestamp:
06/18/14 08:59:41 (10 years ago)
Author:
rkrimmel
Message:

Building distance matrix between sequences

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java

    r1559 r1568  
    3030import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.SmithWatermanRepeated; 
    3131import de.ugoe.cs.autoquest.tasktrees.alignment.substitution.ObjectDistanceSubstitionMatrix; 
     32import de.ugoe.cs.autoquest.tasktrees.alignment.substitution.TriangleMatrix; 
    3233import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality; 
    3334import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
     
    156157                // this is the real rule application. Loop while something is replaced. 
    157158                SymbolMap<ITaskInstance, ITask> uniqueTasks = harmonizeEventTaskInstancesModel(appData); 
     159 
    158160                ObjectDistanceSubstitionMatrix submat = new ObjectDistanceSubstitionMatrix( 
    159161                                uniqueTasks, 5); 
    160162                submat.generate(); 
    161163 
    162                 // good tests: 7/8 20/24 
     164                TriangleMatrix sequenceDistances = new TriangleMatrix(numberseqs.size()); 
     165 
    163166                for (int i = 0; i < numberseqs.size(); i++) { 
     167                        NumberSequence ns1 = numberseqs.get(i); 
     168                        //System.out.print("Sequence " + i + ": "); 
     169                        //ns1.printSequence(); 
    164170                        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); 
    165201                                 
    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                 
    193231                do { 
    194232                        System.out.println(); 
Note: See TracChangeset for help on using the changeset viewer.