diff --git a/src/main/java/ActivationFunctions.java b/src/main/java/ActivationFunctions.java index ae5e7c8..34118c6 100644 --- a/src/main/java/ActivationFunctions.java +++ b/src/main/java/ActivationFunctions.java @@ -52,4 +52,20 @@ public class ActivationFunctions { } return B; } + + public static SimpleMatrix LeakyReLu(SimpleMatrix A) { + SimpleMatrix B = new SimpleMatrix(A); + for (int i = 0; i < A.getNumElements(); i++) { + B.set(i, Math.max(0.001 * A.get(i), A.get(i))); + } + return B; + } + + public static SimpleMatrix LeakyReLuPrime(SimpleMatrix A) { + SimpleMatrix B = new SimpleMatrix(A); + for (int i = 0; i < A.getNumElements(); i++) { + B.set(i, A.get(i) < 0 ? 0.001 : 1); + } + return B; + } }