def plot_example_firing_rate(ax, layer, name, color='b', ylim=[]):
    time_bin = 20

    signal = layer.signals['spikes']
    #signal.my_firing_rate(bin=time_bin, display=ax,
    #                      kwargs={'color':color})

    print name, 'CV:', numpy.mean(signal.cv_isi())
    print name, 'mean:', signal.mean_rate()
    print name, 'std:', signal.mean_rate_std()
    hist = signal.spike_histogram(time_bin=1, normalized=True)
    spk_mean = numpy.mean(hist, axis=0)
    spk_mean = misc.convolve(spk_mean, 100, 'triangle', single=True)[0]
    print spk_mean.shape
    time = numpy.arange(1, len(spk_mean) + 1)
    ax.plot(time, spk_mean)

    if layer.id_mod:
        print numpy.array(layer.id_mod) - layer.ids[0] - 1
        spk_mean = numpy.mean(hist[numpy.array(layer.id_mod) -
                                   layer.ids[0], :],
                              axis=0)
        spk_mean = misc.convolve(spk_mean, 100, 'triangle', single=True)[0]
        print spk_mean.shape
        time = numpy.arange(1, len(spk_mean) + 1)
        ax.plot(time, spk_mean, 'r')

    ax.set_ylabel('Firing rate ' + name + ' (spikes/s)')
    ax.set_xlabel('Time (ms)')
    ax.my_set_no_ticks(yticks=6, xticks=8)
    ax.set_ylim(ylim)
def plot_example_firing_rate_MSN(ax, layer, name, color='b', ylim=[]):
    time_bin = 20

    signal = layer.signals['spikes']
    #signal.my_firing_rate(bin=time_bin, display=ax,
    #                      kwargs={'color':color})

    print name, 'CV:', numpy.mean(signal.cv_isi())
    print name, 'mean:', signal.mean_rate()
    print name, 'std:', signal.mean_rate_std()
    hist = signal.spike_histogram(time_bin=1, normalized=True)
    spk_mean = numpy.mean(hist, axis=0)
    spk_mean = misc.convolve(spk_mean, 100, 'triangle', single=True)[0]
    print spk_mean.shape
    time = numpy.arange(1, len(spk_mean) + 1)
    ax.plot(time, spk_mean)

    shift = 0
    if layer.id_mod:
        print numpy.array(layer.id_mod) - layer.ids[0] - 1
        spk_mean = numpy.mean(
            hist[numpy.array(layer.id_mod) - layer.ids[0], :] - shift, axis=0)
        spk_mean = misc.convolve(spk_mean, 50, 'triangle', single=True)[0]
        print spk_mean.shape
        time = numpy.arange(1, len(spk_mean) + 1)
        ax.plot(time, spk_mean, 'r')

    pylab.setp(ax.lines,
               linewidth=2.0)  # Need to pu ti before generating legend

    ax.set_ylabel('Rate  ' + name + ' (spikes/s)')
    ax.set_xlabel('Time (ms)')
    ax.my_set_no_ticks(yticks=6, xticks=5)
    ax.set_xlim(misc.adjust_limit([0, 1500]))
    ax.set_ylim(misc.adjust_limit(ylim))

    ax.text(0.05,
            0.65,
            'Bursting \n$MSN_{D1}$',
            backgroundcolor='w',
            transform=ax.transAxes,
            fontsize=font_size_text,
            **{'color': 'r'})
    ax.text(0.05,
            0.85,
            'Average \nover all',
            backgroundcolor='w',
            transform=ax.transAxes,
            fontsize=font_size_text,
            **{'color': 'b'})

    for line in ax.lines:
        line.set_xdata(line.get_xdata() - 500)
