You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hama.apache.org by to...@apache.org on 2012/11/03 14:58:56 UTC
svn commit: r1405337 -
/hama/trunk/ml/src/test/java/org/apache/hama/ml/regression/LogisticRegressionModelTest.java
Author: tommaso
Date: Sat Nov 3 13:58:56 2012
New Revision: 1405337
URL: http://svn.apache.org/viewvc?rev=1405337&view=rev
Log:
[HAMA-666] - adding unit test for logistic regression
Added:
hama/trunk/ml/src/test/java/org/apache/hama/ml/regression/LogisticRegressionModelTest.java (with props)
Added: hama/trunk/ml/src/test/java/org/apache/hama/ml/regression/LogisticRegressionModelTest.java
URL: http://svn.apache.org/viewvc/hama/trunk/ml/src/test/java/org/apache/hama/ml/regression/LogisticRegressionModelTest.java?rev=1405337&view=auto
==============================================================================
--- hama/trunk/ml/src/test/java/org/apache/hama/ml/regression/LogisticRegressionModelTest.java (added)
+++ hama/trunk/ml/src/test/java/org/apache/hama/ml/regression/LogisticRegressionModelTest.java Sat Nov 3 13:58:56 2012
@@ -0,0 +1,31 @@
+package org.apache.hama.ml.regression;
+
+import org.apache.hama.ml.math.DenseDoubleVector;
+import org.apache.hama.ml.math.DoubleVector;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Testcase for {@link LogisticRegressionModel}
+ */
+public class LogisticRegressionModelTest {
+
+ @Test
+ public void testCorrectCostCalculation() throws Exception {
+ LogisticRegressionModel logisticRegressionModel = new LogisticRegressionModel();
+ DoubleVector x = new DenseDoubleVector(new double[]{2, 3, 4});
+ double y = 1;
+ DoubleVector theta = new DenseDoubleVector(new double[]{1, 1, 1});
+ Double cost = logisticRegressionModel.calculateCostForItem(x, y, 2, theta);
+ assertEquals("wrong cost calculation for logistic regression", Double.valueOf(16d), cost);
+ }
+
+ @Test
+ public void testCorrectHypothesisCalculation() throws Exception {
+ LogisticRegressionModel logisticRegressionModel = new LogisticRegressionModel();
+ Double hypothesisValue = logisticRegressionModel.applyHypothesis(new DenseDoubleVector(new double[]{1, 1, 1}),
+ new DenseDoubleVector(new double[]{2, 3, 4}));
+ assertEquals("wrong hypothesis value for logistic regression", Double.valueOf(0.9998766054240137), hypothesisValue);
+ }
+}
Propchange: hama/trunk/ml/src/test/java/org/apache/hama/ml/regression/LogisticRegressionModelTest.java
------------------------------------------------------------------------------
svn:eol-style = native