From a3be9daf027c7259e34349433772b51544564f36 Mon Sep 17 00:00:00 2001 From: lluni Date: Wed, 25 May 2022 17:28:03 +0200 Subject: [PATCH] Added LeakyReLu (parameter is currently hardcoded) --- src/main/java/ActivationFunctions.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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; + } }