#28jan19 Exploring the initial conditions import numpy as np ## Python library for array operations ## Round printouts to 3 decimal places np.set_printoptions(formatter={'float': lambda x: "{0:0.3f}".format(x)}) X0 = np.array([[0,0,1],[0,1,1],[1,0,1],[1,1,1]]) ## X0(4,3)=4rows of 3vcrs y0 = np.array([[0,1,1,0]]).T ## XOR, y0(4,1) column vector np.random.seed(1) ##for repeatable experiments W1= 2*np.random.random((3,4))-1 ## W1(3,4) signed fractions w2= 2*np.random.random((4,1))-1 ## w2(4,1) signed fractions #eps = 0.000000000001 #.0001 ok too #W1= 1 - eps*np.random.random((3,4)) ##W1(3,4) nhd of 1 #w2= 1 - eps*np.random.random((4,1)) ##w2(4,1) nhd of 1 #W1 = np.zeros((3,4)) ## solid 0s #w2 = np.zeros((4,1)) #W1 = np.ones((3,4)) ## solid 1s #w2 = np.ones((4,1)) W1[2][3]= 1. ## contaminators w2[1]=-1. for jj in xrange(600): ## by 600 obvious trend, Trask uses 60,000 Y1 = 1/(1+np.exp(-(np.dot(X0,W1)))) #sigma( X0(4,3)W1(3,4) )=Y1(4,4) y2 = 1/(1+np.exp(-(np.dot(Y1,w2)))) #sigma( Y1(4,4)w2(4,1) )=y2(4,1) ### raw_input() ##### wait-for-keypress kludge print "ITERATION", jj print "Weight1" print W1 print "weight2" print w2 print "output" print y2 dy2= (y0-y2)*y2*(1-y2) ## dy2(4,1) arithmetic is termwise w2 += Y1.T.dot(dy2) ##backprop Y1(4,4).T dy2(4,1)= dw2(4,1) dY1= dy2.dot(w2.T)*Y1*(1-Y1) ## w2.T(1,4) W1 += X0.T.dot(dY1) #backprop X0.T(1,4) dY1(1,4) #endfor #print "final W1=" #print W1 #print "final w2=" #print w2 #print "outcome Y1=" #print Y1 #print "outcome y2=" #print y2