<jupyter_start><jupyter_text>Run experiment<jupyter_code>LIFSORN, CF_eTOe = run_free(seedi=0)
#LIFSORN.store(name="free", filename="./data/free")  # save data 
G_e, G_i, S_eTOe = LIFSORN.sorted_objects[:3]
MS_e, MS_i = LIFSORN.sorted_objects[10:12]
MW_eTOe = LIFSORN.sorted_objects[-2]<jupyter_output><empty_output><jupyter_text>Prepare data<jupyter_code># Helper funtion to get pairwise correlation coefficients
def get_ccs(MS, N):

    # Bin spikes
    bin_size = 20*ms
    bins = int(100*second/bin_size)
    spikes_count = np.zeros((N_e, bins))
    for i in range(N):
        spikes = MS.t[MS.i==i]-400*second
        for t_i in spikes:
            spikes_count[i, int(t_i/bin_size)] += 1

    # Pairwise CCs
    cc_list=[]
    for i in tqdm(range(N_e-1)):
        for j in range(i+1, N_e):
            cc_list.append(stats.pearsonr(spikes_count[i], spikes_count[j])[0])
    
    return cc_list

# Helper funtion to get interspike intervals
def get_isi(MS):
    isis = []
    cvs = []
    spiketrains = MS.spike_trains()
    for times in spiketrains.values():
        isis.append(np.diff(times/second))
        cvs.append(np.std(isis[-1]) / np.mean(isis[-1])) 
    return np.concatenate(isis), cvs
cc_list = get_ccs(MS_e, N_e)
isis, cvs = get_isi(MS_e)<jupyter_output><empty_output><jupyter_text>Figure 1<jupyter_code>fig, axs = plt.subplots(2, 2, figsize=(14, 8))

# Panel A
ax = axs[0, 0]
ax.scatter(G_e.x/umeter, G_e.y/umeter, s=6, label="Exc.")
ax.scatter(G_i.x/umeter, G_i.y/umeter, s=6, label="Inh.")
x_0 = G_e.x[0]/umeter
y_0 = G_e.y[0]/umeter
for neur_pre in (np.where(S_eTOe.c[:, 0]==1)[0]+1):
    x_pre = G_e.x[neur_pre]/umeter
    y_pre = G_e.y[neur_pre]/umeter
    ax.plot([x_pre, x_0], [y_pre, y_0], c="C0")
ax.set_xlim(0, length_T/umeter)
ax.set_ylim(0, height_T/umeter)
ax.set_xlabel("x [$\mu m$]")
ax.set_ylabel("y [$\mu m$]")
ax.legend()
ax.set_aspect("equal")

# Panel B
ax = axs[0, 1]
xs = np.linspace(-300, 300, 601) * umeter
xs = np.tile(xs, (2, 1)).T
xs[:, 1] = 0*meter
ax.plot(xs[:,0]/umeter, spot_rate(xs, 0*umeter), c="k")
ax.set_xlim(-300, 300)
ax.set_ylim(0, 55)
ax.set_xlabel("$\Delta x [\mu m]$")
ax.set_ylabel("$r_{spot} [Hz]$")

# Panel C
ax = axs[1, 0]
ax.scatter(G_e.x/umeter, G_e.y/umeter, s=6)
for clu in range(clu_num):
    clu_center = clu_start + (clu_end-clu_start) * clu/(clu_num-1)
    clu_center /= umeter
    circle = plt.Circle((clu_center[0], clu_center[1]), 
                        radius=clu_r/umeter, fill=False)
    ax.text(clu_center[0], clu_center[1], 
                r"$%s$" % string.ascii_uppercase[clu], fontsize=15, 
                bbox=dict(color="w", alpha=1, pad=0.1), va="center", ha="center")
    ax.add_patch(circle)
