-
Notifications
You must be signed in to change notification settings - Fork 0
/
evo_globals.py
47 lines (37 loc) · 908 Bytes
/
evo_globals.py
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
36
37
38
39
40
41
42
43
44
45
46
47
net_dir = "nets"
import os
from . import helpers
if not os.path.exists(helpers.rel_path(net_dir)):
try:
os.mkdir(helpers.rel_path(net_dir))
except OSError:
pass
##################
### Activators ###
import math
curr_activator = "tanh" # tanh is preferred
def activator(val):
return activators[curr_activator](val)
activators = {}
activators["tanh"] = math.tanh
def sigmoid(val): return 1/(1+math.exp(-val))
activators["sigmoid"] = sigmoid
def relu(val): return max(0,val)
activators["relu"] = relu
###################
### Derivatives ###
def derivative(val):
return derivatives[curr_activator](val)
derivatives = {}
def dtanh(x):
return 1 - (math.tanh(x)**2)
derivatives["tanh"] = dtanh
def dsigmoid(x):
return x * (1 - x)
derivatives["sigmoid"] = dsigmoid
def drelu(x):
if x >= 0:
return 1
else:
return 0
derivatives["relu"] = drelu