import numpy as np
def sigmoid(x):
return 1 / (1 + np.exp(-x))
training_input = np.array([[0, 0, 0],
[1, 1, 1],
[1, 0, 1],
[0, 1, 1]])
training_output = np.array([[0, 1, 1, 0]]).T
np.random.seed(1)
synaptic_weights = 2 * np.random.random((3, 1)) - 1
print("Веса до обучения: ")
print(synaptic_weights)
for i in range(20000):
input_layer = training_input
outputs = sigmoid(np.dot(input_layer, synaptic_weights))
err = training_output - outputs
adjustments = np.dot(input_layer.T, err * (outputs * (1 - outputs)))
synaptic_weights += adjustments
new = np.array([1, 1, 0])
output = sigmoid(np.dot(new, synaptic_weights))
print("Ответ: " + output)