Skip to content

Instantly share code, notes, and snippets.

@lucatsf
Created April 17, 2022 22:07
Show Gist options
  • Save lucatsf/87ae2cdd68d5955293b8e98c7ae9d075 to your computer and use it in GitHub Desktop.
Save lucatsf/87ae2cdd68d5955293b8e98c7ae9d075 to your computer and use it in GitHub Desktop.
example of an attempt to simulate a neuron
import numpy as np
entrada = np.array([
[0,0,1],
[1,1,1],
[1,0,1],
[0,1,1]
])
treinamento_resultado = np.array([[0,1,1,0]]).T
np.random.seed(1)
pesos_sinapticos = 2 * np.random.random((3,1)) - 1
def sigmoid(x):
return 1 / (1 + np.exp(-x))
def derivada_sigmoid(x):
return x * (1 - x)
for i in range(10000):
input_layer = entrada
output_layer = sigmoid(np.dot(input_layer, pesos_sinapticos))
error = treinamento_resultado - output_layer
ajuste = error * derivada_sigmoid(output_layer)
pesos_sinapticos += np.dot(input_layer.T, ajuste)
print(output_layer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment