#f.close() W = param_dict['W'].param pylab.ioff() net.set_input('input',Xtest) net.set_target('squared loss',Ytest) net.forward_prop(test=True) pylab.plot(Xtest,net.target_layers['squared loss'].outputs) pylab.plot(X,Y) pylab.show() return param_dict if __name__ == '__main__': #D = loadmat('mnist_small.mat') #D = loadmat('patches_16x16.mat') #X = D['patches'] D = ld.load_mnist(range(10)) X = D[0] Y = D[1] Xtest = D[2] Ytest = D[3] num_examples = X.shape[0] num_hid = 500 num_iters = 100 eta = 0.1 mo = 0.9 np.random.seed(1) ind = np.random.permutation(X.shape[0])[0:num_examples] X = X[ind] Y = Y[ind]
dW = mo * dW - eta * gW dbh = mo * dbh - eta * gbh dO = mo * dO - eta * gO dbo = mo * dbo - eta * gbo W = W + dW bh = bh + dbh O = O + dO bo = bo + dbo print 'Iteration %d Complete. Objective value: %s' % (i + 1, iteration_obj) return W, bh, O, bo if __name__ == '__main__': np.random.seed(1) X, y, Xtest, ytest = ld.load_mnist(range(10))[:4] kmin = 10 kmax = 10 W, bh, O, bo = train_carbm_nnet(X, y, mo=0.5, kmin=kmin, kmax=kmax) yhat = carbm_nnet_classify(W, bh, O, bo, Xtest, 10, 10) err = (yhat != ytest.argmax(1)).mean() print 'Classification error: %s' % err pylab.ioff() d.print_aligned(W) pylab.show(block=True)
print 'File deleted: %s' % ~os.path.isfile(save_file) return W, b, c print 'Iteration %d complete. Objective value: %s' % (i + 1, obj) times.append(time.time()) errs.append(obj) #Save out some results about timing/reconstruction error per epoch. if save_file is not None: np.savez(save_file, W=W, b=b, c=c, times=times, errs=errs) #Plot some diagnostics for this epoch. if plotting: pylab.ion() pylab.subplot(1, 2, 1) d.print_aligned(W[:, 0:np.minimum(100, W.shape[1])]) pylab.subplot(1, 2, 2) d.print_aligned((v_neg + m).T) pylab.draw() return W, b, c if __name__ == '__main__': np.random.seed(1) import load_datasets as ld X = ld.load_mnist(range(10))[0] W, b, c = carbm_cd(X, plotting=True, num_iters=10) pylab.ioff() d.print_aligned(W) pylab.show(block=True)
gO = G['gO'] gbo = G['gbo'] dW = mo*dW - eta*gW dbh = mo*dbh - eta*gbh dO = mo*dO - eta*gO dbo = mo*dbo - eta*gbo W = W + dW bh = bh + dbh O = O + dO bo = bo + dbo print 'Iteration %d Complete. Objective value: %s' % (i+1,iteration_obj) return W,bh,O,bo if __name__ == '__main__': np.random.seed(1) X,y,Xtest,ytest = ld.load_mnist(range(10))[:4] kmin = 10 kmax = 10 W,bh,O,bo = train_carbm_nnet(X,y,mo=0.5,kmin=kmin,kmax=kmax) yhat = carbm_nnet_classify(W,bh,O,bo,Xtest,10,10) err = (yhat != ytest.argmax(1)).mean() print 'Classification error: %s' % err pylab.ioff() d.print_aligned(W) pylab.show(block=True)