-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActivations.py
More file actions
37 lines (22 loc) · 765 Bytes
/
Copy pathActivations.py
File metadata and controls
37 lines (22 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import numpy as np
from abc import ABC, abstractmethod
class Activation(ABC):
def __init__(self) -> None:
pass
@abstractmethod
def forward(self, x) -> np.ndarray:
pass
@abstractmethod
def Differential(self, x) -> np.ndarray:
pass
class ReLu(Activation):
def __init__(self) -> None:
super().__init__()
def singleForward(self, x):
return np.array([y if y >= 0 else 0 for y in x])
def forward(self, x) -> np.ndarray:
return np.array([self.singleForward(y) for y in x])
def singleDifferential(self, x):
return np.array([1 if y >= 0 else 0 for y in x])
def Differential(self, x) -> np.ndarray:
return np.array([self.singleDifferential(y) for y in x])