예제 #1
0
def main():
    from matplotlib import pyplot as plt

    # random matrix
    W, WI = generate_random_matrix(), input_matrix()
    le, mc = ljapunov_exponent(W, WI), memory_capacity(W,
                                                       WI,
                                                       memory_max=MEM_MAX,
                                                       runs=1)[0]
    smc = sum(mc)
    print('RANDOM: le={0}, mc={1}'.format(le, smc))
    plt.subplot(2, 2, 1)
    plt.ylim([0, 1])
    plt.title("normal W, uniform WI, mc=%.2f" % smc)
    plt.plot(mc)

    W = generate_permutation_matrix()
    le, mc = ljapunov_exponent(W, WI), memory_capacity(W,
                                                       WI,
                                                       memory_max=MEM_MAX,
                                                       runs=1)[0]
    smc = sum(mc)
    print('PERMUT: le={0}, mc={1}'.format(le, smc))
    plt.subplot(2, 2, 2)
    plt.ylim([0, 1])
    plt.title("perm W, uniform WI, mc=%.2f" % smc)
    plt.plot(mc)

    W = generate_special_perm_matrix()
    WI = input_matrix()
    le, mc = ljapunov_exponent(W, WI), memory_capacity(W,
                                                       WI,
                                                       memory_max=MEM_MAX,
                                                       runs=1)[0]
    smc = sum(mc)
    print('PERMUT: le={0}, mc={1}'.format(le, smc))
    plt.subplot(2, 2, 3)
    plt.ylim([0, 1])
    plt.title("special perm W, uniform WI, mc=%.2f" % smc)
    plt.plot(mc)

    W = generate_special_perm_matrix()
    WI = generate_special_input()
    le, mc = ljapunov_exponent(W, WI), memory_capacity(W,
                                                       WI,
                                                       memory_max=MEM_MAX,
                                                       runs=1)[0]
    smc = sum(mc)
    print('PERMUT: le={0}, mc={1}'.format(le, smc))
    plt.subplot(2, 2, 4)
    plt.ylim([0, 1])
    plt.title("special perm W, delta WI, mc=%.2f" % smc)
    plt.plot(mc)

    plt.show()

    print('maco')
def main():
	from matplotlib import pyplot as plt

	# random matrix
	W, WI = generate_random_matrix(), input_matrix()
	le, mc = ljapunov_exponent(W, WI), memory_capacity(W, WI, memory_max=MEM_MAX, runs=1)[0]
	smc = sum(mc)
	print('RANDOM: le={0}, mc={1}'.format(le, smc))
	plt.subplot(2, 2, 1)
	plt.ylim([0,1])
	plt.title("normal W, uniform WI, mc=%.2f" % smc)
	plt.plot(mc)
	
	W = generate_permutation_matrix()
	le, mc = ljapunov_exponent(W, WI), memory_capacity(W, WI, memory_max=MEM_MAX, runs=1)[0]
	smc = sum(mc)
	print('PERMUT: le={0}, mc={1}'.format(le, smc))
	plt.subplot(2, 2, 2)
	plt.ylim([0,1])
	plt.title("perm W, uniform WI, mc=%.2f" % smc)
	plt.plot(mc)

	W = generate_special_perm_matrix()
	WI = input_matrix()
	le, mc = ljapunov_exponent(W, WI), memory_capacity(W, WI, memory_max=MEM_MAX, runs=1)[0]
	smc = sum(mc)
	print('PERMUT: le={0}, mc={1}'.format(le, smc))
	plt.subplot(2, 2, 3)
	plt.ylim([0,1])
	plt.title("special perm W, uniform WI, mc=%.2f" % smc)
	plt.plot(mc)

	W = generate_special_perm_matrix()
	WI = generate_special_input()
	le, mc = ljapunov_exponent(W, WI), memory_capacity(W, WI, memory_max=MEM_MAX, runs=1)[0]
	smc = sum(mc)
	print('PERMUT: le={0}, mc={1}'.format(le, smc))
	plt.subplot(2, 2, 4)
	plt.ylim([0,1])
	plt.title("special perm W, delta WI, mc=%.2f" % smc)
	plt.plot(mc)

	plt.show()




	print('maco')
def measure_mc(W, WI):
    return sum(
        memory_capacity(W,
                        WI,
                        memory_max=100,
                        iterations=7000,
                        iterations_skipped=200)[0])
