Skip to content

Instantly share code, notes, and snippets.

@brpereyra
Created July 9, 2018 18:33
Show Gist options
  • Save brpereyra/7ca0b6a2ca6ca14c74d26af0d3dfda80 to your computer and use it in GitHub Desktop.
Save brpereyra/7ca0b6a2ca6ca14c74d26af0d3dfda80 to your computer and use it in GitHub Desktop.
#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