Ejemplo n.º 1
0
def estimate_vkappas(model):
    locs = lb.calc_locs_kappa(model)
    lb.add_Estims(model, locs)
    lb.add_AMPAsyns(model, locs, model.gmax)
    model.tstop = 100
    strvkp = "data/spf4d4_vkappas_RA" + str(model.RA) + "_gm" + str(
        model.gmax) + "_dm_" + str(model.dendmodel) + ".txt"
    fvkp = open(strvkp, 'w')
    vkappas = []
    for lidx in range(len(locs)):
        for l2idx in range(len(locs)):
            model.Estimlist[l2idx].number = 0
        model.Estimlist[lidx].number = 1
        ttmp, vtmp = lb.simulate(model)
        dvtmp = max(vtmp) - vtmp[-1]
        print lidx, dvtmp
        vkappas.append(dvtmp)
        fvkp.write(
            str(locs[lidx][0]) + " " + str(locs[lidx][1]) + " " + str(dvtmp) +
            "\n")
        fvkp.flush()
    plt.hist(vkappas)
    plt.show()
Ejemplo n.º 2
0
def main(args=None):
    """Main"""

    # Simulation general parameters
    data.dt = 0.1
    lb.h.dt = data.dt
    lb.h.steps_per_ms = 1.0 / lb.h.dt
    data.st_onset = 200.0
    data.st_duration = 200.
    data.TSTOP = 600
    data.TRIALS = 5
    data.Egmax = 1
    data.Igmax = 1
    data.Irev = -80
    data.Ensyn = 100
    data.Insyn = int(data.Ensyn * 0.2)
    data.bEnsyn = 200
    data.bInsyn = int(data.bEnsyn * 0.2)

    # Simulation CONTROL
    data.model = 'L23'
    data.locType = 'fixed'
    data.simType = 'rateIteration'
    data.fixedINPUT = False

    data.ACTIVE = True
    data.ACTIVEdend = True
    data.ACTIVEdendNa = True
    data.ACTIVEdendCa = True
    data.ACTIVEaxonSoma = True
    data.ACTIVEhotSpot = True
    data.SYN = True
    data.SPINES = False
    data.ICLAMP = False
    data.NMDA = True
    data.GABA = True
    data.BGROUND = True
    global model
    # Create neuron and add mechanisms
    if data.model == 'BS': model = lb.BS()
    if data.model == 'L23': model = lb.L23()
    if data.model == 'CELL': model = lb.CELL()
    if data.SPINES: lb.addSpines(model)
    if data.ACTIVE:
        lb.init_active(model,
                       axon=data.ACTIVEaxonSoma,
                       soma=data.ACTIVEaxonSoma,
                       dend=data.ACTIVEdend,
                       dendNa=data.ACTIVEdendNa,
                       dendCa=data.ACTIVEdendCa)
    if data.ACTIVEhotSpot: lb.hotSpot(model)

    # Generate synapse locations
    if data.locType == 'random':
        data.Elocs = genRandomLocs(data, model, data.Ensyn)
        data.Ilocs = genRandomLocs(data, model, data.Insyn)

    if data.locType == 'fixed':
        loadElocs = np.load('./Elocs.npy')
        data.Elocs = loadElocs[0:data.Ensyn]
        loadIlocs = np.load('./Ilocs.npy')
        data.Ilocs = loadIlocs[0:data.Insyn]

    if data.BGROUND:
        data.bElocs = genRandomLocs(data, model, data.bEnsyn)
        data.bIlocs = genRandomLocs(data, model, data.bInsyn)
        data.Elocs = np.vstack((data.Elocs, data.bElocs))
        data.Ilocs = np.vstack((data.Ilocs, data.bIlocs))

        # Hack for freezing the background
        # Uncomment first 2 lines and comment out last 2 for
        # random background

        #data.bElocs = loadElocs[data.Ensyn+1:]
        #data.bIlocs = loadIlocs[data.Insyn+1:]
        data.Elocs = loadElocs
        data.Ilocs = loadIlocs

    # Insert synapses
    if data.SYN:
        lb.add_AMPAsyns(model, locs=data.Elocs, gmax=data.Egmax)
        if data.NMDA: lb.add_NMDAsyns(model, locs=data.Elocs, gmax=data.Egmax)
        if data.GABA:
            lb.add_GABAsyns(model,
                            locs=data.Ilocs,
                            gmax=data.Igmax,
                            rev=data.Irev)

    # Insert IClamp
    data.iclampLoc = ['dend', 0.5, 28]
    data.iclampOnset = 50
    data.iclampDur = 250
    data.iclampAmp = 0

    if data.ICLAMP:
        if data.iclampLoc[0] == 'soma':
            lb.add_somaStim(model,
                            data.iclampLoc[1],
                            onset=data.iclampOnset,
                            dur=data.iclampDur,
                            amp=data.iclampAmp)
        if data.iclampLoc[0] == 'dend':
            lb.add_dendStim(model,
                            data.iclampLoc[1],
                            data.iclampLoc[2],
                            onset=data.iclampOnset,
                            dur=data.iclampDur,
                            amp=data.iclampAmp)

    #----------------------------------------------------------------------------
    # Data storage lists
    data.vdata, data.vDdata, data.gdata, data.idata, data.caDdata, data.vsec = [], [], [], [], [], []
    data.rates = []

    #----------------------------------------------------------------------------
    # Run simulation

    # Specific parameters
    data.rateRange = np.arange(8, 9, 10)
    data.lagRange = np.arange(-100, 110, 10)
    data.iRange = np.arange(-0.1, 0.2, 0.1)
    data.singleRate = 51
    data.tInterval = 1
    data.EbGroundRate = 2
    data.IbGroundRate = 2
    data.recordDend = True
    data.recordSec = False

    if data.simType == 'rateIteration':
        SIM_rateIteration(data, model, data.rateRange, data.BGROUND)
    if data.simType == 'iSteps':
        SIM_currentSteps(data, model, data.iRange, data.BGROUND)

    #----------------------------------------------------------------------------
    # Save data
    modelData = sc.emptyObject()
    lb.props(modelData)

    tstamp = time.strftime("sim%Y%b%d_%H%M%S")
    tstamp = 'temp'

    dataList = [data, modelData]
    fname = './' + tstamp + '.pkl'
    f = open(fname, 'wb')
    pickle.dump(dataList, f)
    f.close()
