summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorLester Solbakken <lesters@oath.com>2018-01-10 09:11:04 +0100
committerLester Solbakken <lesters@oath.com>2018-01-11 11:17:08 +0100
commitf3ae39125a550565e6edd6256c063072476f9d5e (patch)
treefc0437783fb6af3a088c5cb5807648378a3715d0 /vespajlib
parent36ce12ede6f05199f219a028d6687bab1eee0a6e (diff)
TensorFlow import of name scopes and new activation functions.
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/functions/ScalarFunctions.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/ScalarFunctions.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/ScalarFunctions.java
index f1dadba2a29..4d1abf3978f 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/functions/ScalarFunctions.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/ScalarFunctions.java
@@ -27,7 +27,10 @@ public class ScalarFunctions {
public static DoubleBinaryOperator multiply() { return new Multiply(); }
public static DoubleUnaryOperator acos() { return new Acos(); }
+ public static DoubleUnaryOperator elu() { return new Elu(); }
public static DoubleUnaryOperator exp() { return new Exp(); }
+ public static DoubleUnaryOperator relu() { return new Relu(); }
+ public static DoubleUnaryOperator sigmoid() { return new Sigmoid(); }
public static DoubleUnaryOperator sqrt() { return new Sqrt(); }
public static DoubleUnaryOperator square() { return new Square(); }
@@ -81,6 +84,27 @@ public class ScalarFunctions {
public String toString() { return "f(a)(acos(a))"; }
}
+ public static class Elu implements DoubleUnaryOperator {
+ @Override
+ public double applyAsDouble(double operand) { return operand < 0 ? Math.exp(operand) -1 : operand; }
+ @Override
+ public String toString() { return "f(a)(if(a < 0, exp(a)-1, a))"; }
+ }
+
+ public static class Relu implements DoubleUnaryOperator {
+ @Override
+ public double applyAsDouble(double operand) { return Math.max(operand, 0); }
+ @Override
+ public String toString() { return "f(a)(max(0, a))"; }
+ }
+
+ public static class Sigmoid implements DoubleUnaryOperator {
+ @Override
+ public double applyAsDouble(double operand) { return 1.0 / (1.0 + Math.exp(-operand)); }
+ @Override
+ public String toString() { return "f(a)(1 / (1 + exp(-a)))"; }
+ }
+
public static class Sqrt implements DoubleUnaryOperator {
@Override
public double applyAsDouble(double operand) { return Math.sqrt(operand); }