-
Notifications
You must be signed in to change notification settings - Fork 0
/
nn.py
47 lines (27 loc) · 776 Bytes
/
nn.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
import math
input = 0
output_desire = 0
input_weight = 0.5
learning_rate = 0.1
def activation(sum):
if sum >= 0:
return 1
else:
return 0
print("entrada", input, "desejado", output_desire)
error = math.inf
iteration = 0
bias = 1
bias_weight = 0.5
while not error == 0:
iteration += 1
print("#### Iteration: ", iteration)
print("Input weight: ", input_weight)
sum = (input * input_weight) + (bias * bias_weight)
output = activation(sum)
print("saida", output)
error = output_desire - output
if not error == 0:
input_weight = input_weight + (learning_rate * input * error)
bias_weight = bias_weight + (learning_rate * bias * error)
print("Convergiu!")