Ejemplo n.º 3
0
## which dendrites to record from
data.locDendRec = [11, 24, 70, 95]
# best for recording - non-terminal apical branches, 100 um from soma, diam > 1 um
# 38 - dend2_1212[0.5] L = 140 um, d=1.1 um, dist ~ 157 um
# 47 - dend2_1222[0.5] L=150, d=1.1, dist ~ 157 um
# 69 - dend3_1212222[0.5] L=47, d=1.4, dist ~ 135 um
# 70 - dend3_12122221[0.5] L = 231um, d = 0.75 um
# mainAll.model.dends[11].name()
# mainAll.lb.h.topology()

# np.random.shuffle(data.Elocs)

# Insert synapses
lb.add_AMPAsyns(model,
                locs=data.Elocs,
                gmax=data.ApN * data.Egmax,
                NoSynDends=noSynDend)
if (data.NMDAkinetic):
    lb.add_NMDAkin_syns(model,
                        locs=data.Elocs,
                        gmax=data.Egmax,
                        NoSynDends=noSynDend)
else:
    if (data.NMDA):
        lb.add_NMDAsyns(model,
                        locs=data.Elocs,
                        gmax=data.Egmax,
                        NoSynDends=noSynDend)
    else:
        lb.add_NMDAsyns(model, locs=data.Elocs, gmax=0, NoSynDends=noSynDend)