Example #3
0
def plot_example_3x_freq(ax, times, spk_mean, hzs=[10, 20, 40]):
    spk_mean = spk_mean
    colors = misc.make_N_colors('YlOrBr', 5)[2:]

    labels = ['%i Hz' % hzs[0], '%i Hz' % hzs[1], '%i Hz' % hzs[2]]
    coords = [[0.4, 0.52], [0.05, 0.22], [0.1, 0.74]]
    for i, col in enumerate(colors):
        ax.plot(times,
                misc.convolve(spk_mean[i, :], 50, 'triangle', single=True)[0],
                color=col)
        #ax.plot(times, spk_mean[i,:], col)

    lines = ax.lines
    for line in lines:
        line.set_xdata(line.get_xdata() - ADJUST_XDATA_MS)
        misc.slice_line(line, xlim=[0, 1490])
    #ax.set_ylim([0,40])

    for label, coord, color in zip(labels, coords, colors):
        ax.text(coord[0],
                coord[1],
                label,
                transform=ax.transAxes,
                fontsize=font_size_text,
                **{'color': color})

    ax.set_ylabel('Rate SNr (spikes/s)')
    ax.set_xlabel('Time (ms)')

    ax.my_set_no_ticks(yticks=6, xticks=8)
    ax.set_xlim(misc.adjust_limit([0, 1500]))
    ax.set_ylim(misc.adjust_limit([0, 40]))
Example #4
0
def plot_example_firing_rate(ax, groups, name,  color='b', ylim=[], ylabel=True, xlabel=False):
    time_bin=20


    colors=misc.make_N_colors('gist_rainbow', len(groups))
    #signal.my_firing_rate(bin=time_bin, display=ax,
    #                      kwargs={'color':color})


    
    for group, col in zip(groups, colors):
        signal=group.signals['spikes']
        print name, 'CV:', numpy.mean(signal.cv_isi())
        print name, 'mean:', signal.mean_rate()
        print name, 'std:', signal.mean_rate_std()
        hist=signal.spike_histogram(time_bin=1, normalized=True)
        spk_mean=numpy.mean(hist, axis=0)
        spk_mean=misc.convolve(spk_mean, 100, 'triangle',single=True)[0]
        print spk_mean.shape
        time=numpy.arange(1,len(spk_mean)+1)
        ax.plot(time,spk_mean, **{'color':col})
    

    ax.set_ylabel('Firing rate '+name+'\n (spikes/s)', fontsize=12.,multialignment='center') 
    ax.set_xlabel('Time (ms)')    
    
    ax.my_set_no_ticks( yticks=6, xticks = 8 ) 
    ax.set_ylim(ylim)
    ax.set_xlim([time[0],time[-1]])
    
    ax.my_remove_axis( xaxis=not xlabel, yaxis=not ylabel ) 
Example #5
0
def conv_data(raw_r,
              conv_r,
              mean_conv_r,
              std_conv_r,
              bin=100,
              kernel='rectangle'):
    conv_r.append(misc.convolve(raw_r[-1], bin, kernel, single=False))
    mean_conv_r.append(numpy.mean(conv_r[-1], axis=0))
    std_conv_r.append(numpy.std(conv_r[-1], axis=0))
    return conv_r, mean_conv_r, std_conv_r
def simulate(load,
             save_at,
             n_exp,
             res,
             params_msn_d1,
             params_msn_d2,
             params_stn,
             synapse_models,
             sim_time,
             seed,
             start_rec,
             I_e_add,
             threads,
             model_params,
             dis_conn_GPE_STN=False):

    if not load:
        r = []

        for i in range(n_exp):
            seed = i
            p = numpy.random.randint(1)
            start_rec += p
            sim_time += p
            layer_dic = simulate_network(params_msn_d1,
                                         params_msn_d2,
                                         params_stn,
                                         synapse_models,
                                         sim_time,
                                         seed,
                                         I_e_add,
                                         threads,
                                         start_rec,
                                         model_params,
                                         dis_conn_GPE_STN=dis_conn_GPE_STN)

            layer_dic['SNR'].get_signal('s', start=start_rec, stop=sim_time)
            signal = layer_dic['SNR'].signals['spikes']
            r.append(
                numpy.mean(signal.spike_histogram(time_bin=1, normalized=True),
                           axis=0))

        numpy.array(r)
        misc.pickle_save(r, save_at)
    else:
        r = misc.pickle_load(save_at)
    r = numpy.array(r)
    r = misc.convolve(r, res, 'triangle', single=False)
    mr = numpy.mean(r, axis=0)
    mstd = numpy.std(r, axis=0)
    d = [mr, mstd]
    return d
