Oi professor,
Tentei adaptar o perceptron ao operador XOR, porém, ele executa continuamente, não parando com erro zero.
Segue o código para avaliação.
import numpy as np
inputs = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
outputs = np.array([0, 1, 1, 0])
weights = np.array([0.0, 0.0])
learningRate = 0.1
def stepFunction(sumValue):
if (sumValue >= 1):
return 1
return 0
def calculateOutput(register):
s = register.dot(weights)
return stepFunction(s)
def training():
totalError = 1
while (totalError != 0):
totalError = 0
for i in range(len(outputs)):
outputCalculated = calculateOutput(np.array(inputs[i]))
error = abs(outputs[i] – outputCalculated)
totalError += error
for j in range(len(weights)):
weights[j] = weights[j] + (learningRate * inputs[i, j] * error)
print (“Atualized weight: ” + str(weights[j]))
print (“Total errors: ” + str(totalError))
training()