train_images = train_images.transpose() test_images = test_images.transpose() groundTruth = np.zeros((10, train_images.shape[1])) q = np.arange(0, train_images.shape[1]) groundTruth[trian_labels.transpose(), q] = 1 architect = [784, 500, 10] option = {} a = NNC(architect, option) #start=clock() #for i in range(4): # a.test() #finish=clock() #print (finish-start)/10000 a.learningRate = 1 a.weightPenaltyL2 = 0.0001 a.nonSparsityPenalty = 0.0001 a.dropoutFraction = 0.1 a.inputZeroMaskedFraction = 0.1 opts = {'batchsize': 100, 'numepochs': 10} a.output = 'softmax' a.train(train_images, groundTruth, opts) result = a.nnpred(test_images) writer = csv.writer(file('nnpredict.csv', 'wb')) writer.writerow(['ImageId', 'Label']) i = 1 for p in result: writer.writerow([i, p]) i = i + 1 #print np.array(c[0:6]).reshape(2,3)
im = q.ae[0].W[0][1:,:][:,i].reshape(28, 28) plotwindow = fig.add_subplot(y_length, x_length, i + 1) plt.imshow(im , cmap='gray') plt.show() architect = [784,200,10]; option ={} a=NNC(architect,option) groundTruth=a.handle_y_4classify(trian_labels); #start=clock() #for i in range(4): # a.test() #finish=clock() #print (finish-start)/10000 a.learningRate=0.4 a.weightPenaltyL2 = 0.0001 opts={'batchsize':100,'numepochs':4} a.output='softmax' a.activation ='tanh' a.W[0]=q.ae[0].W[0] a.train(train_images,groundTruth,opts) qq=a.nnpred(test_images) print qq print test_labels tests=np.zeros((1,num_test_case)).reshape(1,-1); tests[qq.reshape(1,-1)==test_labels.reshape(1,-1)]=1 print np.sum(tests)/num_test_case #print np.array(c[0:6]).reshape(2,3)
test_images=test_images.transpose() groundTruth=np.zeros((10,train_images.shape[1])) q=np.arange(0,train_images.shape[1]) groundTruth[trian_labels.transpose(),q]=1 architect = [784,500,10]; option ={} a=NNC(architect,option) #start=clock() #for i in range(4): # a.test() #finish=clock() #print (finish-start)/10000 a.learningRate=1 a.weightPenaltyL2 = 0.0001 a.nonSparsityPenalty = 0.0001 a.dropoutFraction=0.1 a.inputZeroMaskedFraction=0.1 opts={'batchsize':100,'numepochs':10} a.output='softmax' a.train(train_images,groundTruth,opts) result=a.nnpred(test_images) writer = csv.writer(file('nnpredict.csv', 'wb')) writer.writerow(['ImageId', 'Label']) i=1 for p in result: writer.writerow([i,p]) i=i+1 #print np.array(c[0:6]).reshape(2,3)