You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@horn.apache.org by mi...@apache.org on 2015/11/19 10:45:21 UTC

[1/2] incubator-horn git commit: HORN-9: Add activations package and ReLU function

Repository: incubator-horn
Updated Branches:
  refs/heads/master c10b6f67d -> 22cc9742b


HORN-9: Add activations package and ReLU function

Rename activations to funcs


Project: http://git-wip-us.apache.org/repos/asf/incubator-horn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-horn/commit/b0151fd8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-horn/tree/b0151fd8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-horn/diff/b0151fd8

Branch: refs/heads/master
Commit: b0151fd825f4ab5ae5b8424cc5cd5553cd82db23
Parents: 0aeefcd
Author: Edward J. Yoon <ed...@apache.org>
Authored: Tue Nov 17 16:56:47 2015 +0900
Committer: Edward J. Yoon <ed...@apache.org>
Committed: Wed Nov 18 14:39:15 2015 +0900

----------------------------------------------------------------------
 .../org/apache/horn/funcs/CrossEntropy.java     | 60 ++++++++++++++++++++
 .../java/org/apache/horn/funcs/Identity.java    | 38 +++++++++++++
 src/main/java/org/apache/horn/funcs/ReLU.java   | 41 +++++++++++++
 .../java/org/apache/horn/funcs/Sigmoid.java     | 41 +++++++++++++
 .../org/apache/horn/funcs/SquaredError.java     | 48 ++++++++++++++++
 src/main/java/org/apache/horn/funcs/Tanh.java   | 38 +++++++++++++
 6 files changed, 266 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-horn/blob/b0151fd8/src/main/java/org/apache/horn/funcs/CrossEntropy.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/horn/funcs/CrossEntropy.java b/src/main/java/org/apache/horn/funcs/CrossEntropy.java
