def plot_rasters(K, I_app, Phi): T = np.arange(tTransition, tFinal, 0.05) nk = len(K) for cn in networks: for p in Phi: for ip in I_app: for k in range(nk): fig, ax = pl.subplots(1, figsize=(10, 5)) ifname = str('%s-%.6f-%.6f-%.6f' % (cn, K[k], p, ip)) spikes = lib.read_from_file('text/spk-' + ifname + '.txt', N) for ii in range(N): ax.plot(spikes[ii], [ii] * len(spikes[ii]), '.', c='royalblue', markersize=2) ax.set_ylabel("Node index") ax.set_xlabel('Time(ms)') ax.set_xlim(tTransition, tFinal) ax.set_xlim(2500, 2900) ax.set_title(cn + str(', K = %g, phi = %g, I = %g' % (K[k], p, ip))) fig.savefig('fig/r-' + ifname + '.png') pl.close()
def plot_raster(e_file, i_file, ax): t_e_spikes = read_from_file(e_file) t_i_spikes = read_from_file(i_file) for i in range(num_i): if len(t_i_spikes[i]) > 0: ax.plot(t_i_spikes[i], [i] * len(t_i_spikes[i]), "b.") for i in range(num_i, num_i + num_e): if len(t_e_spikes) > 0: ax.plot(t_e_spikes[i - num_i], [i] * len(t_e_spikes[i - num_i]), "r.") ax.set_xlabel("time [ms]") ax.set_ylabel("neuron #") for i in range(num_i): frequency_of_i_cell = len(t_i_spikes[i]) * 1000 / t_final print("frequency of i cell {}: {}".format(i, frequency_of_i_cell)) for i in range(num_e): frequency_of_e_cell = len(t_e_spikes[i]) * 1000 / t_final print("frequency of e cell {}: {}".format(i, frequency_of_e_cell))
def plot_correlations(g, omega, ns=num_sim): n = len(omega) communities_l1 = lib.read_from_file( str('../src/networks/communities_%d_l1.txt' % N)) for g in G: for i in range(n): cor = np.zeros((N, N)) for ens in range(ns): subname = str("%.6f-%.6f" % (g, omega[i])) c = np.fromfile("text/c-"+subname+"-"+str(ens)+".bin", dtype=float, count=-1) c = np.reshape(c, (N, N)) cor += c cor /= float(ns) cor_ordered = lib.reorder_nodes(cor, communities_l1) np.savez("npz/cor-ave-"+subname, cor=cor_ordered) lib.imshow_plot(cor_ordered, fname="fig/c-"+subname+'.png', vmax=1, vmin=-1)
def plot_nmi(adj, G, Omega, threshold=0.95, to_npz=False): n = len(Omega) N = adj.shape[0] communities_l1 = lib.read_from_file( str('../src/networks/communities_%d_l1.txt' % N)) communities_l2 = lib.nodes_of_each_cluster([32, 33]) adj = lib.reorder_nodes(adj, communities_l1) adj_communities1 = lib.comm_weighted(adj) adj_membership1 = adj_communities1.membership adj_membership2 = [0]*32+[1]*33 fig, ax = pl.subplots(1, figsize=(6, 5)) for g in G: nmi1 = np.zeros((num_sim, n)) nmi2 = np.zeros((num_sim, n)) for i in range(n): for ens in range(num_sim): subname = str("%.6f-%.6f" % (g, Omega[i])) c = np.fromfile("text/c-"+subname+"-"+str(ens)+".bin", dtype=float, count=-1) c = np.reshape(c, (N, N)) c = lib.binarize(c, threshold) cor_communities1 = lib.walktrap( # comm_unweighted lib.reorder_nodes(c, communities_l1), steps=8) cor_communities2 = lib.walktrap( lib.reorder_nodes(c, communities_l2), steps=60) # nmi[ens, i] = lib.calculate_NMI(adj_communities, # cor_communities) nmi1[ens, i] = lib.calculate_NMI( adj_membership1, cor_communities1.membership) nmi2[ens, i] = lib.calculate_NMI( adj_membership2, cor_communities2.membership) if num_sim > 1: nmi_mean1 = np.mean(nmi1, axis=0) nmi_std1 = np.std(nmi1, axis=0) nmi_mean2 = np.mean(nmi2, axis=0) nmi_std2 = np.std(nmi2, axis=0) else: nmi_mean1 = nmi1[0, :] nmi_std1 = 0 nmi_mean2 = nmi2[0, :] nmi_std2 = 0 if to_npz: np.savez("npz/nmi-"+str('%.6f' % g), nmi=[nmi_mean1, nmi_mean2], std=[nmi_std1, nmi_std2], omega=Omega, g=g) if num_sim > 1: ax.errorbar(Omega, nmi_mean1, yerr=nmi_std1, lw=2, marker='o', label=str("%.2f" % g)) ax.errorbar(Omega, nmi_mean2, yerr=nmi_std2, lw=2, marker='o', label=str("%.2f" % g)) else: ax.plot(Omega, nmi_mean1, lw=2, label=str("%.2f" % g)) ax.plot(Omega, nmi_mean2, lw=2, label=str("%.2f" % g)) ax.legend() ax.set_xlabel(r"$\omega$", fontsize=14) ax.set_ylabel(r"NMI") pl.tight_layout() pl.savefig("fig/nmiq.png", dpi=300) pl.close()
right=right - 0.028, wspace=0.4, hspace=0.02, top=0.37, bottom=0.2) ax6 = pl.subplot(gs3[0]) ax7 = pl.subplot(gs3[1]) ax8 = pl.subplot(gs3[2]) gs4 = GridSpec(1, 3) gs4.update(left=left, right=right - 0.028, wspace=0.4, top=0.175, bottom=0.05) ax9 = pl.subplot(gs4[0]) ax10 = pl.subplot(gs4[1]) ax11 = pl.subplot(gs4[2]) communities = lib.read_from_file('communities.txt', 5) con = np.loadtxt("r_C65.dat") length = np.loadtxt("r_L65.dat") c = np.load("R.npz") Rg = c['Rg'][0] Rl1 = c['Rl1'][0] Rl2 = c['Rl2'][0] g = c['g'] mu = c['mu'] cor1 = np.load("cor-0.06.npz")['cor'] cor2 = np.load("cor-0.29.npz")['cor'] cor3 = np.load("cor-0.63.npz")['cor'] c1 = np.load('nmi-30.npz')
import numpy as np import pylab as pl from lib import read_from_file from main import num_e, num_i t_e_spikes = read_from_file("t_e_spikes.txt") t_i_spikes = read_from_file("t_i_spikes.txt") lfp = np.loadtxt("lfp.txt", dtype=float) fig, ax = pl.subplots(2, figsize=(10, 8), sharex=True) for i in range(num_i): ax[0].plot(t_i_spikes[i], [i] * len(t_i_spikes[i]), "b.") for i in range(num_i, num_i + num_e): ax[0].plot(t_e_spikes[i - num_i], [i] * len(t_e_spikes[i - num_i]), "r.") t = lfp[:, 0] lfp = lfp[:, 1] ax[1].plot(t, lfp, lw=2, color="k") ax[1].set_xlabel("time [ms]", fontsize=18) ax[0].set_ylabel("neuron #", fontsize=18) ax[1].set_ylabel("mean(v), E-cells", fontsize=18) for i in range(2): ax[i].tick_params(labelsize=14) ax[1].set_ylim(-100, 50) ax[1].set_xlim(0, np.max(t)) pl.tight_layout()