Exemplo n.º 1
0
def generate_data(label):
    spikesTrain = []
    organisedData = {}
    for i in range(input_class):
        for j in range(input_len):
            neuid = (i, j)
            organisedData[neuid] = []
    for i in range(input_len):
        neuid = (label, i)
        organisedData[neuid].append(i * v_co)


#        if neuid not in organisedData:
#            organisedData[neuid]=[i*v_co]
#        else:
#            organisedData[neuid].append(i*v_co)
    for i in range(input_class):
        for j in range(input_len):
            neuid = (i, j)
            organisedData[neuid].sort()
            spikesTrain.append(organisedData[neuid])
    runTime = int(max(max(spikesTrain)))
    sim.setup(timestep=1)

    noise = sim.Population(input_size, sim.SpikeSourcePoisson(), label='noise')

    noise.record(['spikes'])  #noise

    sim.run(runTime)
    neonoise = noise.get_data(["spikes"])
    spikesnoise = neonoise.segments[0].spiketrains  #noise
    sim.end()
    for i in range(input_size):
        for noisespike in spikesnoise[i]:
            spikesTrain[i].append(noisespike)
            spikesTrain[i].sort()
    return spikesTrain
Exemplo n.º 2
0
import pyNN.brian as sim
import numpy as np 
import matplotlib.pyplot as plt

run_time = 500
no_run = 3

sim.setup()
Excinp = sim.Population(10, sim.SpikeSourcePoisson(rate = 20.0, start = 0, duration = run_time * no_run))
# cell_type_parameters = {'tau_refrac': 0.1, 'v_thresh': -50.0, 'tau_m': 20.0, 'tau_syn_E': 0.5, 'v_rest': -65.0,\
						# 'cm': 1.0, 'v_reset': -65.0, 'tau_syn_I': 0.5, 'i_offset': 0.0}
# print(sim.IF_curr_alpha.default_parameters)

# cell_type = sim.IF_cond_exp(**cell_type_parameters) # neuron type of population
Pexc = sim.Population(10, sim.EIF_cond_exp_isfa_ista(), label = "excitotary neurons")
# Pexc.set(tau_refrac = 0.1, v_thresh = -50.0, tau_m = 20.0, tau_syn_E = 0.5, v_rest = -65.0, \
# 		cm = 1.0, v_reset = -65, tau_syn_I = 0.5, i_offset = 0.0)
# Pexc.initialize(**cell_type_parameters)
# print Pexc.celltype.default_initial_values
# print Pexc.get('tau_m')
# syn = sim.StaticSynapse(weight = 0.05, delay = 0.5)
# depressing_synapse_ee = sim.TsodyksMarkramSynapse(weight = 0.05, delay = 0.2, U = 0.5, tau_rec = 800.0, tau_facil = 0.01)
facilitating_synapse_ee = sim.TsodyksMarkramSynapse(weight = 0.05, delay = 0.5, U = 0.04, tau_rec = 100.0, tau_facil = 1000)
connection = sim.Projection(Excinp, Pexc, sim.AllToAllConnector(), facilitating_synapse_ee, receptor_type = 'excitatory')


# E_E_connection = sim.Projection(Pexc, Pexc, sim.FixedProbabilityConnector(p_connect = 0.5), depressing_synapse_ee, receptor_type = 'excitatory')

Excinp.record('spikes')
# Excinp[1].record('v')
Pexc.record('spikes')
import pyNN.brian as sim
from pyNN.random import RandomDistribution, NumpyRNG
import numpy as np
import matplotlib.pyplot as plt

N_e = 75  # number of excitatory neurons
N_i = 25  # number of inhibitatory neurons
Exc_in = 32  # number of excitatory inputs
Inh_in = 32  # number of inhibitatory inputs
weight_ini = 0.16  # define the initial value of the input signal weight

run_time = 500  # define the simulation time per run

sim.setup()
# ==========generate OR read in the input spikes data=====================
Excinp = sim.Population(Exc_in, sim.SpikeSourcePoisson(rate=15))
Inhinp = sim.Population(Inh_in, sim.SpikeSourcePoisson(rate=15))

# ==========create neuron population=====================
# todo: the initail parameters of neurons might be modified
cell_type_parameters = {'tau_refrac': 0.1, 'v_thresh': -50.0, 'tau_m': 20.0, 'tau_syn_E': 0.5, 'v_rest': -65.0,\
      'cm': 1.0, 'v_reset': -65.0, 'tau_syn_I': 0.5, 'i_offset': 0.0}
# print(sim.IF_curr_alpha.default_parameters)

cell_type = sim.IF_cond_exp(**
                            cell_type_parameters)  # neuron type of population
Pexc = sim.Population(
    N_e, cell_type, label="excitotary neurons")  # excitatory neuron population
Pinh = sim.Population(
    N_i, cell_type,
    label="inhibitatory neurons")  # inhibitoty neuron population
p[0, 2, 4].set(tau_m=10)
print(p.get('tau_m'))
print(p[0].tau_m)

#random value
from pyNN.random import RandomDistribution, NumpyRNG
gbar_na_distr = RandomDistribution('normal', (20.0, 2.0),
                                   rng=NumpyRNG(seed=85524))
p = sim.Population(7, sim.HH_cond_exp(gbar_Na=gbar_na_distr))
print(p.get('gbar_Na'))
print(p[0].gbar_Na)

#setting from an array
import numpy as np
p = sim.Population(6,
                   sim.SpikeSourcePoisson(rate=np.linspace(10.0, 20.0, num=6)))
print(p.get('rate'))