Example #7
0
def plot_example_snr(ax, SNR):
    time_bin = 20
    signal = SNR.signals['spikes']
    colors = ['k']

    sim_time = 2500

    hist = signal.spike_histogram(time_bin=1, normalized=True)
    spk_mean = numpy.mean(hist, axis=0)
    spk_mean = misc.convolve(spk_mean, 100, 'triangle', single=True)[0]
    time = numpy.arange(1, len(spk_mean) + 1)
    ax.plot(time, spk_mean, 'k')

    ax.my_set_no_ticks(yticks=6, xticks=7)
    lines = ax.lines

    lines = ax.lines
    for line in lines:

        misc.slice_line(line, xlim=[50, 2450])

    ax.plot([0, sim_time], [SELECTION_THR] * len([0, sim_time]), **{
        'color': [0.6, 0.6, 0.6],
        'label': '',
        'linewidth': 1,
        'linestyle': '--'
    })
    ax.text(0.9,
            0.14,
            'Thr',
            transform=ax.transAxes,
            **{'color': [0.6, 0.6, 0.6]})
    misc.slice_line(lines[0], xlim=[0, sim_time])

    ax.plot([1000, 1500], [39, 39], color='k', marker='|')
    ax.text(0.47, 0.84, 'stop', transform=ax.transAxes, **{'color': 'k'})

    ax.plot([500, 700], [30, 30], color='k', marker='|')
    ax.text(0.23, 0.67, '1st', transform=ax.transAxes, **{'color': 'k'})

    ax.plot([1500, 1700], [30, 30], color='k', marker='|')
    ax.text(0.60, 0.67, '2nd', transform=ax.transAxes, **{'color': 'k'})

    ax.set_xlim(misc.adjust_limit([0, sim_time]))
    ax.set_ylim(misc.adjust_limit([0, 45]))

    ax.set_ylabel('Firing rate SNr (spikes/s)')
def plot_example_firing_rate(ax, spk, name, color=['b', 'g', 'r'], ylim=[]):

    for col, sp in zip(color, spk):
        time = numpy.arange(1, len(sp) + 1)
        sp = misc.convolve(sp, 100, 'triangle', single=True)[0]
        ax.plot(time, sp, **{'color': col})

    #spk_rate=misc.convolve(spk_mean[i,:], 50, 'triangle',single=True)[0]
    #plot()
    #meanRate=round(layer.signals['spikes'].mean_rate(1000,sim_time),1)
    #spk=SNR.signals['spikes'].time_slice(1000,sim_time).raw_data()
    #CV=numpy.std(numpy.diff(spk[:,0],axis=0))/numpy.mean(numpy.diff(spk[:,0],axis=0))

    ax.set_ylabel('Firing rate ' + name + ' (spikes/s)')
    ax.set_xlabel('Time (ms)')
    ax.my_set_no_ticks(yticks=6, xticks=8)
    ax.set_ylim(ylim)
