Last active
July 15, 2020 20:31
-
-
Save CarlosOrtiz/af1d213d27cde7fd4603fc9ee5cf77b4 to your computer and use it in GitHub Desktop.
Entrenamiento del perceptrón para detectar la sintomatología de un infarto.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
W = [4, 67, 21, 54, 11] | |
X1 =[21, 23, 30, 25, 33.9, 34.9, 35, 35.3, 32, 37] | |
X2 =[120, 122, 140, 90, 98, 149, 150, 160, 110, 180] | |
X3 =[190, 215, 240, 202, 120, 260, 85, 300, 305, 290] | |
X4 =[90, 119, 170, 100, 126, 179, 194, 200, 300, 240] | |
X5 =[1, 0, 0, 1, 1, 0, 1, 0, 0, 0] | |
salidaEsperada = [-1, -1, 1, -1, -1, 1, 1, 1, 1, 1] | |
bias = -9 | |
epocas = 0 | |
iterar = True | |
datosObtenidos=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0] | |
while iterar: | |
iterar = False | |
epocas += 1 | |
for i in range(10): | |
y = ((X1[i]*W[0]) + (X2[i]*W[1]) + (X3[i]*W[2]) + | |
(X4[i]*W[3]) + (X5[i]*W[4]) + bias) | |
print(str(i+1) + ' ' + str(y)) | |
y = 1 if y > 0 else -1 | |
if y!= salidaEsperada[i]: | |
bias = bias+(0.5 * (salidaEsperada[i]-y))*-1 | |
W[0] = W[0]+0.5*(salidaEsperada[i]-y)*X1[i] | |
W[1] = W[1]+0.5*(salidaEsperada[i]-y)*X2[i] | |
W[2] = W[2]+0.5*(salidaEsperada[i]-y)*X3[i] | |
W[3] = W[3]+0.5*(salidaEsperada[i]-y)*X4[i] | |
W[4] = W[4]+0.5*(salidaEsperada[i]-y)*X5[i] | |
iterar = True | |
break | |
datosObtenidos[i]=y | |
print('\nSalida Esperada:\n' + str(salidaEsperada)) | |
print('\nSalida Obtenida:\n' + str(datosObtenidos)) | |
print('\nEpocas: ' + str(epocas)) | |
print('Iterar: ' + str(iterar)) | |
print('W: ' + str(W)) | |
print('bias: ' + str(bias) +'\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment