Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion joey/activation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abc import ABC, abstractmethod
from sympy import Max, sign
from sympy import Max, Min, sign
from devito import Eq


Expand Down Expand Up @@ -50,6 +50,21 @@ def backprop_eqs(self, layer):
* Max(0, sign(layer.result[dims])))]


class LeakyReLU(Activation):
"""An Activation subclass corresponding to ReLU."""
def __init__(self, negative_slope=0.01):
self.negative_slope = negative_slope
super().__init__(lambda x: x if x > 0 else x*negative_slope)

def backprop_eqs(self, layer):
dims = layer.result_gradients.dimensions
return [Eq(layer.result_gradients[dims],
layer.result_geadients[dims]
* (Max(0, sign(layer.result[dims])
+ Min(0, sign(layer.result[dims]
* self.negative_slope)))))]


class Dummy(Activation):
"""An Activation subclass corresponding to f(x) = x."""

Expand Down