Edgar Furtado edgardfurtado

Give Me The Damn Code: Artificial Intelligence

view sourceprint?

01.import numpy as np

02.X = np.array([ [0,0,1],[0,1,1],[1,0,1],[1,1,1] ])

03.y = np.array([[0,1,1,0]]).T

04.alpha,hidden_dim = (0.5,4)

05.synapse_0 = 2*np.random.random((3,hidden_dim)) - 1

06.synapse_1 = 2*np.random.random((hidden_dim,1)) - 1

07.for j in xrange(60000):

08.layer_1 = 1/(1+np.exp(-(np.dot(X,synapse_0))))

09.layer_2 = 1/(1+np.exp(-(np.dot(layer_1,synapse_1))))

10.layer_2_delta = (layer_2 - y)*(layer_2*(1-layer_2))

11.layer_1_delta = layer_2_delta.dot(synapse_1.T) * (layer_1 *(1-layer_1))

12.synapse_1 -= (alpha * layer_1.T.dot(layer_2_delta))

13.synapse_0 -= (alpha * X.T.dot(layer_1_delta))

 

Quote 1 0
Abhi Nandan AbhizNandan
Thanks for sharing!
Quote 0 0