-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActivationFunctions.py
More file actions
35 lines (26 loc) · 852 Bytes
/
ActivationFunctions.py
File metadata and controls
35 lines (26 loc) · 852 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
35
import numpy as np
from level import level
from activation import Activation
class Tanh(Activation):
def __init__(element):
def tanh(x):
return np.tanh(x)
def tan_h(x):
a = 1 - np.tanh(x) ** 2
return a
class Sigmoid(Activation):
def __init__(element):
def sigmoid(input):
sg = 1 / (1 + np.exp(-input))
return sg
def sig_moid(x):
s = sigmoid(x)
return s * (1 - s)
class Softmax(level):
def forProp(element, input):
tempVal = np.exp(input)
element.output = tempVal / np.sum(tempVal)
return element.output
def backProp(element, output_gradient, alpha):
lim = np.size(element.output)
return np.dot((np.identity(lim) - element.output.T) * element.output, output_gradient)