Created
July 9, 2018 18:33
-
-
Save brpereyra/7ca0b6a2ca6ca14c74d26af0d3dfda80 to your computer and use it in GitHub Desktop.
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
#importacion de metodo random | |
from random import uniform as rand | |
#declaracion de variables | |
aprendiendo=True | |
weights=[rand(-1,1),rand(-1,1)] | |
bias=rand(-1,1) | |
iteraciones=0 | |
#tabla de la verdad y datos de entrada y saldia | |
datos=[ | |
[1,1,1], | |
[1,0,0], | |
[0,1,0], | |
[0,0,0] | |
] | |
while aprendiendo: | |
iteraciones+=1 | |
aprendiendo=False | |
for x in range(0,4): | |
valorReal=datos[x][0]*weights[0]+datos[x][1]*weights[1]+bias | |
valorEntero=1 if valorReal>0 else 0 | |
if valorEntero!= datos[x][2]: | |
weights[0]=rand(-1,1) | |
weights[1]=rand(-1,1) | |
bias=rand(-1,1) | |
aprendiendo=True | |
print("w1:",weights[0]) | |
print("w2:",weights[1]) | |
print("bias:",bias) | |
for x in range(0,4): | |
valorReal=datos[x][0]*weights[0]+datos[x][1]*weights[1]+bias | |
valorEntero=1 if valorReal>0 else 0 | |
print("Entradas: " + str(datos[x][0])+" y "+str(datos[x][1])+" = "+str(datos[x][2]) + " perceptron: " + str(valorEntero)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment