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

26
percettrone.py Normal file
View File

@@ -0,0 +1,26 @@
class Percettrone:
def __init__(self, w1 = 0, w2 = 0, bias = 0, lre = 1):
self.w1 = w1
self.w2 = w2
self.bias = bias
self.lre = lre
def funzione_gradino(self, x1, x2):
if ((x1 * self.w1) + (x2 * self.w2) + self.bias) >= 0:
return 1
return 0
def valuta(self, x1, x2, risultato_atteso):
y = self.funzione_gradino(x1, x2)
errore = risultato_atteso - y
return errore
def correggi_pesi(self, x1, x2, errore):
self.bias = self.bias + (errore * self.lre)
#print(f"errore: {errore * self.bias}")
self.w1 = self.w1 + (errore * x1 * self.lre)
self.w2 = self.w2 + (errore * x2 * self.lre)
def get_pesi(self):
return (self.w1, self.w2, self.bias)