32 lines
816 B
Python
32 lines
816 B
Python
from percettrone import Percettrone
|
|
from stampe_video import disegna_funzione, stampa_risultati_single_layer
|
|
|
|
x = [(0,0),(0,1),(1,0),(1,1)] # Combinazioni
|
|
#output = (0,0,0,1) # AND Logico
|
|
output = (0,1,1,1) # OR Logico
|
|
|
|
p = Percettrone()
|
|
corrette = 0 #Fermo le epoche se termina prima
|
|
|
|
for i in range(1,100): #Epoche
|
|
|
|
if corrette == 4:
|
|
print(f"Epoche necessarie: {i-1}")
|
|
stampa_risultati_single_layer(p)
|
|
break
|
|
|
|
print(f"EPOCA {i}")
|
|
corrette = 0;
|
|
|
|
for j in range(0,4): #Combinazioni
|
|
y = p.funzione_gradino(x[j][0], x[j][1])
|
|
errore = output[j] - y
|
|
|
|
print("\n")
|
|
disegna_funzione(p, y, x[j][0], x[j][1], True, errore)
|
|
|
|
if errore != 0:
|
|
p.correggi_pesi(x[j][0], x[j][1], errore)
|
|
else:
|
|
corrette += 1
|