Commits

Elias Ponvert committed da98893

adding entropy to stats output - fix 2

  • Participants
  • Parent commits 92a38a3
  • Branches dissertation-work

Comments (0)

Files changed (3)

File java/upparse/model/CombinedProb.java

           final String label = "P(" + tag + " => " + word + " " + nextTag + ")";
           final double val = prob[t][nextT][w] * backoffHmm.nonLogTrans(t, nextT);
           final double logProb = Math.log(val);
-          if (val != 0 && !Double.isNaN(val))
+          if (val != 0 && !Double.isNaN(val) && !Double.isInfinite(val))
             sumForEntropy += val * logProb;
           final RankedRecord<String> rec = new RankedRecord<String>(label, val);
           probRec.add(rec);

File java/upparse/model/EmissionProbs.java

         final String label = "P(" + word + "|" + tag + ")";
         final double val = emiss[t][w];
         final double probVal = Math.exp(val);
-        if (!Double.isNaN(val))
+        if (!Double.isNaN(val) && !Double.isInfinite(val))
           sumForEntropy += val * probVal;
         final RankedRecord<String> rec = new RankedRecord<String>(label, probVal);
         emissRec.add(rec);

File java/upparse/model/HMM.java

         final String label = "P(" + t2Tag + "|" + t1Tag + ")";
         final double val = trans[t1][t2];
         final double probVal = Math.exp(val);
-        if (!Double.isNaN(val))
+        if (!Double.isNaN(val) && !Double.isInfinite(val))
           sumForEntropy += val * probVal;
         final double scaleVal = 100.0 * probVal;
         final String templ = "%s = %.1f\n";