Exemplo n.º 1
0
def pif_reset():
    defaultclock.reinit()
    sim = Network()
    I = 0.2*nA
    R = 1*Mohm
    lifeq = """
    dV/dt = I*R/ms : volt
    Vth : volt
    """
    thstep = 15*mV
    nrn = NeuronGroup(1, lifeq, threshold="V>=Vth", reset="V=0*mV")
    nrn.V = 0*mV
    nrn.Vth = thstep
    sim.add(nrn)

    #connection = Connection(inputgrp, nrn, state="V", weight=0.5*mV)
    #sim.add(inputgrp, connection)

    vmon = StateMonitor(nrn, "V", record=True)
    thmon = StateMonitor(nrn, "Vth", record=True)
    spikemon = SpikeMonitor(nrn, record=True)

    sim.add(vmon, thmon, spikemon)
    sim.run(duration)
    return vmon, thmon, spikemon
Exemplo n.º 2
0
def runsim(Nin, weight, fout, sync):
    sim = Network()
    clear(True)
    gc.collect()
    defaultclock.reinit()
    duration = 5*second
    lifeq = "dV/dt = -V/(10*ms) : volt"
    nrndef = {"model": lifeq, "threshold": "V>=15*mV", "reset": "V=0*mV",
              "refractory": 2*ms}
    fin = load_or_calibrate(nrndef, Nin, weight, sync, fout,
                            Vth=15*mV, tau=10*ms)
    # print("Calibrated frequencies:")
    # print(", ".join(str(f) for f in fin))
    inputgroups = []
    connections = []
    neurons = []
    Nneurons = len(fin)
    neurons = NeuronGroup(Nneurons, **nrndef)
    for idx in range(Nneurons):
        fin_i = fin[idx]
        sync_i, sigma_i = sync[idx]
        inputgrp = sl.tools.fast_synchronous_input_gen(Nin, fin_i,
                                                       sync_i, sigma_i,
                                                       duration)
        defaultclock.reinit()
        conn = Connection(inputgrp, neurons[idx], state="V", weight=weight)
        inputgroups.append(inputgrp)
        connections.append(conn)
    voltagemon = StateMonitor(neurons, "V", record=True)
    spikemon = SpikeMonitor(neurons, record=True)
    sim.add(neurons, voltagemon, spikemon)
    sim.add(*inputgroups)
    sim.add(*connections)
    print("Running {} {} {}".format(Nin, weight, fout))
    sim.run(duration, report="stdout")
    mnpss = []
    allnpss = []
    for idx in range(Nneurons):
        vmon = voltagemon[idx]
        smon = spikemon[idx]
        # print("Desired firing rate: {}".format(fout))
        # print("Actual firing rate:  {}".format(len(smon)/duration))
        if len(smon) > 0:
            npss = sl.tools.npss(vmon, smon, 0*mV, 15*mV, 10*ms, 2*ms)
        else:
            npss = 0
        mnpss.append(np.mean(npss))
        allnpss.append(npss)
    nrndeftuple = tuple(nrndef.items())
    key = (nrndeftuple, Nin, weight, tuple(sync), fout, 15*mV, 10*ms)
    save_data(key, allnpss)
    imshape = (len(sigma), len(Sin))
    imextent = (0, 1, 0, 4.0)
    mnpss = np.reshape(mnpss, imshape, order="F")
    plt.figure()
    plt.imshow(mnpss, aspect="auto", origin="lower", extent=imextent,
               interpolation="none", vmin=0, vmax=1)
    cbar = plt.colorbar()
    cbar.set_label("$\overline{M}$")
    plt.xlabel("$S_{in}$")
    plt.ylabel("$\sigma_{in}$ (ms)")
    filename = "npss_{}_{}_{}".format(Nin, weight, fout).replace(".", "")
    plt.savefig(filename+".pdf")
    plt.savefig(filename+".png")
    print("{} saved".format(filename))
    voltages = voltagemon.values
    spiketrains = spikemon.spiketimes.values()
    pickle.dump({"voltages": voltages, "spiketrains": spiketrains},
                 open(filename+".pkl", 'w'))
    return voltagemon, spikemon
Exemplo n.º 3
0
def runsim(fin):
    clear(True)
    gc.collect()
    defaultclock.reinit()
    weight = 0.16*mV
    sim = Network()
    duration = 2.0*second
    Vth = 15*mV
    Vreset = 13.65*mV
    trefr = 2*ms
    lifeq = """
    dV/dt = -V/(10*ms) : volt
    Vth : volt
    """
    nrndef = {"model": lifeq, "threshold": "V>=Vth", "reset": "V=Vreset",
              "refractory": 0.1*ms}
    inputgroups = []
    connections = []
    neurons = []
    Nneurons = len(fin)
    neurons = NeuronGroup(Nneurons, **nrndef)
    neurons.V = 0*mV
    neurons.Vth = 15*mV
    for idx in range(Nneurons):
        fin_i = fin[idx]*Hz
        inputgrp = PoissonGroup(50, fin_i)
        conn = Connection(inputgrp, neurons[idx], state="V", weight=weight)
        inputgroups.append(inputgrp)
        connections.append(conn)
    voltagemon = StateMonitor(neurons, "V", record=True)
    spikemon = SpikeMonitor(neurons, record=True)
    sim.add(neurons, voltagemon, spikemon)
    sim.add(*inputgroups)
    sim.add(*connections)

    @network_operation
    def refractory_threshold(clock):
        for idx in range(Nneurons):
            if (len(spikemon.spiketimes[idx])
                    and clock.t < spikemon.spiketimes[idx][-1]*second+trefr):
                neurons.Vth[idx] = 100*mV
            else:
                neurons.Vth[idx] = Vth

    sim.add(refractory_threshold)
    print("Running simulation of {} neurons for {} s".format(Nneurons, duration))
    sim.run(duration, report="stdout")
    mnpss = []
    allnpss = []
    outisi = []
    for idx in range(Nneurons):
        vmon = voltagemon[idx]
        smon = spikemon[idx]
        if not len(smon):
            continue
        outisi.append(duration*1000/len(smon))
        if len(smon) > 0:
            npss = sl.tools.npss(vmon, smon, 0*mV, 15*mV, 10*ms, 2*ms)
        else:
            npss = 0
        mnpss.append(np.mean(npss))
        allnpss.append(npss)
    return outisi, mnpss