Example #9
0
def simulate_direct_vs_indirect(load,
                                N_MSN,
                                burst_rate,
                                save_at,
                                threads,
                                resolution=10,
                                flag_bg=False):

    params_msn_d1 = {
        'base_rates': [0.1],
        'base_times': [1],
        'mod_rates': [0.1, burst_rate, 0.1],
        'mod_times': [1, 1000, 1000 + 500],
        'n_mod': 0,
        'bg_rate': 0
    }
    params_msn_d2 = {
        'base_rates': [0.1],
        'base_times': [1],
        'mod_rates': [0.1, burst_rate, 0.1],
        'mod_times': [1, 1000, 1000 + 500],
        'n_mod': 0,
        'focus': False,
        'skip': 1,
        'bg_rate': 0
    }
    params_stn = {
        'rate': 250.,
        'mod': False,
        'mod_rate': 0.,
        'mod_times': [1000., 1000. + 500.]
    }

    model_params = {
        'conns': {
            'MSN_D2_GPE': {
                'lines': False
            }
        },
        'neurons': {
            'MSN_D1': {
                'n': N_MSN
            },
            'MSN_D2': {
                'n': N_MSN
            }
        }
    }

    synapse_models = ['MSN_SNR_gaba_p1', 'GPE_SNR_gaba_p']

    if flag_bg: save_at = save_at + '_bg'

    sim_time = 2000.

    n_exp = 2

    proportions_d1 = numpy.linspace(0.01, 0.15,
                                    resolution)  #arange(1,7,1)*150.
    proportions_d2 = numpy.linspace(0.01, 0.15,
                                    resolution)  #arange(1,7,1)*150.
    mods_d1 = proportions_d1 * N_MSN
    mods_d2 = proportions_d2 * N_MSN

    raw_r = []
    conv_r = []
    mean_conv_r = []
    std_conv_r = []

    inputs = []
    i = 0
    if not load:
        for m_d1 in mods_d1:
            for m_d2 in mods_d2:
                tmp_rates = []
                for e in range(n_exp):
                    seed = i

                    rates_SNR, rates_GPE = simulate_network_direct_indirect_onoff_vs_rate(
                        m_d1,
                        m_d1,
                        params_msn_d1,
                        params_msn_d2,
                        params_stn,
                        synapse_models, {
                            'SNR': 280,
                            'STN': 0,
                            'GPE': 20
                        },
                        sim_time=sim_time,
                        seed=seed,
                        threads=threads,
                        start_rec=500.,
                        model_params=model_params,
                        flag_bg=flag_bg)

                    tmp_rates.append(list(rates_SNR))

                    i += 1

                raw_r.append(numpy.array(tmp_rates))
                conv_r.append(
                    misc.convolve(raw_r[-1], 100, 'rectangle', single=False))
                mean_conv_r.append(numpy.mean(conv_r[-1], axis=0))
                std_conv_r.append(numpy.std(conv_r[-1], axis=0))
                inputs.append((m_d1, m_d2))

                misc.pickle_save(
                    [raw_r, conv_r, mean_conv_r, std_conv_r, inputs], save_at)
    else:
        raw_r, conv_r, mean_conv_r, std_conv_r, inputs = misc.pickle_load(
            save_at)

    data, data_split, slopes = get_data_and_slopes(inputs, mean_conv_r,
                                                   std_conv_r, resolution,
                                                   N_MSN)

    return data, data_split, slopes, burst_rate, proportions_d1, proportions_d2
