Created
April 17, 2022 22:07
-
-
Save lucatsf/87ae2cdd68d5955293b8e98c7ae9d075 to your computer and use it in GitHub Desktop.
example of an attempt to simulate a neuron
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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