You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jo...@apache.org on 2011/06/06 17:22:33 UTC

svn commit: r1132668 - /incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/perceptron/PerceptronModel.java

Author: joern
Date: Mon Jun  6 15:22:33 2011
New Revision: 1132668

URL: http://svn.apache.org/viewvc?rev=1132668&view=rev
Log:
OPENNLP-154 Prior values are scaled down to be between -1 and 1 before the normalization is performed.

Modified:
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/perceptron/PerceptronModel.java

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/perceptron/PerceptronModel.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/perceptron/PerceptronModel.java?rev=1132668&r1=1132667&r2=1132668&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/perceptron/PerceptronModel.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/perceptron/PerceptronModel.java Mon Jun  6 15:22:33 2011
@@ -98,8 +98,16 @@ public class PerceptronModel extends Abs
     }    
     if (normalize) {
       int numOutcomes = model.getNumOutcomes();
+      
+      double maxPrior = 1;
+      
+      for (int oid = 0; oid < numOutcomes; oid++) {
+        if (maxPrior < Math.abs(prior[oid]))
+          maxPrior = Math.abs(prior[oid]);
+      }
+      
       for (int oid = 0; oid < numOutcomes; oid++)
-	prior[oid] = Math.exp(prior[oid]);
+	prior[oid] = Math.exp(prior[oid]/maxPrior);
 
       double normal = 0.0;
       for (int oid = 0; oid < numOutcomes; oid++)