soluzione funzionante per AND, OR, XOR. Funzione sigmoide. Funziona solo con i certi bias

This commit is contained in:
2025-01-23 11:28:01 +01:00
parent 9e9e9923fe
commit 32cbb7c6cb
4 changed files with 68 additions and 30 deletions

View File

@@ -1,17 +1,21 @@
class Percettrone:
import math
def __init__(self, w1 = 1, w2 = 1, bias = 1, lre = 1):
class Percettrone:
def __init__(self, w1 = 1, w2 = 1, bias = 1, lre = 0.2):
self.w1 = w1
self.w2 = w2
self.bias = bias
self.lre = lre
# # il return verrà confrontato col valore di soglia di attivazione
def funzione_gradino(self, x1, x2):
if ((x1 * self.w1) + (x2 * self.w2) + self.bias) >= 0:
return 1
return 0
return ((x1 * self.w1) + (x2 * self.w2) + self.bias)
# il return verrà confrontato col valore di soglia di attivazione
def funzione_sigmoide(self, x1, x2):
return (1 / (1 + math.exp(-((x1 * self.w1) + (x2 * self.w2) + self.bias))))
def correggi_pesi(self, x1, x2, errore):
self.bias = self.bias + (errore * self.lre)
self.w1 = self.w1 + (errore * x1 * self.lre)
self.w2 = self.w2 + (errore * x2 * self.lre)
def correggi_pesi(self, gradiente_w1, gradiente_w2, gradiente_bias):
self.bias = self.bias - (gradiente_bias * self.lre)
self.w1 = self.w1 - (gradiente_w1 * self.lre)
self.w2 = self.w2 - (gradiente_w2 * self.lre)