ax.plot(spot_start[0]/umeter, spot_start[1]/umeter, "kx", ms=20, mew=2)
ax.plot(spot_end[0]/umeter, spot_end[1]/umeter, "kx", ms=20, mew=2)
ax.plot(spot_mid[0]/umeter, spot_mid[1]/umeter, "kx", ms=20, mew=2)
ax.set_xlim(0, length_T/umeter)
ax.set_ylim(0, height_T/umeter)
ax.set_xlabel("x [$\mu m$]")
ax.set_ylabel("y [$\mu m$]")
ax.set_aspect("equal")

axs[1,1].axis("off")

fig.tight_layout()
plt.show()<jupyter_output><empty_output><jupyter_text>Figure 2  Panels A-D<jupyter_code># Helper function to plot spike trains
def plot_spikes(ax, MS, N, ylabel, c="C0"):
    ax.plot(MS.t, MS.i, '.', c=c)
    ax.set_ylim(0, N)
    ax.set_xlim(499, 500)
    ax.set_ylabel(ylabel)
    ax.set_xlabel("Simulation time [s]")

# Helper function to plot rate distribution
def plot_rates(ax, MS, N, c="C0", label="Exc."):
    rates = MS.count/(MS.t[-1]-MS.t[0])*second
    ax.hist(rates, color=c, bins=20)
    ax.legend([label])
    ax.set_ylabel("Count")
    ax.set_xlabel("Rate [Hz]")
fig, axs = plt.subplots(2, 2, figsize=(14, 8))

# Panels A-D
plot_spikes(axs[0, 0], MS_e, N_e, "Exc. neuron")
plot_spikes(axs[0, 1], MS_i, N_i, "Inh. neuron", "C1")
plot_rates(axs[1, 0], MS_e, N_e)
plot_rates(axs[1, 1], MS_i, N_i, "C1", label="Inh.")

fig.tight_layout()
plt.show()<jupyter_output><empty_output><jupyter_text>Panels E-G<jupyter_code>fig, axs = plt.subplots(1, 3, figsize=(14, 4))

# Panel E
ax = axs[0]
ax.hist(cc_list, bins=20)
ax.set_ylabel("Count")
ax.set_xlabel("$c_{mn}$")

# Panel F
ax = axs[1]
ax.hist(isis, bins=100)
ax.set_ylabel("Count")
ax.set_xlabel("$t_{ISI} [s]$")
ax.set_xlim(0, 2)

# Panel G
ax = axs[2]
ax.hist(cvs, bins=20)
ax.set_ylabel("Count")
ax.set_xlabel("$CV_{ISI}$")

fig.tight_layout()
plt.show()<jupyter_output><empty_output><jupyter_text>Figure 3<jupyter_code>fig, axs = plt.subplots(2, 2, figsize=(14, 8))

# Panel A
ax = axs[0,0]
ax.plot(CF_eTOe)
ax.set_xlim(0, 500)
ax.set_ylim(0, 0.12)
ax.set_xlabel("Simulation time [s]")
ax.set_ylabel("Connection fraction")

# Panel B
ax = axs[0,1]
rng = np.random.default_rng(53111)
ax.plot(MW_eTOe.t, MW_eTOe.w[rng.choice(np.arange(1_000), 10, replace=False)].T)
ax.set_xlim(400, 500)
ax.set_ylim(0, 3)
ax.set_xlabel("Simulation time [s]")
ax.set_ylabel("Weight")

# Panel C
ax = axs[1,0]
logbins = np.logspace(np.log10(0.001), np.log10(10), 40)
ax.hist(S_eTOe.w[:][S_eTOe.c[:]==1], bins=logbins)
ax.set_xscale("log")
ax.set_xlim(1e-2, 1e1)
ax.set_xlabel("Weight")
ax.set_ylabel("Count")

axs[1,1].axis("off")

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19568982105060612, 'fraction_numerical': 0.03963825283817587, 'mean_word_length': 4.553418803418803, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '617691', 'license': 'MIT', 'n_tokens_mistral': 2607, 'n_tokens_neox': 2460, 'n_words': 407, 'path': 'figs1-3.ipynb', 'repo_name': 'chklos/lifsorn-seqlearn', 'size': '5197'}