add HardClip activation layer
This commit is contained in:
parent
44cae4ad50
commit
4746103978
1 changed files with 14 additions and 0 deletions
|
@ -206,3 +206,17 @@ class Arcsinh(Layer):
|
||||||
|
|
||||||
def backward(self, dY):
|
def backward(self, dY):
|
||||||
return dY / np.sqrt(self.X * self.X + 1)
|
return dY / np.sqrt(self.X * self.X + 1)
|
||||||
|
|
||||||
|
|
||||||
|
class HardClip(Layer): # aka HardTanh when at default settings
|
||||||
|
def __init__(self, lower=-1.0, upper=1.0):
|
||||||
|
super().__init__()
|
||||||
|
self.lower = _f(lower)
|
||||||
|
self.upper = _f(upper)
|
||||||
|
|
||||||
|
def forward(self, X):
|
||||||
|
self.X = X
|
||||||
|
return np.clip(X, self.lower, self.upper)
|
||||||
|
|
||||||
|
def backward(self, dY):
|
||||||
|
return dY * ((self.X <= self.lower) & (self.X >= self.upper))
|
||||||
|
|
Loading…
Reference in a new issue