import back_prop as bp import numpy as np import h5py as h5 dim=28 N = [28*28,16,16,10] max_iterations = 700*10*10 lyapunov = [] n=0 while True: W = np.array(bp.set_rand_omega(N)) W_ = W + np.array([ 2e-10*(np.array([np.random.random((N[1],N[0])),np.random.random((N[2],N[1])),np.random.random((N[3],N[2]))])-0.5), 0*W[1], 2e-10*(np.array([np.random.random(N[1]),np.random.random(N[2]),np.random.random(N[3])])-0.5) ]) Wt = bp.back_prop(N, W, range(700),max_iterations=max_iterations)[0] W_t = bp.back_prop(N, W_, range(700),max_iterations=max_iterations)[0] num = 0 den = 0 for i in range(3): for j in range(3): num += ((Wt[i][j]-W_t[i][j])**2).sum() den += ((W[i][j]-W_[i][j])**2).sum() num = np.sqrt(num) den = np.sqrt(den) lyapunov += [(700.*10/max_iterations)*np.log(num/den)]
print '\n###', i, '###' for gamma in [0.2, 0.4, 0.6, 0.8, 1]: bp.GAMMA = gamma print '\n# GAMMA =', gamma, '#' training_error = [] test_error = [] hits_perc = [] for T in np.arange(DT, Tmax + 1, DT): print 'T =', T t0 = time.time() [[w01, w12, w23], [a01, a12, a23], [th1, th2, th3]] = bp.set_rand_omega(N) fonts = np.random.choice(range(700), T, replace=False) tr_err, ts_err, hits = bp.back_prop( N, [[w01, w12, w23], [a01, a12, a23], [th1, th2, th3]], fonts, max_iterations=max_iterations, n_fonts_error=n_fonts_error, calculate_error=True, calculate_train_error=True)[1][:3] #[[w01,w12,w23],[a01,a12,a23],[th1,th2,th3]] = bp.back_prop( #N,[[w01,w12,w23],[a01,a12,a23],[th1,th2,th3]],fonts,max_iterations=max_iterations,n_fonts_error=n_fonts_error)[0] #tr_err = bp.evaluate(N,[[w01,w12,w23],[a01,a12,a23],[th1,th2,th3]],fonts,printerror=False)[0] #ts_err, hits = bp.evaluate(N,[[w01,w12,w23],[a01,a12,a23],[th1,th2,th3]],np.arange(700,1000,1),printerror=False)[:2]
for A in [0.3, 0.5, 0.7]: for B in [0.3, 0.7]: bp.A = A bp.B = B print '\n# A =', A, '#\n# B =', B, '#' training_error = [] test_error = [] hits_perc = [] for T in np.arange(DT, Tmax + 1, DT): print 'T =', T t0 = time.time() [[w01, w12, w23], [a01, a12, a23], [th1, th2, th3]] = bp.set_rand_omega(N) fonts = np.random.choice(range(700), T, replace=False) tr_err, ts_err, hits = bp.back_prop( N, [[w01, w12, w23], [a01, a12, a23], [th1, th2, th3]], fonts, max_iterations=max_iterations, n_fonts_error=n_fonts_error, calculate_error=True, calculate_train_error=True)[1][:3] #[[w01,w12,w23],[a01,a12,a23],[th1,th2,th3]] = bp.back_prop( #N,[[w01,w12,w23],[a01,a12,a23],[th1,th2,th3]],fonts,max_iterations=max_iterations,n_fonts_error=n_fonts_error)[0] #tr_err = bp.evaluate(N,[[w01,w12,w23],[a01,a12,a23],[th1,th2,th3]],fonts,printerror=False)[0] #ts_err, hits = bp.evaluate(N,[[w01,w12,w23],[a01,a12,a23],[th1,th2,th3]],np.arange(700,1000,1),printerror=False)[:2]
dim = 28 N = np.array([dim * dim, 16, 16, 10]) for i in range(n_omegas): print '\n###', i, '###' training_error = [] test_error = [] hits_perc = [] error_prediction = [] err_pred = [] print 'T =', 0 t0 = time.time() [[w01, w12, w23], [a01, a12, a23], [th1, th2, th3]] = bp.set_rand_omega(N) fonts = [] font_extra = np.random.choice([k for k in range(700) if not k in fonts], 1)[0] err_pred += [ bp.back_prop(N, [[w01, w12, w23], [a01, a12, a23], [th1, th2, th3]], fonts, f_extra=font_extra, max_iterations=max_iterations, n_fonts_error=n_fonts_error)[1][4] ] print time.time() - t0, 's' for T in np.arange(1, Tmax + 1, 1):