Operador lógico AND en Python
Redes neuronales (perceptrón)
threshold = 0
learning_rate = 0.1
weights = [1, 0, 0]
training_set = [((-1, 0, 0), 0), ((-1, 0, 1), 0), ((-1, 1, 0), 0), ((-1, 1, 1), 1)]
def sum_function(values):
return sum(value * weights[index] for index, value in enumerate(values))
while True:
print '-' * 60
error_count = 0
for input_vector, desired_output in training_set:
print weights
result = 1 if sum_function(input_vector) >= threshold else 0
error = desired_output - result
if error != 0:
error_count += 1
for index, value in enumerate(input_vector):
weights[index] += learning_rate * error * value
if error_count == 0:
break
No hay comentarios:
Publicar un comentario