def main():
	A = random.normal(0, 0.1 , [n, n])
	A = normalize_columns(A)
	# A = array([[3/5, 0], [4/5, 1]])
	# 
	# print(A)
	# print("energy = %f" % energy(A))
	# print(step(A))
	# return

	print(energy(A))

	for it in range(20):
		A = step(A)
		print(energy(A))
	print(A)

	WI = random.uniform(-.1, .1, [n, 1])
	#W = random.normal(0, 0.1, [100,100])
	mc, err = memory_capacity(A, WI, memory_max=200)
	print(sum(mc))
	from matplotlib import pyplot as plt
	plt.errorbar(range(len(mc)), mc, yerr=(err*3))
	plt.ylim([0, 1])
	plt.show()
def main():
	

	ITERATIONS = 100
	mc = zeros(ITERATIONS)
	og = zeros(ITERATIONS)

	#farby = 
	QS = 10

	colors = [
		[0, 0, 0],
		[0, 0, 1],
		[0, 1, 0],
		[1, 0, 0],
		[0, 1, 1],
		[1, 0, 1],
		[0, 1, 1],
	]

	for qpre in range(QS):
		q =  qpre + 2
		for it in range(ITERATIONS):
			W = random.normal(0, 0.1, [q, q])
			WI = random.uniform(-.1, .1, [q, 1])
			mc[it] = sum(memory_capacity(W, WI, memory_max=200, runs=1, iterations_coef_measure=5000)[0][:q+2])
			og[it] = matrix_orthogonality(W)
			print(qpre, QS, it, ITERATIONS)
		plt.scatter(og, mc, marker='+', label=q, c=(colors[qpre % len(colors)]))

	plt.xlabel("orthogonality")
	plt.ylabel("memory capacity")
	plt.grid(True)
	plt.legend()
	plt.show()
def main():
    A = random.normal(0, 0.1, [n, n])
    A = normalize_columns(A)
    # A = array([[3/5, 0], [4/5, 1]])
    #
    # print(A)
    # print("energy = %f" % energy(A))
    # print(step(A))
    # return

    print(energy(A))

    for it in range(20):
        A = step(A)
        print(energy(A))
    print(A)

    WI = random.uniform(-.1, .1, [n, 1])
    #W = random.normal(0, 0.1, [100,100])
    mc, err = memory_capacity(A, WI, memory_max=200)
    print(sum(mc))
    from matplotlib import pyplot as plt
    plt.errorbar(range(len(mc)), mc, yerr=(err * 3))
    plt.ylim([0, 1])
    plt.show()
def main2():
	ITERATIONS = 10
	q= 100
	for it in range(ITERATIONS):
		W = random.uniform(-0.1, 0.1, [q, q])
		WI = random.uniform(-.1, .1, [q, 1])
		mc = sum(memory_capacity(W, WI, memory_max=200, runs=1)[0])
		og = matrix_orthogonality(W)
		print(og)
def rv(xval, linepar):
	W = np.random.normal(0, xval, [q, q])
	WI = np.random.uniform(-tau, tau, [q, 1])

	for i, j in itertools.product(range(q), range(q)):
		if random.random() < linepar:
			W[i, j] = 0

	#current_radius = np.max(np.abs(np.linalg.eig(W)[0]))
	#W = W * (xval / current_radius)

	return sum(memory_capacity(W, WI, iterations=1200, iterations_skipped=q, iterations_coef_measure=100)[0])
def rv(xval, linepar):
    W = np.random.normal(0, xval, [q, q])
    WI = np.random.uniform(-tau, tau, [q, 1])

    for i, j in itertools.product(range(q), range(q)):
        if random.random() < linepar:
            W[i, j] = 0

    #current_radius = np.max(np.abs(np.linalg.eig(W)[0]))
    #W = W * (xval / current_radius)

    return sum(
        memory_capacity(W,
                        WI,
                        iterations=1200,
                        iterations_skipped=q,
                        iterations_coef_measure=100)[0])
예제 #10
0
def getmc(W, WI):
	return np.sum(memory_capacity(W, WI, memory_max=q, runs=1, iterations=1200, iterations_skipped=(q+1))[0])
def test_le_mc(W, WI):
	return ljapunov_exponent(W, WI), memory_capacity(W, WI, memory_max=MEM_MAX, runs=1)[0]
예제 #12
0
Y = zeros(len(sigmas))
Yerr = zeros(len(sigmas))

