-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathann.py
101 lines (64 loc) · 1.36 KB
/
ann.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import math as m
# Distribution Functions
# Multiplication
def multiplication(n, net, threshold):
i = 0
weight = 1
while i < n:
weight *= (net[i] * threshold[i])
i += 1
return weight
# Maximum
def maximum(net, threshold):
return max(net, threshold)
# Minimum
def minimum(net, threshold):
return min(net, threshold)
# Sum
def sum(n, net, threshold):
i = 0
weight = 0
while i < n:
weight += (net[i] * threshold[i])
i += 1
return weight
# Cumulative Distribution
def cumulative(n, net, threshold):
i = 0
weight = 1
while i < n:
weight += weight * (net[i] * threshold[i])
i += 1
return weight
# Activation Functions
# Sigmoid
def sigmoid(x):
return 1 / (1 + m.pow(m.e, -x))
# Linear
def linear(net):
return net
# ReLu
def relu(net):
if net > 1:
return 1
elif net > -1 or net < 1:
return net
else:
return -1
# Step
def step(net, threshold):
if net > threshold:
return 1
elif net <= threshold:
return 0
else:
return -1
# Sinusoid
def sinusoid(net):
return m.sin(m.radians(net))
# Hyperbolic Tangent
def htan(net):
return m.tanh(m.radians(net))
# Hyperbolic Tangent - 2
def htan2(net):
return (m.pow(m.e, net) + m.pow(m.e, -net)) / (m.pow(m.e, net) - m.pow(m.e, -net))