Example #10
0
def simulate_indirect(load,
                      N_MSN,
                      save_at,
                      threads,
                      resolution=10,
                      max_prop=1.1,
                      flag_bg=False,
                      skip=1,
                      lines=False):

    params_msn_d1 = {
        'base_rates': [0.1],
        'base_times': [1],
        'mod_rates': [],
        'mod_times': [],
        'n_mod': 0,
        'bg_rate': 0
    }
    params_msn_d2 = {
        'base_rates': [0.1],
        'base_times': [1],
        'mod_rates': [],
        'mod_times': [],
        'n_mod': 0,
        'focus': False,
        'skip': skip,
        'bg_rate': 0
    }
    params_stn = {
        'rate': 250.,
        'mod': False,
        'mod_rate': 0.,
        'mod_times': [1000., 1000. + 500.]
    }

    synapse_models = ['MSN_SNR_gaba_p1', 'GPE_SNR_gaba_p']

    model_params = {
        'misc': {
            'N_MSN': N_MSN
        },
        'conns': {
            'MSN_D2_GPE': {
                'lines': lines
            }
        },
        'neurons': {
            'MSN_D1': {
                'n': N_MSN
            },
            'MSN_D2': {
                'n': N_MSN
            }
        }
    }

    if flag_bg: save_at = save_at + '_bg'

    sim_time = 2000.
    n_exp = 5

    burst_rate = numpy.linspace(15, 50, resolution)
    proportions = numpy.linspace(0.01, max_prop,
                                 resolution)  #arange(1,7,1)*150.
    mods = proportions * N_MSN

    raw_r, conv_r, mean_conv_r, std_conv_r, inputs = [], [], [], [], []
    i = 0
    if not load:
        for m in mods:

            for r in burst_rate:
                tmp_rates = []
                for e in range(n_exp):
                    seed = i
                    rates_SNR, rates_GPE = simulate_indirect_fun(
                        m,
                        r,
                        params_msn_d1,
                        params_msn_d2,
                        params_stn,
                        synapse_models, {
                            'SNR': 280,
                            'STN': 0,
                            'GPE': 20
                        },
                        sim_time=sim_time,
                        seed=seed,
                        threads=threads,
                        start_rec=500.,
                        model_params=model_params,
                        flag_bg=flag_bg,
                        max_mod=max(mods))

                    tmp_rates.append(list(rates_SNR))

                    i += 1

                raw_r.append(numpy.array(tmp_rates))
                conv_r.append(
                    misc.convolve(raw_r[-1], 100, 'rectangle', single=False))
                mean_conv_r.append(numpy.mean(conv_r[-1], axis=0))
                std_conv_r.append(numpy.std(conv_r[-1], axis=0))
                inputs.append((m, r))

                misc.pickle_save(
                    [raw_r, conv_r, mean_conv_r, std_conv_r, inputs], save_at)
    else:
        raw_r, conv_r, mean_conv_r, std_conv_r, inputs = misc.pickle_load(
            save_at)

    data, data_split, slopes = get_data_and_slopes(inputs, mean_conv_r,
                                                   std_conv_r, resolution,
                                                   N_MSN)

    return data, data_split, slopes, burst_rate, proportions
Example #11
0
def simulate_non_diffuse(load, save_at, n_exp, mod, skip, res=100):
    #synapse_models=['MSN_SNR_gaba_p1', 'GPE_SNR_gaba_p_stoc']
    synapse_models_mod = ['GPE_SNR_gaba_s_ref', 'GPE_SNR_gaba_p']

    model_params = {
        'misc': {
            'N_MSN': N_MSN
        },
        'conns': {
            'MSN_D2_GPE': {
                'lines': True
            }
        },
        'neurons': {
            'MSN_D1': {
                'n': N_MSN
            },
            'MSN_D2': {
                'n': N_MSN
            }
        }
    }
    params_msn_d2 = {
        'base_rates': [0.1],
        'base_times': [1],
        'mod_rates': [0.1, 20.0, 0.1],
        'mod_times': [1, 1500, 1500 + 500],
        'n_mod': mod,
        'focus': False,
        'skip': skip
    }

    if not load:
        d = {}
        for model, seed in zip(synapse_models_mod, [1, 1]):
            synapse_models = ['MSN_SNR_gaba_p1', model]
            spk_mean = []
            for i in range(n_exp):
                seed = i
                layer_dic = simulate_network(params_msn_d1,
                                             params_msn_d2,
                                             params_stn,
                                             synapse_models,
                                             sim_time=sim_time,
                                             seed=seed,
                                             I_e_add={},
                                             threads=4,
                                             start_rec=start_rec,
                                             model_params=model_params)

                signal = layer_dic['SNR'].signals['spikes']
                spk_mean.append(
                    numpy.mean(signal.spike_histogram(time_bin=1,
                                                      normalized=True),
                               axis=0))

                signal = layer_dic['GPE'].signals['spikes']
                hist = signal.spike_histogram(time_bin=1, normalized=True)
                spk_mean.append(numpy.mean(hist, axis=0))

                down, up = [], []
                for i in range(hist.shape[0]):
                    if numpy.mean(hist[i, 1000:1500]) < numpy.mean(
                            hist[i, 0:1000]):
                        down.append(hist[i, :])
                    else:
                        up.append(hist[i, :])

                spk_mean.append(numpy.mean(numpy.array(down), axis=0))
                spk_mean.append(numpy.mean(numpy.array(up), axis=0))

            d[model] = spk_mean

            misc.pickle_save(d, save_at)
    else:
        d = misc.pickle_load(save_at)

    d_SNR, d_GPE = [], []
    for r in d.values():
        r = numpy.array(r)
        r = misc.convolve(r, res, 'triangle', single=False)
        d_SNR.append(
            [numpy.mean(r[0::4, :], axis=0),
             numpy.std(r[0::4, :], axis=0)])  # SNR

    d_GPE.append(
        [numpy.mean(r[1::4, :], axis=0),
         numpy.std(r[1::4, :], axis=0)])  # GPE
    d_GPE.append(
        [numpy.mean(r[2::4, :], axis=0),
         numpy.std(r[2::4, :], axis=0)])  # GPE down
    d_GPE.append(
        [numpy.mean(r[3::4, :], axis=0),
         numpy.std(r[3::4, :], axis=0)])  # GPE up

    return d, d_SNR, d_GPE
