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