for ti, tau in enumerate(taus):
    print(tau, "of", str(taus))
    for i, sigma in enumerate(sigmas):
        mcs = zeros(INSTANCES)
        for inm in range(INSTANCES):
            W = random.normal(0, sigma, [q, q])
            WI = random.uniform(-tau, tau, [q, 1])
            mcs[inm] = sum(
                memory_capacity(W,
                                WI,
                                memory_max=q,
                                runs=1,
                                iterations=15000,
                                iterations_skipped=10000,
                                iterations_coef_measure=1000)[0])
        Y[i] = average(mcs)
        Yerr[i] = std(mcs)  # / sqrt(INSTANCES)
        print(i, "of", len(sigmas))

    np.savetxt('saved/avg-t' + str(ti + posun) + '.txt', Y)
    np.savetxt('saved/std-t' + str(ti + posun) + '.txt', Yerr)

    plt.errorbar(sigmas, Y, yerr=Yerr, label=("$\\tau={0}$".format(tau)))

plt.grid(True)
plt.xlabel("sigma: $W = N(0, \\sigma)$")
plt.ylabel("MC, errbar: $1 \\times \\sigma$")
예제 #13
0
        mcs = np.zeros(ITERATIONS)
        for it in range(ITERATIONS):
            W = np.random.normal(0, 1, [q, q])
            WI = np.random.uniform(-tau, tau, [q, 1])

            for i, j in itertools.product(range(q), range(q)):
                if random.random() < sparsity:
                    W[i, j] = 0

            current_radius = np.max(np.abs(np.linalg.eig(W)[0]))
            W = W * (radius / current_radius)

            mcs[it] = sum(
                memory_capacity(W,
                                WI,
                                iterations=1200,
                                iterations_skipped=q,
                                iterations_coef_measure=100)[0])
        Y[li][si] = np.average(mcs)
        Yerr[li][si] = np.std(mcs)


def replot():
    for li in range(len(sparsities)):
        plt.errorbar(radiuses,
                     Y[li],
                     yerr=Yerr[li],
                     label="sparsity = {:1.2f}".format(sparsities[li]))

    plt.grid(True)
    plt.legend(loc=3)
	Y[line] = zeros(len(svals))
	Yerr[line] = zeros(len(svals))
	#Yerr[line] = zeros(len(sigmas))

for qi, q in enumerate(res_sizes):
	print(q, "of", str(res_sizes))
	for i, sval in enumerate(svals):
		mcs = zeros(INSTANCES)
		for inm in range(INSTANCES):
			W = random.normal(0, 1, [q, q])
			# find the largest singular value and rescale the matrix 
			current_sv = linalg.svd(W, compute_uv=0)[0]
			W = W * (sval / current_sv)

			WI = random.uniform(-tau, tau, [q, 1])
			mcs[inm] = sum(memory_capacity(W, WI, memory_max=q, runs=1, iterations=1200, iterations_skipped=itskip, iterations_coef_measure=100)[0])
		Y[qi][i] = average(mcs)
		Yerr[qi][i] = std(mcs)
		print(i,"of", len(svals))

	maxinlineX[qi] = svals[argmax(Y[qi])]
	maxinlineY[qi] = max(Y[qi])

	np.savetxt('saved/mcs-t'+str(qi + posun)+'.txt', Y[qi])
	np.savetxt('saved/stds-t'+str(qi + posun)+'.txt', Yerr[qi])

	plt.errorbar(svals, Y[qi], label=("res. size={0}".format(q)), yerr=Yerr[qi])
	#plt.scatter(X[qi], Y[qi], label=("res. size={0}".format(q)), c=(colors[qi % len(colors)]))

plt.plot(maxinlineX, maxinlineY, c=(0,0,0), label="maxima")
plt.grid(True)
예제 #15
0
def test_le_mc(W, WI):
    return ljapunov_exponent(W, WI), memory_capacity(W,
                                                     WI,
                                                     memory_max=MEM_MAX,
                                                     runs=1)[0]
sigmas = np.linspace(0.08, 0.11, 7)
tau = 0.01
ITERATIONS = 1000

bins = 20

hists = [None] * len(sigmas)

for i, sigma in enumerate(sigmas):
	
	print(sigma,'of', str(sigmas))
	mcs = np.zeros(ITERATIONS)
	for it in range(ITERATIONS):
		W = np.random.normal(0, sigma, [reservoir_size, reservoir_size])
		WI = np.random.uniform(-tau, tau, [reservoir_size, 1])
		mc = sum(memory_capacity(W, WI, memory_max=reservoir_size, runs=1)[0])
		mcs[it] = mc
		print("\r{} of {}".format(it, ITERATIONS), end="")
	print()
	hists[i] = mcs
	

def replot():
	together= True
	if together:
		max_yticks = 2
		fig = plt.figure()
		fig.subplots_adjust(hspace=0.4)
		
	bins = np.linspace(0, 60, 60)
	for i, sigma in enumerate(sigmas):