save_result_at = OUTPUT_PATH + '/main_mutual_information_prob.pkl'
if RUN is False:
    c_prob = []
    c_sum = []
    for i in sorted(list(count_dic.keys())):
        c_prob.append([])
        c_sum.append([])
        for j, hz in enumerate(sorted(list(count_dic[i].keys()))):
            c_prob[i].append([])
            c_sum[i].append([])
            for N in sorted(list(count_dic[i][hz].keys())):

                c = count_dic[i][hz][N][2::3, :]  # Pick out results for SNr
                c_conv = misc.convolve(c,
                                       bin_extent=100,
                                       kernel_type='rectangle')
                c_prob[i][j].append(
                    numpy.sum(c_conv < 1, axis=0) / float(c_conv.shape[0]))
                c_sum[i][j].append(numpy.sum(c, axis=0))

    c_prob = numpy.array(c_prob)
    c_sum = numpy.array(c_sum)

    misc.pickle_save([c_prob, c_sum, time], save_result_at)
else:
    c_prob, c_sum, time = misc.pickle_load(save_result_at)

from numpy import *
import pylab as p
#import matplotlib.axes3d as p3
def simluate(load, save_at, n_exp, synapse_models_mod, mod, res=100.):
    model_params = {
        'misc': {
            'N_MSN': N_MSN
        },
        'neurons': {
            'MSN_D1': {
                'n': N_MSN
            },
            'MSN_D2': {
                'n': N_MSN
            }
        }
    }
    params_msn_d1 = {
        'base_rates': [0.1],
        'base_times': [1],
        'mod_rates': [0.1, 20, 0.1],
        'mod_times': [1, 1500, 1500 + 500],
        'n_mod': mod
    }
    if not load:
        d = {}
        for model in synapse_models_mod:
            synapse_models = [model, 'GPE_SNR_gaba_p']
            spk_mean = []
            for i in range(n_exp):
                seed = i
                layer_dic = simulate_network(params_msn_d1,
                                             params_msn_d2,
                                             params_stn,
                                             synapse_models,
                                             sim_time=sim_time,
                                             seed=seed,
                                             I_e_add={},
                                             threads=4,
                                             start_rec=start_rec,
                                             model_params=model_params)

                layer_dic['SNR'].get_signal('s',
                                            start=start_rec,
                                            stop=sim_time)
                signal = layer_dic['SNR'].signals['spikes']
                spk_mean.append(
                    numpy.mean(signal.spike_histogram(time_bin=1,
                                                      normalized=True),
                               axis=0))

            d[model] = spk_mean

            misc.pickle_save(d, save_at)
    else:
        d = misc.pickle_load(save_at)

    d_SNR, d_GPE = [], []
    for r in d.values():
        r = numpy.array(r)
        r = misc.convolve(r, res, 'triangle', single=False)
        d_SNR.append(
            [numpy.mean(r[0::1, :], axis=0),
             numpy.std(r[0::1, :], axis=0)])  # SNR

    return d, d_SNR
