Exemple #1
0
 def __init__(self, architecture):
     self.architecture = architecture
     self.ae = {}
     for i in range(len(architecture) - 1):
         self.ae.setdefault(i)
         self.ae[i] = NNC([
             self.architecture[i], self.architecture[i + 1],
             self.architecture[i]
         ])
     pass
Exemple #2
0
print q.ae[0].W[0].shape
print q.ae[0].W[0][1:,:].shape
x_length = 10; y_length = 10
fig = plt.figure()
for i in range(x_length * y_length):
	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 train_images[1,:,:].reshape(1,-1)
num_train_case = train_images.shape[0]
num_test_case = test_images.shape[0]
print train_images.shape, trian_labels.shape
print test_images.shape

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'))
Exemple #4
0
num_train_case=train_images.shape[0]
num_test_case=test_images.shape[0]
print train_images.shape,trian_labels.shape
print test_images.shape

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'))