Made last-train handle zero counts more robustly.
authorMartin C. Frith
Wed Oct 07 16:46:52 2015 +0900 (2015-10-07)
changeset 6380d044e3aead4
parent 637 98e55d5d41c5
child 639 047baa399047
Made last-train handle zero counts more robustly.
scripts/last-train
     1.1 --- a/scripts/last-train	Wed Oct 07 16:43:47 2015 +0900
     1.2 +++ b/scripts/last-train	Wed Oct 07 16:46:52 2015 +0900
     1.3 @@ -62,7 +62,9 @@
     1.4      return matrix, gapCounts
     1.5  
     1.6  def scoreFromProb(scale, prob):
     1.7 -    return int(round(scale * math.log(prob)))
     1.8 +    if prob > 0: logProb = math.log(prob)
     1.9 +    else:        logProb = -800  # exp(-800) is exactly zero, on my computer
    1.10 +    return int(round(scale * logProb))
    1.11  
    1.12  def costFromProb(scale, prob):
    1.13      return -scoreFromProb(scale, prob)
    1.14 @@ -105,13 +107,17 @@
    1.15      if opts.gapsym:
    1.16          delOpenProb = gapOpens / denominator / 2
    1.17          insOpenProb = gapOpens / denominator / 2
    1.18 -        delExtendProb = (gaps - gapOpens) / gaps
    1.19 -        insExtendProb = (gaps - gapOpens) / gaps
    1.20 +        if gaps > 0: delExtendProb = (gaps - gapOpens) / gaps
    1.21 +        else:        delExtendProb = 0.5  # arbitrary
    1.22 +        if gaps > 0: insExtendProb = (gaps - gapOpens) / gaps
    1.23 +        else:        insExtendProb = 0.5  # arbitrary
    1.24      else:
    1.25          delOpenProb = delOpens / denominator
    1.26          insOpenProb = insOpens / denominator
    1.27 -        delExtendProb = (deletes - delOpens) / deletes
    1.28 -        insExtendProb = (inserts - insOpens) / inserts
    1.29 +        if deletes > 0: delExtendProb = (deletes - delOpens) / deletes
    1.30 +        else:           delExtendProb = 0.5  # arbitrary
    1.31 +        if inserts > 0: insExtendProb = (inserts - insOpens) / inserts
    1.32 +        else:           insExtendProb = 0.5  # arbitrary
    1.33  
    1.34      print "# aligned letter pairs:", matches
    1.35      print "# deletes:", deletes
    1.36 @@ -119,8 +125,8 @@
    1.37      print "# delOpens:", delOpens
    1.38      print "# insOpens:", insOpens
    1.39      print "# alignments:", alignments
    1.40 -    print "# mean delete size: %g" % (deletes / delOpens)
    1.41 -    print "# mean insert size: %g" % (inserts / insOpens)
    1.42 +    if delOpens: print "# mean delete size: %g" % (deletes / delOpens)
    1.43 +    if insOpens: print "# mean insert size: %g" % (inserts / insOpens)
    1.44      print "# delOpenProb: %g" % delOpenProb
    1.45      print "# insOpenProb: %g" % insOpenProb
    1.46      print "# delExtendProb: %g" % delExtendProb