Example #14
0
def simulate_hyperdirect(load,
                         N_MSN,
                         save_at,
                         type,
                         burst_time,
                         burst_rate,
                         n_exp,
                         res,
                         threads,
                         stn_syn='STN_SNR_ampa_s',
                         gpe_syn='GPE_SNR_gaba_p',
                         flag_bg=False):

    ra = random.random() * 200.
    start_rec = 950 + ra  #Hundred ms before burst
    delay = 10.0
    params_msn_d1 = {
        'base_rates': [0.1],
        'base_times': [1],
        'mod_rates': [],
        'mod_times': [],
        'n_mod': 0.,
        'bg_rate': 0
    }
    params_msn_d2 = {
        'base_rates': [0.1],
        'base_times': [1],
        'mod_rates': [],
        'mod_times': [],
        'n_mod': 0,
        'focus': False,
        'skip': 1,
        'bg_rate': 0
    }
    params_stn = {
        'rate': 219.,
        'mod': True,
        'mod_rate': burst_rate,
        'mod_times': [1000. + ra, 1000. + ra + burst_time]
    }
    synapse_models = ['MSN_SNR_gaba_p1', gpe_syn]

    model_params = {
        'misc': {
            'N_MSN': N_MSN
        },
        'conns': {
            'MSN_D2_GPE': {
                'lines': False
            },
            'STN_SNR': {
                'syn': stn_syn
            }
        },
        'neurons': {
            'MSN_D1': {
                'n': 0
            },
            'MSN_D2': {
                'n': 0
            }
        }
    }
    if type == 'normal':
        pass
    if type == 'no STN-GPE':
        model_params['conns'] = {'STN_GPE': {'lesion': True}}
    if type == 'no GPE-STN':
        model_params['conns'] = {'GPE_STN': {'lesion': True}}
    if type == 'no STN-SNR':
        model_params['conns'] = {'STN_SNR': {'lesion': True}}
    if type == 'no GPE-SNR':
        model_params['conns'] = {'GPE_SNR': {'lesion': True}}

    if flag_bg: save_at = save_at + '_bg'

    sim_time = 1300. + burst_time

    raw_r = []
    conv_r = []
    mean_conv_r = []
    std_conv_r = []
    inputs = []
    i = 0
    if not load:
        mr = []
        for i in range(n_exp):
            seed = i
            mr_tmp = simulate_hyperdirect_fun(params_msn_d1, params_msn_d2,
                                              params_stn, synapse_models, {},
                                              sim_time, seed, threads,
                                              start_rec, model_params, flag_bg)

            mr.append(mr_tmp)

        misc.pickle_save(mr, save_at)
    else:
        mr = misc.pickle_load(save_at)

    r_new = [[], [], []]
    for r in mr:
        r = numpy.array(r)
        for i in range(3):
            r_new[i].append(r[i::4, :])  #

    mr_new = []
    std_new = []
    for r in r_new:
        r = numpy.array(r)
        r = misc.convolve(r[:, 0, :], res, 'triangle', single=False)
        mr_new.append(numpy.mean(r, axis=0))
        std_new.append(numpy.std(r, axis=0))
    #print mr_new
    return mr_new, std_new
Example #15
0
    synapse_models = {
        'MSN': 'MSN_SNR_gaba_p1',
        'GPE': 'GPE_SNR_gaba_p',
        'STN': 'STN_SNR_ampa_s'
    }

    #times, spk_binned =_simulate_model([params_msn, params_gpe,params_gpe, 'SNR_izh',
    #                                   synapse_models, sim_time, 0])

    t = ttime.time()

    times, spk_binned = simulate_model(params_msn,
                                       params_gpe,
                                       params_stn,
                                       'SNR_izh',
                                       synapse_models,
                                       sim_time,
                                       n_exp=n_exp,
                                       threads=4)

    print 'Time:', ttime.time() - t
    spk_mean = numpy.sum(spk_binned, axis=0)
    #spk_std=numpy.std(spk_binned,axis=0)
    #pylab.plot(times, spk_mean*1000/n_exp)
    pylab.plot(
        times,
        misc.convolve(spk_mean, 50, 'triangle', single=True)[0] * 1000 / n_exp,
        col)
