Author: tommaso
Date: Tue Nov 13 15:09:47 2012
New Revision: 1408773

URL: http://svn.apache.org/viewvc?rev=1408773&view=rev
Log:
[HAMA-668] - added an assertion to check h to be within 0 and 1

Modified:
    
hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/LogisticRegressionModel.java

Modified: 
hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/LogisticRegressionModel.java
URL: 
http://svn.apache.org/viewvc/hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/LogisticRegressionModel.java?rev=1408773&r1=1408772&r2=1408773&view=diff
==============================================================================
--- 
hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/LogisticRegressionModel.java
 (original)
+++ 
hama/trunk/ml/src/main/java/org/apache/hama/ml/regression/LogisticRegressionModel.java
 Tue Nov 13 15:09:47 2012
@@ -30,7 +30,10 @@ public class LogisticRegressionModel imp
     costFunction = new CostFunction() {
       @Override
       public double calculateCostForItem(DoubleVector x, double y, int m, 
DoubleVector theta, HypothesisFunction hypothesis) {
-        return (-1 * y * Math.log(applyHypothesis(theta, x)) + (1 - y) * 
Math.log(1 - applyHypothesis(theta, x))) / m;
+          double h = applyHypothesis(theta, x);
+          assert h > 0 && h < 1 : new StringBuilder("cannot calculate the log 
of a number equal to / less than zero [h:").
+                  append(h).append(" in log(h) and log(1-h)]").toString();
+          return (-1 * y * Math.log(h) + (1 - y) * Math.log(1 - h)) / m;
       }
     };
   }


Reply via email to