primo push
This commit is contained in:
38
single_layer.py
Normal file
38
single_layer.py
Normal 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
|
||||
Reference in New Issue
Block a user