def run_gj(cls, num_neu, prob=1., gjw=0.1, k_spikelet=0., Iext=12., run_duration=300): lif = nn.LIF(num_neu) connection = nn.conn.fixed_prob(lif.num, lif.num, prob) if k_spikelet > 0.: gj = cls(lif, lif, gjw, connection, delay=1., k_spikelet=k_spikelet) else: gj = cls(lif, lif, gjw, connection, delay=1., ) neu_mon = nn.StateMonitor(lif) syn_mon = nn.StateMonitor(gj) net = nn.Network(gj=gj, syn_mon=syn_mon, lif=lif, neu_mon=neu_mon) net.run(run_duration, inputs=[lif, np.array([Iext, 0])]) fig, gs = nn.vis.get_figure(2, 1, 3, 10) nn.vis.plot_potential(net.run_time(), neu_mon, (0, 1), fig.add_subplot(gs[0, 0])) nn.vis.plot_value(net.run_time(), syn_mon, 'g', (0, 1), fig.add_subplot(gs[1, 0])) plt.show()
def run_ampa(cls, num_pre=5, num_post=10, prob=1., duration=650.): pre = nn.FreqInput(num_pre, 10., 100.) post = nn.generate_fake_neuron(num_post) conn = nn.conn.fixed_prob(pre.num, post.num, prob) ampa = cls(pre, post, conn, delay=2.) mon = nn.StateMonitor(ampa, ['g_post', 's']) net = nn.Network(ampa, pre, post, mon) net.run(duration, report=True) ts = net.run_time() fig, gs = nn.vis.get_figure(1, 1, 5, 10) fig.add_subplot(gs[0, 0]) plt.plot(ts, mon.g_post[:, 0], label='g_post') plt.plot(ts, mon.s[:, 0], label='s') plt.legend() plt.show()
def run_gaba(cls, num_pre=5, num_post=10, prob=1., monitor=[], duration=300, stimulus_gap=10): pre = nn.FreqInput(num_pre, 1e3 / stimulus_gap, 20.) post = nn.generate_fake_neuron(num_post) conn = nn.conn.fixed_prob(num_pre, num_post, prob) gaba = cls(pre, post, conn, delay=2.) mon = nn.StateMonitor(gaba, monitor) net = nn.Network(gaba, pre, post, mon) net.run(duration, report=True) fig, gs = nn.vis.get_figure(1, 1, 5, 10) fig.add_subplot(gs[0, 0]) for k in monitor: plt.plot(net.run_time(), getattr(mon, k)[:, 0], label=k) plt.legend() plt.show()
def output_synapse( syn_state, var_index, post_neu_state, ): output_idx = var_index[-2] syn_val = syn_state[output_idx[0]][output_idx[1]] post_neu_state[1] += syn_val[:num_post] post_neu_state[2] += syn_val[num_post:] return nn.Synapses(**locals()) neurons = CUBA(num_exc + num_inh) syn = Synapse( neurons, neurons, ) mon = nn.StateMonitor(neurons, ['spike', 'spike_time']) net = nn.Network(syn=syn, neu=neurons, mon=mon) t0 = time.time() net.run(10 * 1000., report=True) print('Used time {} s.'.format(time.time() - t0)) index, time = nn.raster_plot(mon) plt.plot(time, index, ',k') plt.xlabel('Time (ms)') plt.ylabel('Neuron index') plt.show()
import npbrain as nn nn.profile.set_backend('numba') nn.profile.set_dt(0.02) import matplotlib.pyplot as plt if __name__ == '__main__': hh = nn.HH(1, noise=1.) mon = nn.StateMonitor(hh, ['V', 'm', 'h', 'n']) net = nn.Network(hh=hh, mon=mon) net.run(duration=100, inputs=[hh, 10], report=True) ts = net.run_time() fig, gs = nn.vis.get_figure(2, 1, 3, 12) fig.add_subplot(gs[0, 0]) plt.plot(ts, mon.V[:, 0], label='N') plt.ylabel('Membrane potential') plt.xlim(-0.1, net.current_time + 0.1) plt.legend() fig.add_subplot(gs[1, 0]) plt.plot(ts, mon.m[:, 0], label='m') plt.plot(ts, mon.h[:, 0], label='h') plt.plot(ts, mon.n[:, 0], label='n') plt.legend() plt.xlim(-0.1, net.current_time + 0.1) plt.xlabel('Time (ms)') plt.show()
import matplotlib.pyplot as plt import npbrain as nn nn.profile.set_backend('numba') nn.profile.set_dt(0.02) if __name__ == '__main__': izh = nn.Izhikevich(10, noise=1.) mon = nn.StateMonitor(izh, ['V', 'u']) net = nn.Network(hh=izh, mon=mon) net.run(duration=100, inputs=[izh, 10], report=True) ts = net.run_time() fig, gs = nn.vis.get_figure(2, 1, 3, 12) indexes = [0, 1, 2] fig.add_subplot(gs[0, 0]) nn.vis.plot_potential(mon, ts, neuron_index=indexes) plt.xlim(-0.1, net.current_time + 0.1) plt.legend() fig.add_subplot(gs[1, 0]) nn.vis.plot_value(mon, ts, 'u', val_index=indexes) plt.xlim(-0.1, net.current_time + 0.1) plt.xlabel('Time (ms)') plt.legend() plt.show()
import npbrain as nn import numpy as np import matplotlib.pyplot as plt nn.profile.set_backend('numba') nn.profile.set_dt(0.02) np.random.seed(1234) if __name__ == '__main__': lif1 = nn.LIF(500, ref=1., noise=1.1) lif2 = nn.LIF(1000, ref=1., noise=1.1) conn = nn.conn.fixed_prob(lif1.num, lif2.num, prob=0.1) syn = nn.VoltageJumpSynapse(lif1, lif2, 0.2, conn) mon_lif1 = nn.StateMonitor(lif1) mon2 = nn.SpikeMonitor(lif1) mon_lif2 = nn.StateMonitor(lif2) mon4 = nn.SpikeMonitor(lif2) net = nn.Network(syn=syn, lif1=lif1, lif2=lif2, mon1=mon_lif1, mon2=mon2, mon3=mon_lif2, mon4=mon4) net.run(duration=100, inputs=[lif1, 15], report=True) ts = net.run_time() fig, gs = nn.vis.get_figure(2, 1, 3, 8) ax = fig.add_subplot(gs[0, 0])