+ fixed bug in the assertion whether scalar prod + loss equals viterbi output
authorfabio <fabio@e1793c9e-67f9-0310-80fc-b846ff1f7b36>
Mon, 21 Jan 2008 10:23:15 +0000 (10:23 +0000)
committerfabio <fabio@e1793c9e-67f9-0310-80fc-b846ff1f7b36>
Mon, 21 Jan 2008 10:23:15 +0000 (10:23 +0000)
+ now check before whether states have distinct scores

git-svn-id: http://svn.tuebingen.mpg.de/ag-raetsch/projects/QPalma@7508 e1793c9e-67f9-0310-80fc-b846ff1f7b36

python/Configuration.py
python/qpalma.py

index 1a0cf49..34fcb74 100644 (file)
@@ -155,6 +155,8 @@ numQualSuppPoints    = 2
 min_qual = -1
 max_qual = 40
 
+USE_OPT = True
+
 if mode == 'normal':
    sizeMatchmatrix   = (6,6)
    numQualPlifs = 0
index 96040af..7586613 100644 (file)
@@ -82,8 +82,6 @@ class QPalma:
       else:
          assert(False)
 
-      pdb.set_trace()
-
       # number of training instances
       N = len(Sequences) 
       self.numExamples = N
@@ -112,7 +110,7 @@ class QPalma:
                Donors[i] = 1
 
       # Initialize solver 
-      if not __debug__:
+      if Configuration.USE_OPT:
          self.plog('Initializing problem...\n')
          solver = SIQPSolver(Configuration.numFeatures,self.numExamples,Configuration.C,self.logfh)
 
@@ -311,7 +309,7 @@ class QPalma:
 
                path_loss[pathNr] = 0
                # sum up positionwise loss between alignments
-               for alignPosIdx in range(len(newSpliceAlign[pathNr,:])):
+               for alignPosIdx in range(newSpliceAlign[pathNr,:].shape[1]):
                   if newSpliceAlign[pathNr,alignPosIdx] != trueSpliceAlign[alignPosIdx]:
                      path_loss[pathNr] += 1
 
@@ -333,9 +331,14 @@ class QPalma:
                #assert math.fabs(AlignmentScores[pathNr] - AlignmentScores[pathNr+1]) < 1e-6,\
                #'Scalar prod + loss is not equal Viterbi score. Respective values are %f, %f' % \
                #(AlignmentScores[pathNr],AlignmentScores[pathNr+1])
-               print '%f vs %f' % (newDPScores[pathNr], AlignmentScores[pathNr+1] + path_loss[pathNr])
-               assert math.fabs(newDPScores[pathNr] - (AlignmentScores[pathNr+1]\
-               + path_loss[pathNr])) <= 1e-5
+               print '%f vs %f' % (newDPScores[pathNr,0], AlignmentScores[pathNr+1])
+
+               distinct_scores = False
+               if AlignmentScores[pathNr] != AlignmentScores[pathNr+1]:
+                  distinct_scores = True
+               
+               if not math.fabs(newDPScores[pathNr,0] - AlignmentScores[pathNr+1]) + [0,1][distinct_scores and (pathNr>0)] <= 1e-5:
+                  pdb.set_trace()
 
                #  # if the pathNr-best alignment is very close to the true alignment consider it as true
                if norm( allWeights[:,0] - allWeights[:,pathNr+1] ) < 1e-5:
@@ -363,7 +366,7 @@ class QPalma:
                   differenceVector  = firstFalseWeights - trueWeights
                   #pdb.set_trace()
 
-                  if not __debug__:
+                  if Configuration.USE_OPT:
                      const_added = solver.addConstraint(differenceVector, exampleIdx)
                      const_added_ctr += 1
                #
@@ -371,7 +374,7 @@ class QPalma:
                #
 
             # call solver every nth example //added constraint
-            if exampleIdx != 0 and exampleIdx % 10 == 0 and not __debug__:
+            if exampleIdx != 0 and exampleIdx % 10 == 0 and Configuration.USE_OPT:
                objValue,w,self.slacks = solver.solve()
       
                print "objValue is %f" % objValue