Revision: 17815
          http://sourceforge.net/p/gate/code/17815
Author:   adamfunk
Date:     2014-04-11 13:55:26 +0000 (Fri, 11 Apr 2014)
Log Message:
-----------
Prevent division by zero; fix bug #144.

Modified Paths:
--------------
    gate/trunk/src/main/gate/util/ClassificationMeasures.java

Modified: gate/trunk/src/main/gate/util/ClassificationMeasures.java
===================================================================
--- gate/trunk/src/main/gate/util/ClassificationMeasures.java   2014-04-11 
13:27:42 UTC (rev 17814)
+++ gate/trunk/src/main/gate/util/ClassificationMeasures.java   2014-04-11 
13:55:26 UTC (rev 17815)
@@ -318,6 +318,7 @@
         sum += confusionMatrix[j][i];
       marginalArrayR[i] = sum;
     }
+    
     // Compute Cohen's p(E)
     float pE = 0;
     if(totalSum > 0) {
@@ -325,10 +326,15 @@
       for(int i = 0; i < numCats; ++i)
         pE += (marginalArrayC[i] * marginalArrayR[i]) / doubleSum;
     }
+    
     // Compute Cohen's Kappa
-    if(totalSum > 0) // FIXME: division by zero when pE = 1
-      kappaCohen = (observedAgreement - pE) / (1 - pE);
+    if (pE == 1.0F) { // prevent division by zero
+      kappaCohen = 1.0F;
+    }
+    else if (totalSum > 0) 
+      kappaCohen = (observedAgreement - pE) / (1.0F - pE);
     else kappaCohen = 0;
+    
     // Compute S&C's chance agreement
     pE = 0;
     if(totalSum > 0) {
@@ -338,9 +344,14 @@
         pE += p * p;
       }
     }
-    if(totalSum > 0) // FIXME: division by zero when pE = 1
-      kappaPi = (observedAgreement - pE) / (1 - pE);
+    
+    if (pE == 1.0F) { // prevent division by zero
+      kappaPi = 1.0F;
+    }
+    else if (totalSum > 0)
+      kappaPi = (observedAgreement - pE) / (1.0F - pE);
     else kappaPi = 0;
+    
     // Compute the specific agreement for each label using marginal sums
     float[][] sAgreements = new float[numCats][2];
     for(int i = 0; i < numCats; ++i) {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment 
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to