taus = linspace(0.0001, 0.01, 20)
INSTANCES = 5 * 6

X, Y = meshgrid(sigmas, taus)
Z = zeros(X.shape)
i = 0

for sigma_r, tau_r in zip(X, Y):

    j = 0
    for sigma, tau in zip(sigma_r, tau_r):
        mcs = zeros(INSTANCES)
        for inm in range(INSTANCES):
            W = random.normal(0, sigma, [q, q])
            WI = random.uniform(-tau, tau, [q, 1])
            mcs[inm] = sum(memory_capacity(W, WI, memory_max=q)[0])

        Z[i, j] = average(mcs)
        print(sigma, tau)
        j += 1

    i += 1
cmap = plt.get_cmap('PiYG')
c = plt.pcolormesh(X, Y, Z, cmap=cmap)
plt.colorbar()
plt.ylim([0, 0.010])
plt.xlim([0.08, 0.095])
plt.xlabel("sigma: $W = N(0, \\sigma)$")
plt.ylabel("tau: $W^I = U(-\\tau, \\tau)$")
plt.show()
예제 #18
0
sigmas = np.linspace(0.08, 0.11, 7)
tau = 0.01
ITERATIONS = 1000

bins = 20

hists = [None] * len(sigmas)

for i, sigma in enumerate(sigmas):

    print(sigma, 'of', str(sigmas))
    mcs = np.zeros(ITERATIONS)
    for it in range(ITERATIONS):
        W = np.random.normal(0, sigma, [reservoir_size, reservoir_size])
        WI = np.random.uniform(-tau, tau, [reservoir_size, 1])
        mc = sum(memory_capacity(W, WI, memory_max=reservoir_size, runs=1)[0])
        mcs[it] = mc
        print("\r{} of {}".format(it, ITERATIONS), end="")
    print()
    hists[i] = mcs


def replot():
    together = True
    if together:
        max_yticks = 2
        fig = plt.figure()
        fig.subplots_adjust(hspace=0.4)

    bins = np.linspace(0, 60, 60)
    for i, sigma in enumerate(sigmas):
	Yerr[li] = np.zeros(len(radiuses))
	for si, radius in enumerate(radiuses):
		print('point {} of {}'.format(si, len(radiuses)))
		mcs = np.zeros(ITERATIONS)
		for it in range(ITERATIONS):
			W = np.random.normal(0, 1, [q, q])
			WI = np.random.uniform(-tau, tau, [q, 1])

			for i, j in itertools.product(range(q), range(q)):
				if random.random() < sparsity:
					W[i, j] = 0

			current_radius = np.max(np.abs(np.linalg.eig(W)[0]))
			W = W * (radius / current_radius)

			mcs[it] = sum(memory_capacity(W, WI, iterations=1200, iterations_skipped=q, iterations_coef_measure=100)[0])
		Y[li][si] = np.average(mcs)
		Yerr[li][si] = np.std(mcs)

def replot():
	for li in range(len(sparsities)):
		plt.errorbar(radiuses, Y[li], yerr=Yerr[li], label="sparsity = {:1.2f}".format(sparsities[li]))

	plt.grid(True)
	plt.legend(loc=3)
	plt.xlabel("$|\lambda|_{max}$")
	plt.ylabel("MC")

	try_save_fig()
	plt.show()
def measure_mc(W, WI):
	return sum(memory_capacity(W, WI, memory_max=100, iterations=7000, iterations_skipped=200)[0])
X, Y = meshgrid(sigmas, taus)
Z = zeros(X.shape)
i = 0



for sigma_r, tau_r in zip(X,Y):

	j = 0
	for sigma, tau in zip(sigma_r, tau_r):
		mcs = zeros(INSTANCES)
		for inm in range(INSTANCES):
			W = random.normal(0, sigma, [q, q])
			WI = random.uniform(-tau, tau, [q, 1])
			mcs[inm] = sum(memory_capacity(W, WI, memory_max=q)[0])

		Z[i,j] = average(mcs)
		print(sigma, tau)
		j += 1

	i += 1
cmap = plt.get_cmap('PiYG')
c = plt.pcolormesh(X, Y, Z, cmap=cmap)
plt.colorbar()
plt.ylim([0,0.010])
plt.xlim([0.08, 0.095])
plt.xlabel("sigma: $W = N(0, \\sigma)$")
plt.ylabel("tau: $W^I = U(-\\tau, \\tau)$")
plt.show()