コード例 #1
0
            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]

                training_error += [tr_err]
                test_error += [ts_err]
                hits_perc += [(1. * np.array(hits) / 30).tolist()]

                print time.time() - t0, 's'
コード例 #2
0
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)]
	n+=1
	
	#print lyapunov
コード例 #3
0
    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):
        print 'T =', T
        t0 = time.time()

        [[w01, w12, w23], [a01, a12, a23], [th1, th2,
                                            th3]] = bp.set_rand_omega(N)

        if (T + 1) % DT == 0:
            fonts += [font_extra]