Author: yxjiang
Date: Fri Jul 12 12:57:23 2013
New Revision: 1502542
URL: http://svn.apache.org/r1502542
Log:
HAMA-777: FunctionFactory does not work when create IdentityFunction
Added:
hama/trunk/ml/src/main/java/org/apache/hama/ml/math/IdentityFunction.java
Modified:
hama/trunk/CHANGES.txt
hama/trunk/ml/src/main/java/org/apache/hama/ml/math/FunctionFactory.java
hama/trunk/ml/src/test/java/org/apache/hama/ml/math/TestFunctionFactory.java
Modified: hama/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hama/trunk/CHANGES.txt?rev=1502542&r1=1502541&r2=1502542&view=diff
==============================================================================
--- hama/trunk/CHANGES.txt (original)
+++ hama/trunk/CHANGES.txt Fri Jul 12 12:57:23 2013
@@ -8,6 +8,7 @@ Release 0.6.3 (unreleased changes)
HAMA-769: Intermediate queue's close method is not called, clean work may
be omitted (kennethxian)
HAMA-771: Determining the count of active vertices (edwardyoon)
+ HAMA-777: FunctionFactory does not work when create IdentityFunction (Yexi
Jiang)
IMPROVEMENTS
Modified:
hama/trunk/ml/src/main/java/org/apache/hama/ml/math/FunctionFactory.java
URL:
http://svn.apache.org/viewvc/hama/trunk/ml/src/main/java/org/apache/hama/ml/math/FunctionFactory.java?rev=1502542&r1=1502541&r2=1502542&view=diff
==============================================================================
--- hama/trunk/ml/src/main/java/org/apache/hama/ml/math/FunctionFactory.java
(original)
+++ hama/trunk/ml/src/main/java/org/apache/hama/ml/math/FunctionFactory.java
Fri Jul 12 12:57:23 2013
@@ -30,10 +30,13 @@ public class FunctionFactory {
* @return
*/
public static DoubleFunction createDoubleFunction(String functionName) {
- if (functionName.equals(Sigmoid.class.getSimpleName())) {
+ if (functionName.equalsIgnoreCase(Sigmoid.class.getSimpleName())) {
return new Sigmoid();
- } else if (functionName.equals(Tanh.class.getSimpleName())) {
+ } else if (functionName.equalsIgnoreCase(Tanh.class.getSimpleName())) {
return new Tanh();
+ } else if (functionName.equalsIgnoreCase(IdentityFunction.class
+ .getSimpleName())) {
+ return new IdentityFunction();
}
throw new IllegalArgumentException(String.format(
@@ -48,9 +51,10 @@ public class FunctionFactory {
*/
public static DoubleDoubleFunction createDoubleDoubleFunction(
String functionName) {
- if (functionName.equals(SquaredError.class.getSimpleName())) {
+ if (functionName.equalsIgnoreCase(SquaredError.class.getSimpleName())) {
return new SquaredError();
- } else if (functionName.equals(CrossEntropy.class.getSimpleName())) {
+ } else if (functionName
+ .equalsIgnoreCase(CrossEntropy.class.getSimpleName())) {
return new CrossEntropy();
}
Added: hama/trunk/ml/src/main/java/org/apache/hama/ml/math/IdentityFunction.java
URL:
http://svn.apache.org/viewvc/hama/trunk/ml/src/main/java/org/apache/hama/ml/math/IdentityFunction.java?rev=1502542&view=auto
==============================================================================
--- hama/trunk/ml/src/main/java/org/apache/hama/ml/math/IdentityFunction.java
(added)
+++ hama/trunk/ml/src/main/java/org/apache/hama/ml/math/IdentityFunction.java
Fri Jul 12 12:57:23 2013
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.ml.math;
+
+/**
+ * The identity function f(x) = x.
+ *
+ */
+public class IdentityFunction extends DoubleFunction {
+
+ @Override
+ public double apply(double value) {
+ return value;
+ }
+
+ @Override
+ public double applyDerivative(double value) {
+ return 0;
+ }
+
+}
Modified:
hama/trunk/ml/src/test/java/org/apache/hama/ml/math/TestFunctionFactory.java
URL:
http://svn.apache.org/viewvc/hama/trunk/ml/src/test/java/org/apache/hama/ml/math/TestFunctionFactory.java?rev=1502542&r1=1502541&r2=1502542&view=diff
==============================================================================
---
hama/trunk/ml/src/test/java/org/apache/hama/ml/math/TestFunctionFactory.java
(original)
+++
hama/trunk/ml/src/test/java/org/apache/hama/ml/math/TestFunctionFactory.java
Fri Jul 12 12:57:23 2013
@@ -19,6 +19,8 @@ package org.apache.hama.ml.math;
import static org.junit.Assert.assertEquals;
+import java.util.Random;
+
import org.junit.Test;
/**
@@ -39,12 +41,21 @@ public class TestFunctionFactory {
double sigmoidExcepted = 0.68997448;
assertEquals(sigmoidExcepted, sigmoidFunction.apply(input), 0.000001);
+
String tanhName = "Tanh";
DoubleFunction tanhFunction =
FunctionFactory.createDoubleFunction(tanhName);
assertEquals(tanhName, tanhFunction.getFunctionName());
double tanhExpected = 0.66403677;
assertEquals(tanhExpected, tanhFunction.apply(input), 0.00001);
+
+
+ String identityFunctionName = "IdentityFunction";
+ DoubleFunction identityFunction =
FunctionFactory.createDoubleFunction(identityFunctionName);
+
+ Random rnd = new Random();
+ double identityExpected = rnd.nextDouble();
+ assertEquals(identityExpected, identityFunction.apply(identityExpected),
0.000001);
}
@Test