40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from percettrone import Percettrone
|
|
|
|
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
|
|
|
|
def stampa_operazione(p, y, x1, x2):
|
|
print("\n")
|
|
print(f"\tW1: {p.w1}")
|
|
print(f"X1: {x1} --------> ")
|
|
print(f"\t\t( bias: {p.bias} ) -------> Y: {y} ----> errore: {errore}")
|
|
print(f"X2: {x2} --------> ")
|
|
print(f"\tW2: {p.w2}")
|
|
|
|
# Singolo percettrone AND, OR
|
|
def stampa_risultati_single_layer():
|
|
print("Percettrone:")
|
|
print(f"\t W1: {p.w1}, W2: {p.w2}, bias: {p.bias}")
|
|
|
|
for i in range(1,100): #Epoche
|
|
if corrette == 4:
|
|
print(f"Epoche necessarie: {i-1}")
|
|
print(f"\t W1: {p.w1}, W2: {p.w2}, bias: {p.bias}")
|
|
break
|
|
|
|
print(f"\t\t\t\tEPOCA {i}")
|
|
corrette = 0;
|
|
|
|
for j in range(0,4): #Combinazioni
|
|
y = p.funzione_gradino(x[j][0], x[j][1])
|
|
errore = output[j] - y
|
|
stampa_operazione(p, y, x[j][0], x[j][1])
|
|
if errore != 0:
|
|
p.correggi_pesi(x[j][0], x[j][1], errore)
|
|
else:
|
|
corrette += 1
|