pylab.ylim([0, 40])
pylab.show()
Example #16
0
def simulate_direct(load, N_MSN, save_at, threads, points=[550, 650, 950]):

    params_msn_d1 = {
        'base_rates': [0.1],
        'base_times': [1],
        'mod_rates': [0.1, 20, 0.1],
        'mod_times': [1, 1000, 1000 + 500],
        'n_mod': 0
    }
    params_msn_d2 = {
        'base_rates': [0.1],
        'base_times': [1],
        'mod_rates': [0.1, 20, 0.1],
        'mod_times': [1, 1000, 1000 + 500],
        'n_mod': 0,
        'focus': False,
        'skip': 1
    }
    params_stn = {
        'rate': 300.,
        'mod': False,
        'mod_rate': 0.,
        'mod_times': [1000., 1000. + 500.]
    }

    model_params = {
        'neurons': {
            'MSN_D1': {
                'n': N_MSN
            },
            'MSN_D2': {
                'n': N_MSN
            }
        }
    }

    synapse_models = ['MSN_SNR_gaba_p1', 'GPE_SNR_gaba_p']

    sim_time = 2000.

    resolution = 2
    n_exp = 2

    burst_rate = numpy.linspace(15, 50, resolution)
    proportions = numpy.linspace(0.01, 0.07, resolution)  #arange(1,7,1)*150.
    mods = proportions * N_MSN

    pop_raw_rates = []
    pop_conv_rates = []
    mean_pop_conv_rates = []
    std_pop_conv_rates = []

    inputs = []
    i = 0
    if not load:
        for m in mods:
            for r in burst_rate:
                tmp_rates = []
                for e in range(n_exp):
                    seed = i

                    rates = simulate_network_direct_onoff_vs_rate(
                        m,
                        r,
                        params_msn_d1,
                        params_msn_d2,
                        params_stn,
                        synapse_models, {
                            'SNR': 280,
                            'STN': 0,
                            'GPE': 20
                        },
                        sim_time=sim_time,
                        seed=seed,
                        threads=threads,
                        start_rec=500.,
                        model_params=model_params)

                    tmp_rates.append(list(rates))

                    i += 1

                tmp_rates = numpy.array(tmp_rates)
                pop_raw_rates.append(tmp_rates)
                pop_conv_rates.append(
                    misc.convolve(tmp_rates, 100, 'rectangle', single=False))

                inputs.append((m, r))

                mean_pop_conv_rates.append(
                    numpy.mean(pop_conv_rates[-1], axis=0))
                std_pop_conv_rates.append(numpy.std(pop_conv_rates[-1],
                                                    axis=0))

                #                mean=mean_pop_conv_rates[-1]
                #                std=std_pop_conv_rates[-1]
                #
                #                for i in range(n_exp):
                #                    pylab.plot(pop_conv_rates[-1][i,:])
                #                pylab.plot(mean,'k')
                #                pylab.plot(mean-std,'--k')
                #                pylab.plot(mean+std,'--k')
                #                pylab.show()

                misc.pickle_save([
                    pop_raw_rates, pop_conv_rates, mean_pop_conv_rates,
                    std_pop_conv_rates, inputs
                ], save_result_at)
    else:
        pop_raw_rates, pop_conv_rates, mean_pop_conv_rates, std_pop_conv_rates, inputs = misc.pickle_load(
            save_result_at)

    data = {}
    for p in points:

        x = []
        y = []
        z_mean = []
        z_std = []
        for i, m, s in zip(inputs, mean_pop_conv_rates, std_pop_conv_rates):
            x.append(i[0])
            y.append(i[1])
            z_mean.append(m[p])
            z_std.append(s[p])

        data[p] = numpy.array([x, y, z_mean, z_std])

        spl = numpy.split(data[p], 2, axis=1)


#
#        for a in spl:
#            pylab.plot(a[1,:],a[2,:])
#            pylab.plot(a[1,:],a[2,:]+a[3,:],'--k')
#            pylab.plot(a[1,:],a[2,:]-a[3,:],'--k')
#
#    pylab.show()

    return data