#using function to calculate
from numpy import sin, pi
p = sim.Population(8, sim.IF_cond_exp(i_offset=lambda i: sin(i * pi / 8)))
print(p.get('i_offset'))

#Setting parameters as a function of spatial position
from pyNN.space import Grid2D
grid = Grid2D(dx=10.0, dy=10.0)
p = sim.Population(16, sim.IF_cond_alpha(), structure=grid)


def f_v_thresh(pos):
    x, y, z = pos.T
Exemplo n.º 5
0
import pyNN.brian as sim  # can of course replace `neuron` with `nest`, `brian`, etc.
import matplotlib.pyplot as plt
import numpy as np

sim.setup(timestep=0.01)
p_in = sim.Population(10, sim.SpikeSourcePoisson(rate=10.0), label="input")
p_out = sim.Population(10, sim.EIF_cond_exp_isfa_ista(), label="AdExp neurons")

syn = sim.StaticSynapse(weight=0.05)
random = sim.FixedProbabilityConnector(p_connect=0.5)
connections = sim.Projection(p_in,
                             p_out,
                             random,
                             syn,
                             receptor_type='excitatory')

p_in.record('spikes')
p_out.record('spikes')  # record spikes from all neurons
p_out[0:2].record(['v', 'w', 'gsyn_exc'
                   ])  # record other variables from first two neurons

for i in range(2):
    sim.run(500.0)
    spikes_in = p_in.get_data()
    data_out = p_out.get_data()
    sim.reset()
    connections.set(weight=0.05)

sim.end()
print 'finish simulation'
Exemplo n.º 6
0
eta = 0.5  # learning rate
iter_no = 5  # learning iteration
source_rate = [20, 40]

w1_1 = 0.1
w1_2 = 0.1
w2_1 = 0.1
w2_2 = 0.1

# set up the classifier network
for i in range(len(training_label)):
    # for i in range(1):
    lg.info('iteration number %d' % i)
    sim.setup()
    In_1 = sim.Population(
        10, sim.SpikeSourcePoisson(rate=source_rate[training_label[i]]))
    In_2 = sim.Population(
        10, sim.SpikeSourcePoisson(rate=source_rate[1 - training_label[i]]))
    In = In_1 + In_2

    Out_1 = sim.Population(10, sim.IF_cond_exp())
    Out_2 = sim.Population(10, sim.IF_cond_exp())

    Out = Out_1 + Out_2

    syn_1_1 = sim.StaticSynapse(weight=w1_1, delay=0.5)
    syn_1_2 = sim.StaticSynapse(weight=w1_2, delay=0.5)
    syn_2_1 = sim.StaticSynapse(weight=w2_1, delay=0.5)
    syn_2_2 = sim.StaticSynapse(weight=w2_2, delay=0.5)
    prj_1_1 = sim.Projection(In_1,
                             Out_1,
Exemplo n.º 7
0
import pyNN.brian as sim
import numpy as np
import matplotlib.pyplot as plt

sim.setup()
Excinp = sim.Population(
    10, sim.SpikeSourcePoisson(rate=20.0, start=0, duration=500))
# cell_type_parameters = {'tau_refrac': 0.1, 'v_thresh': -50.0, 'tau_m': 20.0, 'tau_syn_E': 0.5, 'v_rest': -65.0,\
# 'cm': 1.0, 'v_reset': -65.0, 'tau_syn_I': 0.5, 'i_offset': 0.0}
# print(sim.IF_curr_alpha.default_parameters)

# cell_type = sim.IF_cond_exp(**cell_type_parameters) # neuron type of population
Pexc = sim.Population(10,
                      sim.EIF_cond_exp_isfa_ista(),
                      label="excitotary neurons")
# Pexc.set(tau_refrac = 0.1, v_thresh = -50.0, tau_m = 20.0, tau_syn_E = 0.5, v_rest = -65.0, \
# 		cm = 1.0, v_reset = -65, tau_syn_I = 0.5, i_offset = 0.0)
# Pexc.initialize(**cell_type_parameters)
# print Pexc.celltype.default_initial_values
# print Pexc.get('tau_m')
# syn = sim.StaticSynapse(weight = 0.05, delay = 0.5)
# depressing_synapse_ee = sim.TsodyksMarkramSynapse(weight = 0.05, delay = 0.2, U = 0.5, tau_rec = 800.0, tau_facil = 0.01)
facilitating_synapse_ee = sim.TsodyksMarkramSynapse(weight=0.05,
                                                    delay=0.5,
                                                    U=0.04,
                                                    tau_rec=100.0,
                                                    tau_facil=1000)
connection = sim.Projection(Excinp,
                            Pexc,
                            sim.AllToAllConnector(),
                            facilitating_synapse_ee,
import pyNN.brian as sim
import numpy as np
training_data = np.loadtxt('training_data_0_1.txt', delimiter=',')
training_label = training_data[:, -1]
training_rate = training_data[:, 0:64]
# print training_rate[1, :]
inputpop = []
sim.setup()
for i in range(np.size(training_rate, 1)):
    inputpop.append(
        sim.Population(1, sim.SpikeSourcePoisson(rate=abs(training_rate[0,
                                                                        i]))))

# print inputpop[0].get('rate')
# inputpop[0].set(rate = 8)
# print inputpop[0].get('rate')

pop = sim.Population(1, sim.IF_cond_exp(), label='exc')

prj1 = sim.Projection(inputpop[0],
                      pop,
                      sim.OneToOneConnector(),
                      synapse_type=sim.StaticSynapse(weight=0.04, delay=0.5),
                      receptor_type='inhibitory')
print prj1.get('weight', format='list')