lb.add_GABAsyns(model,
Ejemplo n.º 4
0
def simul(Kin, gmax, gI, uk_min, sd_bias, release_prob, ik):
    model = lb.L23()  # Layer 2/3 model is selected
    dendActive = True  # with passive/active dendrrite
    opt_update = True  #whether update rule is optimal or approximate
    rewiring = True  #if the model includes rewiring or not
    dropping = True  #if the model includes uncompensated elimination
    membrane_recording = True  #if membrane dynamics is recorded or not (generate a heavy file if true)
    prespike_recording = False  #if the prespikes are recorded or not

    # active channels are distributed over both axon and dendrite
    lb.init_active(model,
                   axon=True,
                   soma=True,
                   dend=dendActive,
                   dendNa=True,
                   dendCa=True)
    lb.init_params(model, Kin, gmax, gI, uk_min, sd_bias, release_prob)

    model.dendmodel = 'active' if dendActive else 'passive'
    model.learningrule = 'opt' if opt_update else 'apr'
    if rewiring or dropping:
        model.connections = ''
        if rewiring:
            model.connections = model.connections + 'rewired_'
        if dropping:
            model.connections = model.connections + 'dropped_'
    else:
        model.connections = 'fixed'

    #CAUTION: 'estimate_vkappas' resets vkappa
    #estimate_vkappas(model)

    #locs = lb.calc_locs(model) #uniformly locate synapses
    locs = lb.calc_locs_random(model)  # randomly locate synapses
    lb.allocate_syns(model)
    #lb.plot_morphology(model,locs)

    lb.add_Estims(model, locs)
    lb.add_AMPAsyns(model, locs, model.gmax)

    inh_locs = lb.calc_inh_locs_uniform(model)
    lb.add_Istims(model, inh_locs)
    lb.add_GABAsyns(model, inh_locs, model.gI)

    dks = estimate_dks(model, locs)  #estimate the distances from the soma
    vks = pickup_vks(model, locs)  #readout values of vks
    mean_pre_rates = np.full((model.Nin), model.spn_rate)

    pvks = calc_pvks(vks)  #prior distribution of vks

    uks, gks = initialize_ukgks(model, pvks)
    lb.generate_pre_tuning(model)
    lb.generate_input_rates(model)

    model.vkmax = max(vks)
    model.vkmin = min(vks)
    model.gamma = max(model.log_p_rates) / model.vkmax
    model.vo = 1.5 * model.vkmin  #

    fstrtmp = 'K' + str(model.Kin) + "_RA" + str(model.RA) + '_gm' + str(model.gmax) + '_gi' + str(model.gI) + \
              '_dm_' + str(model.dendmodel) + '_lr_' + str(model.learningrule) + '_cw_' + str(model.connections) \
              + '_ukm_' + str(uk_min) + '_sdb_' + str(sd_bias) + '_pr_' + str(release_prob) + '_ik' + str(ik) + '.txt'
    strperf = 'data/nrn_simul_perf_' + fstrtmp
    fperf = open(strperf, 'w')
    strduvk = 'data/nrn_simul_duvk_' + fstrtmp
    fduvk = open(strduvk, 'w')
    strtune = 'data/nrn_simul_tune_' + fstrtmp
    ftune = open(strtune, 'w')
    for j in range(model.Min):
        ftune.write(
            str(j) + ' ' + str(model.phis[j]) + ' ' + str(model.thetas[j]) +
            ' ' + str(model.rfdists[j]) + ' ' +
            str(model.log_p_rates[j] / model.gamma) + ' ' +
            str(model.log_n_rates[j] / model.gamma) + '\n')
    ftune.flush()
    if prespike_recording:
        strprespike = 'data/nrn_simul_prespike_' + fstrtmp
        fprespike = open(strprespike, 'w')

    model.tstop = 100
    trs = [0, 100]
    perfs = []
    for q in range(3):
        perfs.append([])
    for t in range(model.trials):
        if is_match(t, trs):  #evaluation
            if membrane_recording:
                if t == trs[0]:
                    strmbps = 'data/nrn_simul_mbps_' + fstrtmp
                    fmbps = open(strmbps, 'w')
                elif t == trs[-1]:
                    strmbpf = 'data/nrn_simul_mbpf_' + fstrtmp
                    fmbpf = open(strmbpf, 'w')

            for i in range(model.Nin):
                fduvk.write(
                    str(locs[i][0]) + " " + str(locs[i][1]) + " " +
                    str(model.preidx[i]) + " " + str(dks[i]) + " " +
                    str(uks[i]) + " " + str(vks[i]) + "\n")

            dist_bt_syns = lb.calc_dist_bt_syns(model, locs)
            for didx in range(len(dist_bt_syns)):
                fduvk.write(str(dist_bt_syns[didx]) + ' ')
            fduvk.write('\n')
            fduvk.flush()

            #test phase
            for t2 in range(200):
                true_pre_spikes = []
                pre_spikes = []
                if t2 < 100:
                    true_pre_spikes, pre_spikes = lb.generate_prespikes(
                        model, model.p_rates)
                else:
                    true_pre_spikes, pre_spikes = lb.generate_prespikes(
                        model, model.n_rates)
                if prespike_recording:
                    for j in range(model.Min):
                        fprespike.write(
                            str(t) + " " + str(t2) + " " + str(j) + " " +
                            str(true_pre_spikes[j]) + "\n")
                    fprespike.flush()

                lb.generate_inputs(model, uks, pre_spikes)
                lb.generate_inh_inputs(model, true_pre_spikes)

                ttmp, vtmp = lb.simulate(model)

                perftmp = evaluate_perf(model, true_pre_spikes, ttmp, vtmp)
                strtmp = str(t) + ' ' + str(perftmp[0]) + ' ' + str(
                    perftmp[1]) + ' ' + str(perftmp[2]) + ' ' + str(
                        perftmp[3]) + ' ' + str(perftmp[4]) + '\n'
                fperf.write(strtmp)
                if membrane_recording:
                    if t == trs[0]:
                        for t3 in range(len(ttmp)):
                            strtmp = str(t2) + ' ' + str(ttmp[t3]) + ' ' + str(
                                vtmp[t3]) + '\n'
                            fmbps.write(strtmp)
                        fmbps.flush()
                    if t == trs[-1]:
                        for t3 in range(len(ttmp)):
                            strtmp = str(t2) + ' ' + str(ttmp[t3]) + ' ' + str(
                                vtmp[t3]) + '\n'
                            fmbpf.write(strtmp)
                        fmbpf.flush()

        #training phase
        true_pre_spikes, pre_spikes = lb.generate_prespikes(
            model, model.p_rates)
        mean_pre_rates = np.multiply(1.0 - 1.0 / model.taumr,
                                     mean_pre_rates) + np.multiply(
                                         1.0 / model.taumr, pre_spikes)
        if opt_update:
            uks = update_uks(model, vks, uks, pre_spikes, rewiring, dropping)
        else:
            uks = update_uks_apr(model, vks, uks, pre_spikes, rewiring,
                                 dropping)
        if prespike_recording:
            for j in range(model.Min):
                fprespike.write(
                    str(t) + " " + str(j) + " " + str(true_pre_spikes[j]) +
                    "\n")
            fprespike.flush()

        if rewiring:  #rewiring of connections with small spine sizes
            rwcnt = 0
            loctmp = []
            for i in range(model.Nin):
                if uks[i] < model.ukthreshold and uks[i] != 0.0:
                    if np.random.random() < model.rewiring_freq:
                        loctmp = lb.restricted_resampling(model, locs, i)

                        locs[i][0] = loctmp[0]
                        locs[i][1] = loctmp[1]
                        vks[i] = pick_a_vk(model, locs[i])
                        uks[i] = model.ukinit

                        dks[i] = model.dists[locs[i][
                            0]] + locs[i][1] * model.dends[locs[i][0]].L
                        lb.rewire_synapse(model, locs[i], i)
                        rwcnt += 1
        if dropping:  #elimination of inactive connections
            for i in range(model.Nin):
                if mean_pre_rates[i] < model.pre_rates_th and np.random.random(
                ) < model.rewiring_freq:
                    uks[i] = 0.0
        for i in range(model.Nin):
            if uks[i] != 0.0 and uks[i] < model.ukthreshold:
                uks[i] = model.uk_min