primo push

This commit is contained in:
2025-01-22 17:37:26 +01:00
parent 2e863f4e08
commit 86d5442838
3 changed files with 150 additions and 0 deletions

38
single_layer.py Normal file
View File

@@ -0,0 +1,38 @@
from percettrone import Percettrone
x = [(0,0),(0,1),(1,0),(1,1)] # Combinazioni
output = (0,0,0,1) # AND 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 = p.valuta(x[j][0], x[j][1], output[j])
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