-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivations.py
More file actions
48 lines (43 loc) · 963 Bytes
/
activations.py
File metadata and controls
48 lines (43 loc) · 963 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
36
37
38
39
40
41
42
43
44
45
46
47
48
'''Copyright (c) 2016 Jason Bunk
Covered by LICENSE.txt, which contains the "MIT License (Expat)".
'''
import numpy as np
class identity:
@staticmethod
def calc(x):
return x
@staticmethod
def calcderiv(x):
return np.ones(x.shape,dtype=x.dtype)
# ranges from 0 to 1
class sigmoid:
@staticmethod
def calc(x):
return np.divide(1., 1. + np.exp(x*-1.))
@staticmethod
def calcderiv(x):
return np.multiply(sigmoid.calc(x), sigmoid.calc(x)*-1. + 1.)
# ranges from -1 to 1
class tanh:
@staticmethod
def calc(x):
return np.tanh(x)
@staticmethod
def calcderiv(x):
return 1.0 - np.power(np.tanh(x), 2.)
# ranges from 0 to 1
class tanhadjusted:
@staticmethod
def calc(x):
return (np.tanh(x) + 1.) * 0.5
@staticmethod
def calcderiv(x):
return (1.0 - np.power(np.tanh(x), 2.)) * 0.5
# ranges from 0 to infinity
class relu:
@staticmethod
def calc(x):
return np.maximum(x,0.)
@staticmethod
def calcderiv(x):
return (np.sign(x)+1.)*0.5