-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
48 lines (35 loc) · 992 Bytes
/
functions.py
File metadata and controls
48 lines (35 loc) · 992 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
import math
import random
def ReLU(x): return (max(0, x))
def derivReLU(x):
return (1 if x > 0 else 0)
def leakyReLU(x): return (max(0.01*x, x))
def derivLeakyReLU(x):
return (1 if x > 0 else 0.01)
def sigmoid(x):
# print(x)
try:
return (1/(1+(math.e**(-x))))
except:
print(x)
raise Exception
def derivSigmoid(x):
sig = sigmoid(x)
return sig * (1-sig)
def gen_data(function, amount, negative=True):
# function should take in one input and return one output
start = -amount//2 if negative else 0
end = -start if negative else amount
data = []
for i in range(start, end):
data.append([[i], [function(i)]])
random.shuffle(data)
return data
def gen_range(function, min, max, amount):
# same as gen_data but from min-max, doing floats
data = []
step = (max-min)/amount
for i in range(amount):
current = i*step + min
data.append([[current], [function(current)]])
return data