new file mode 100644
index 0000000..567db29
--- /dev/null
+++ b/src/main/java/org/apache/horn/funcs/CrossEntropy.java
@@ -0,0 +1,60 @@
+/**
+ * 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.horn.funcs;
+
+import org.apache.hama.commons.math.DoubleDoubleFunction;
+
+/**
+ * The cross entropy cost function.
+ * 
+ * <pre>
+ * cost(t, y) = - t * log(y) - (1 - t) * log(1 - y),
+ * where t denotes the target value, y denotes the estimated value.
+ * </pre>
+ */
+public class CrossEntropy extends DoubleDoubleFunction {
+
+  @Override
+  public double apply(double target, double actual) {
+    double adjustedTarget = (target == 0 ? 0.000001 : target);
+    adjustedTarget = (target == 1.0 ? 0.999999 : target);
+    double adjustedActual = (actual == 0 ? 0.000001 : actual);
+    adjustedActual = (actual == 1 ? 0.999999 : actual);
+    return -adjustedTarget * Math.log(adjustedActual) - (1 - adjustedTarget)
+        * Math.log(1 - adjustedActual);
+  }
+
+  @Override
+  public double applyDerivative(double target, double actual) {
+    double adjustedTarget = target;
+    double adjustedActual = actual;
+    if (adjustedActual == 1) {
+      adjustedActual = 0.999;
+    } else if (actual == 0) {
+      adjustedActual = 0.001;
+    }
+    if (adjustedTarget == 1) {
+      adjustedTarget = 0.999;
+    } else if (adjustedTarget == 0) {
+      adjustedTarget = 0.001;
+    }
+    return -adjustedTarget / adjustedActual + (1 - adjustedTarget)
+        / (1 - adjustedActual);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-horn/blob/b0151fd8/src/main/java/org/apache/horn/funcs/Identity.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/horn/funcs/Identity.java b/src/main/java/org/apache/horn/funcs/Identity.java
new file mode 100644
index 0000000..d8c8380
--- /dev/null
+++ b/src/main/java/org/apache/horn/funcs/Identity.java
@@ -0,0 +1,38 @@
+/**
+ * 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.horn.funcs;
+
+import org.apache.hama.commons.math.DoubleFunction;
+
+/**
+ * The identity function f(x) = x.
+ * 
+ */
+public class Identity extends DoubleFunction {
+
+  @Override
+  public double apply(double value) {
+    return value;
+  }
+
+  @Override
+  public double applyDerivative(double value) {
+    return 1;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-horn/blob/b0151fd8/src/main/java/org/apache/horn/funcs/ReLU.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/horn/funcs/ReLU.java b/src/main/java/org/apache/horn/funcs/ReLU.java
new file mode 100644
index 0000000..425137f
--- /dev/null
+++ b/src/main/java/org/apache/horn/funcs/ReLU.java
@@ -0,0 +1,41 @@
+/**
+ * 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.horn.funcs;
+
+import org.apache.hama.commons.math.DoubleFunction;
+
+/**
+ * The rectifier function
+ * 
+ * <pre>
+ * f(x) = max(0, x)
+ * </pre>
+ */
+public class ReLU extends DoubleFunction {
+
+  @Override
+  public double apply(double value) {
+    return Math.max(0, value);
+  }
+
+  @Override
+  public double applyDerivative(double value) {
+    return (value > Double.MIN_VALUE) ? 1 : 0;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-horn/blob/b0151fd8/src/main/java/org/apache/horn/funcs/Sigmoid.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/horn/funcs/Sigmoid.java b/src/main/java/org/apache/horn/funcs/Sigmoid.java
new file mode 100644
index 0000000..4472b8a
--- /dev/null
+++ b/src/main/java/org/apache/horn/funcs/Sigmoid.java
@@ -0,0 +1,41 @@
+/**
+ * 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.horn.funcs;
+
+import org.apache.hama.commons.math.DoubleFunction;
+
+/**
+ * The Sigmoid function
+ * 
+ * <pre>
+ * f(x) = 1 / (1 + e^{-x})
+ * </pre>
+ */
+public class Sigmoid extends DoubleFunction {
+
+  @Override
+  public double apply(double value) {
+    return 1.0 / (1 + Math.exp(-value));
+  }
+
+  @Override
+  public double applyDerivative(double value) {
+    return value * (1 - value);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-horn/blob/b0151fd8/src/main/java/org/apache/horn/funcs/SquaredError.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/horn/funcs/SquaredError.java b/src/main/java/org/apache/horn/funcs/SquaredError.java
new file mode 100644
index 0000000..081c53d
--- /dev/null
+++ b/src/main/java/org/apache/horn/funcs/SquaredError.java
@@ -0,0 +1,48 @@
+/**
+ * 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.horn.funcs;
+
+import org.apache.hama.commons.math.DoubleDoubleFunction;
+
+/**
+ * Square error cost function.
+ * 
+ * <pre>
+ * cost(t, y) = 0.5 * (t - y) &circ; 2
+ * </pre>
+ */
+public class SquaredError extends DoubleDoubleFunction {
+
+  @Override
+  /**
+   * {@inheritDoc}
+   */
+  public double apply(double target, double actual) {
+    double diff = target - actual;
+    return 0.5 * diff * diff;
+  }
+
+  @Override
+  /**
+   * {@inheritDoc}
+   */
+  public double applyDerivative(double target, double actual) {
+    return actual - target;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-horn/blob/b0151fd8/src/main/java/org/apache/horn/funcs/Tanh.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/horn/funcs/Tanh.java b/src/main/java/org/apache/horn/funcs/Tanh.java
new file mode 100644
index 0000000..c7ced33
--- /dev/null
+++ b/src/main/java/org/apache/horn/funcs/Tanh.java
@@ -0,0 +1,38 @@
+/**
+ * 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.horn.funcs;
+
+import org.apache.hama.commons.math.DoubleFunction;
+
+/**
+ * Tanh function.
+ * 
+ */
+public class Tanh extends DoubleFunction {
+
+  @Override
+  public double apply(double value) {
+    return Math.tanh(value);
+  }
+
+  @Override
+  public double applyDerivative(double value) {
+    return 1 - Math.pow(Math.tanh(value), 2);
+  }
+  
+}


[2/2] incubator-horn git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-horn into HORN-9

Posted by mi...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-horn into HORN-9


Project: http://git-wip-us.apache.org/repos/asf/incubator-horn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-horn/commit/22cc9742
Tree: http://git-wip-us.apache.org/repos/asf/incubator-horn/tree/22cc9742
Diff: http://git-wip-us.apache.org/repos/asf/incubator-horn/diff/22cc9742

Branch: refs/heads/master
Commit: 22cc9742bfc699a5dbcb475d745cf3293e275d2d
Parents: b0151fd c10b6f6
Author: Minho Kim <mi...@samsung.com>
Authored: Thu Nov 19 18:43:45 2015 +0900
Committer: Minho Kim <mi...@samsung.com>
Committed: Thu Nov 19 18:43:45 2015 +0900

----------------------------------------------------------------------
 README.md | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
----------------------------------------------------------------------