Beispiel #1
0
def estimate_kb(cell_params_lif):
    cell_para = copy.deepcopy(cell_params_lif)
    random.seed(0)
    p.setup(timestep=1.0, min_delay=1.0, max_delay=16.0)
    run_s = 10.
    runtime = 1000. * run_s
    max_rate = 1000.
    ee_connector = p.OneToOneConnector(weights=1.0, delays=2.0)

    pop_list = []
    pop_output = []
    pop_source = []
    x = np.arange(0., 1.01, 0.1)
    count = 0
    trail = 10

    for i in x:
        for j in range(trail):  #trails for average
            pop_output.append(p.Population(1, p.IF_curr_exp, cell_para))
            poisson_spikes = mu.poisson_generator(i * max_rate, 0, runtime)
            pop_source.append(
                p.Population(1, p.SpikeSourceArray,
                             {'spike_times': poisson_spikes}))
            p.Projection(pop_source[count],
                         pop_output[count],
                         ee_connector,
                         target='excitatory')
            pop_output[count].record()
            count += 1

    count = 0
    for i in x:
        cell_para['i_offset'] = i
        pop_list.append(p.Population(1, p.IF_curr_exp, cell_para))
        pop_list[count].record()
        count += 1
    pop_list[count - 1].record_v()

    p.run(runtime)

    rate_I = np.zeros(count)
    rate_P = np.zeros(count)
    rate_P_max = np.zeros(count)
    rate_P_min = np.ones(count) * 1000.
    for i in range(count):
        spikes = pop_list[i].getSpikes(compatible_output=True)
        rate_I[i] = len(spikes) / run_s
        for j in range(trail):
            spikes = pop_output[i * trail +
                                j].getSpikes(compatible_output=True)
            spike_num = len(spikes) / run_s
            rate_P[i] += spike_num
            if spike_num > rate_P_max[i]:
                rate_P_max[i] = spike_num
            if spike_num < rate_P_min[i]:
                rate_P_min[i] = spike_num
        rate_P[i] /= trail
    '''
    #plot_spikes(spikes, 'Current = 10. mA')
    plt.plot(x, rate_I, label='current',)
    plt.plot(x, rate_P, label='Poisson input')
    plt.fill_between(x, rate_P_min, rate_P_max, facecolor = 'green', alpha=0.3)
    '''
    x0 = np.where(rate_P > 1.)[0][0]
    x1 = 4
    k = (rate_P[x1] - rate_P[x0]) / (x[x1] - x[x0])
    '''
    plt.plot(x, k*(x-x[x0])+rate_P[x0], label='linear')
    plt.legend(loc='upper left', shadow=True)
    plt.grid('on')
    plt.show()
    '''
    p.end()
    return k, x[x0], rate_P[x0]
Beispiel #2
0
def estimate_kb(cell_params_lif):
    cell_para = copy.deepcopy(cell_params_lif)
    random.seed(0)
    p.setup(timestep=1.0, min_delay=1.0, max_delay=16.0)
    run_s = 10.
    runtime = 1000. * run_s
    max_rate = 1000.
    ee_connector = p.OneToOneConnector(weights=1.0, delays=2.0)    


    pop_list = []
    pop_output = []
    pop_source = []
    x = np.arange(0., 1.01, 0.1)
    count = 0
    trail = 10

    for i in x:
        for j in range(trail): #trails for average
            pop_output.append(p.Population(1, p.IF_curr_exp, cell_para))
            poisson_spikes = mu.poisson_generator(i*max_rate, 0, runtime)
            pop_source.append( p.Population(1, p.SpikeSourceArray, {'spike_times' : poisson_spikes}) )
            p.Projection(pop_source[count], pop_output[count], ee_connector, target='excitatory')
            pop_output[count].record()
            count += 1


    count = 0
    for i in x:
        cell_para['i_offset'] = i
        pop_list.append(p.Population(1, p.IF_curr_exp, cell_para))
        pop_list[count].record()
        count += 1
    pop_list[count-1].record_v()

    p.run(runtime)

    rate_I = np.zeros(count)
    rate_P = np.zeros(count)
    rate_P_max = np.zeros(count)
    rate_P_min = np.ones(count) * 1000.
    for i in range(count):
        spikes = pop_list[i].getSpikes(compatible_output=True)
        rate_I[i] = len(spikes)/run_s
        for j in range(trail):
            spikes = pop_output[i*trail+j].getSpikes(compatible_output=True)
            spike_num = len(spikes)/run_s
            rate_P[i] += spike_num
            if spike_num > rate_P_max[i]:
                rate_P_max[i] = spike_num
            if spike_num < rate_P_min[i]:
                rate_P_min[i] = spike_num
        rate_P[i] /= trail
    '''
    #plot_spikes(spikes, 'Current = 10. mA')
    plt.plot(x, rate_I, label='current',)
    plt.plot(x, rate_P, label='Poisson input')
    plt.fill_between(x, rate_P_min, rate_P_max, facecolor = 'green', alpha=0.3)
    '''
    x0 = np.where(rate_P>1.)[0][0]
    x1 = 4
    k = (rate_P[x1] - rate_P[x0])/(x[x1]-x[x0])
    '''
    plt.plot(x, k*(x-x[x0])+rate_P[x0], label='linear')
    plt.legend(loc='upper left', shadow=True)
    plt.grid('on')
    plt.show()
    '''
    p.end()
    return k, x[x0], rate_P[x0]