def __init__(self, sheet, parameters):
        DirectStimulator.__init__(self, sheet,parameters)
        
        exc_syn = self.sheet.sim.StaticSynapse(weight=self.parameters.exc_weight)
        inh_syn = self.sheet.sim.StaticSynapse(weight=self.parameters.inh_weight)
        
        if not self.sheet.parameters.mpi_safe:
            from pyNN.nest import native_cell_type        
            if (self.parameters.exc_firing_rate != 0 or self.parameters.exc_weight != 0):
                self.np_exc = self.sheet.sim.Population(1, native_cell_type("poisson_generator"),{'rate': 0})
                self.sheet.sim.Projection(self.np_exc, self.sheet.pop,self.sheet.sim.AllToAllConnector(),synapse_type=exc_syn,receptor_type='excitatory')

            if (self.parameters.inh_firing_rate != 0 or self.parameters.inh_weight != 0):
                self.np_inh = self.sheet.sim.Population(1, native_cell_type("poisson_generator"),{'rate': 0})
                self.sheet.sim.Projection(self.np_inh, self.sheet.pop,self.sheet.sim.AllToAllConnector(),synapse_type=inh_syn,receptor_type='inhibitory')
        
        else:
            if (self.parameters.exc_firing_rate != 0 or self.parameters.exc_weight != 0):
                        self.ssae = self.sheet.sim.Population(self.sheet.pop.size,self.sheet.sim.SpikeSourceArray())
                        seeds=mozaik.get_seeds((self.sheet.pop.size,))
                        self.stgene = [stgen.StGen(rng=numpy.random.RandomState(seed=seeds[i])) for i in numpy.nonzero(self.sheet.pop._mask_local)[0]]
                        self.sheet.sim.Projection(self.ssae, self.sheet.pop,self.sheet.sim.OneToOneConnector(),synapse_type=exc_syn,receptor_type='excitatory')

            if (self.parameters.inh_firing_rate != 0 or self.parameters.inh_weight != 0):
                        self.ssai = self.sheet.sim.Population(self.sheet.pop.size,self.sheet.sim.SpikeSourceArray())
                        seeds=mozaik.get_seeds((self.sheet.pop.size,))
                        self.stgeni = [stgen.StGen(rng=numpy.random.RandomState(seed=seeds[i])) for i in numpy.nonzero(self.sheet.pop._mask_local)[0]]
                        self.sheet.sim.Projection(self.ssai, self.sheet.pop,self.sheet.sim.OneToOneConnector(),synapse_type=inh_syn,receptor_type='inhibitory')
Beispiel #2
0
    def setup_background_noise(self):
        from pyNN.nest import native_cell_type
        if (self.parameters.background_noise.exc_firing_rate != 0) or (self.parameters.background_noise.exc_firing_rate != 0):
            np_exc = self.sim.Population(1, native_cell_type("poisson_generator"), {'rate' : self.parameters.background_noise.exc_firing_rate})
            prj = self.sim.Projection(np_exc, self.pop, self.sim.AllToAllConnector(weights=self.parameters.background_noise.exc_weight),target='excitatory')

        if (self.parameters.background_noise.inh_firing_rate != 0) or (self.parameters.background_noise.inh_firing_rate != 0):
            np_inh = self.sim.Population(1, native_cell_type("poisson_generator"), {'rate' : self.parameters.background_noise.inh_firing_rate})
            prj = self.sim.Projection(np_inh, self.pop, self.sim.AllToAllConnector(weights=self.parameters.background_noise.inh_weight),target='inhibitory')
Beispiel #3
0
 def __init__(self, cell_params, col_params):
   global seed    
   self.exc = sim.Population(col_params['EI_ratio']*col_params['size'],sim.native_cell_type("aeif_beuler"), cell_params)
   self.inh = sim.Population(col_params['size'], sim.native_cell_type("aeif_beuler"), cell_params)
   self.inh.set('b', 0.0)
   uniformDistr = sim.RandomDistribution('uniform', [cell_params['V_reset'],cell_params['V_th']], rng=sim.NumpyRNG(seed))
   seed += 1
   self.all.initialize('v',uniformDistr)
   self.w_E = col_params['wE']
   self.w_I = col_params['wI']
Beispiel #4
0
def load_cell_types(simulator_name):
    cell_type_dict = {}

    if simulator_name == "NEST":
        music_event_out_proxy = sim.native_cell_type('music_event_out_proxy')
        music_event_in_proxy = sim.native_cell_type('music_event_in_proxy')
        parrot_neuron_type = sim.native_cell_type('parrot_neuron')
        model_list = [music_event_out_proxy, music_event_in_proxy, parrot_neuron_type]
        for model in model_list:
            model.default_initial_values = {}
            model.default_parameters = {}
        cell_type_dict['out'] = {'Event': music_event_out_proxy}
        cell_type_dict['in'] = {'Event': music_event_in_proxy}
        cell_type_dict['parrot'] = parrot_neuron_type
    else:
        raise Exception("Implementation for {} not found"
                        .format(simulator_name))
    return cell_type_dict
Beispiel #5
0
def test_record_native_model():
    if not have_nest:
        raise SkipTest
    nest = pyNN.nest
    from pyNN.random import RandomDistribution

    init_logging(logfile=None, debug=True)

    nest.setup()

    parameters = {'tau_m': 17.0}
    n_cells = 10
    p1 = nest.Population(n_cells, nest.native_cell_type("ht_neuron")(**parameters))
    p1.initialize(V_m=-70.0, Theta=-50.0)
    p1.set(theta_eq=-51.5)
    #assert_arrays_equal(p1.get('theta_eq'), -51.5*numpy.ones((10,)))
    assert_equal(p1.get('theta_eq'), -51.5)
    print(p1.get('tau_m'))
    p1.set(tau_m=RandomDistribution('uniform', low=15.0, high=20.0))
    print(p1.get('tau_m'))

    current_source = nest.StepCurrentSource(times=[50.0, 110.0, 150.0, 210.0],
                                            amplitudes=[0.01, 0.02, -0.02, 0.01])
    p1.inject(current_source)

    p2 = nest.Population(1, nest.native_cell_type("poisson_generator")(rate=200.0))

    print("Setting up recording")
    p2.record('spikes')
    p1.record('V_m')

    connector = nest.AllToAllConnector()
    syn = nest.StaticSynapse(weight=0.001)

    prj_ampa = nest.Projection(p2, p1, connector, syn, receptor_type='AMPA')

    tstop = 250.0
    nest.run(tstop)

    vm = p1.get_data().segments[0].analogsignals[0]
    n_points = int(tstop / nest.get_time_step()) + 1
    assert_equal(vm.shape, (n_points, n_cells))
    assert vm.max() > 0.0  # should have some spikes
Beispiel #6
0
def test_ticket240():
    nest = pyNN.nest
    nest.setup(threads=4)
    parameters = {'Tau_m': 17.0}
    p1 = nest.Population(4, nest.IF_curr_exp())
    p2 = nest.Population(5, nest.native_cell_type("ht_neuron")(**parameters))
    conn = nest.AllToAllConnector()
    syn = nest.StaticSynapse(weight=1.0)
    prj = nest.Projection(p1, p2, conn, syn, receptor_type='AMPA') # This should be a nonstandard receptor type but I don't know of one to use.
    connections = prj.get(('weight',), format='list')
    assert len(connections) > 0
Beispiel #7
0
    def __init__(self, sim_time, n_spike_source, n_hidden_neurons, n_output_neurons, W_in, W_re, W_out):
        self.sim_time = sim_time
        self.n_spike_source = int(n_spike_source)
        self.n_hidden_neurons = int(n_hidden_neurons)
        self.n_output_neurons = int(n_output_neurons)
        self.mem_scale = 2**16                  ## new new new
        self.weight_scale = 2**15               ## new new new
        self.parameters = {
            'VBits': 32,
            'VdecBits': 32,
            'Vdec_sig': 0,
            'V_th': 2000 * self.mem_scale / 1000, ## new new new
            'wBits': 16,
            'wAccBits': 20,
            'wAccShift': 1,
            't_ref': 0.
        }
        self.cell_type = sim.native_cell_type('iaf_psc_delta_int')
        self.parameters_out = {
            u'E_L': 0.0,
            u'I_e': 1.0,  # 用这个参数来表示leaky, 1.0则表示没有leak
            u'V_reset': 0.0,
            u'V_th': 2000, # 10000,                 ## new new new
            u't_ref': 0.0,
        }
        self.cell_type_out = sim.native_cell_type('iaf_psc_delta_xxq')
        # network structure
        self.spike_source = None
        self.hidden_neurons = None
        self.output_neurons = None
        self.connection_in = None
        self.connection_hidden = None
        self.connection_out = None
        W_in = np.round(W_in * self.weight_scale) / 1000.
        W_re = np.round(W_re * self.weight_scale) / 1000.
        # print W_in

        self.hidden_spike_cnts = []

        self.connection_in_list, self.connection_hidden_list, self.connection_out_list = self.getListConnection(W_in, W_re, W_out)
        self.ready()
Beispiel #8
0
def test_record_native_model():
    nest = pyNN.nest
    from pyNN.random import RandomDistribution
    from pyNN.utility import init_logging

    init_logging(logfile=None, debug=True)
    
    nest.setup()
    
    parameters = {'Tau_m': 17.0}
    n_cells = 10
    p1 = nest.Population(n_cells, nest.native_cell_type("ht_neuron"), parameters)
    p1.initialize('V_m', -70.0)
    p1.initialize('Theta', -50.0)
    p1.set('Theta_eq', -51.5)
    assert_equal(p1.get('Theta_eq'), [-51.5]*10)
    print p1.get('Tau_m')
    p1.rset('Tau_m', RandomDistribution('uniform', [15.0, 20.0]))
    print p1.get('Tau_m')
    
    current_source = nest.StepCurrentSource({'times' : [50.0, 110.0, 150.0, 210.0],
                                            'amplitudes' : [0.01, 0.02, -0.02, 0.01]})
    p1.inject(current_source)
    
    p2 = nest.Population(1, nest.native_cell_type("poisson_generator"), {'rate': 200.0})
    
    print "Setting up recording"
    p2.record()
    p1._record('V_m')
    
    connector = nest.AllToAllConnector(weights=0.001)
    
    prj_ampa = nest.Projection(p2, p1, connector, target='AMPA')
    
    tstop = 250.0
    nest.run(tstop)
    
    n_points = int(tstop/nest.get_time_step()) + 1
    assert_equal(p1.recorders['V_m'].get().shape, (n_points*n_cells, 3))
    id, t, v = p1.recorders['V_m'].get().T
    assert v.max() > 0.0 # should have some spikes
Beispiel #9
0
 def stimulate_on_target(self, stimulus, idx):
   cres=0
   if (stimulus['type'] == 'Poisson_E' or stimulus['type'] == 'Poisson_EI'):
     self.ext_stim = sim.Population(stimulus['N_E'], sim.native_cell_type('poisson_generator'), {'rate': stimulus['rate_E'], 'stop' : float(stimulus['duration'])})
     #weight  = RandomDistribution('normal', (self.w_E, self.w_E/3), boundaries=(0, self.w_E*100), constrain='redraw', rng=rng)
      
   if stimulus["target"]=="E":
      N_target=self.Ne
      target_cells=self.get_exc_from_blocks(idx)
   if stimulus["target"]=="I":
      N_target=self.Ni
      target_cells=self.get_inh_from_blocks(idx)
   if stimulus["target"]=="EI":
      N_target=self.Ne+self.Ni
      target_cells=self.get_all_from_blocks(idx)
   conn    = MyConnector(numpy.repeat(stimulus['ee'],N_target), weights = stimulus['wE'], delays=self.timestep)
   prj     = sim.Projection(self.ext_stim, target_cells, conn, target='excitatory', rng=rng)	     	
   if self.graph==idx: self.conn_graph.make_stim_nodes(self.get_stim_idx(), conn.edg)
   self.mpi_print("-->o %d excitatory connections were established from external sources ..." %prj.size())
Beispiel #10
0
 def __init__(self, sim_time, n_spike_source, n_hidden_neurons, n_output_neurons, W_in, W_re, W_out):
     self.max_mem = 0.0
     self.sim_time = sim_time
     self.n_spike_source = int(n_spike_source)
     self.n_hidden_neurons = int(n_hidden_neurons)
     self.n_output_neurons = int(n_output_neurons)
     self.parameters = {
         u'E_L': 0.0,
         u'I_e': 1.0,  # 用这个参数来表示leaky, 1.0则表示没有leak
         u'V_reset': 0.0,
         u'V_th': 2000,
         u't_ref': 0.0,
     }
     self.cell_type = sim.native_cell_type('iaf_psc_delta')
     # network structure
     self.spike_source = None
     self.hidden_neurons = None
     self.output_neurons = None
     self.connection_in = None
     self.connection_hidden = None
     self.connection_out = None
     self.connection_in_list, self.connection_hidden_list, self.connection_out_list = self.getListConnection(W_in, W_re, W_out)
     self.ready()
import pyNN.nest as sim

sim.nest.Install("coronetmodule")
sim.setup()
sim.nest.SetKernelStatus({"dict_miss_is_error": False})

coronet_neuron = sim.native_cell_type("coronet_neuron")
p1 = sim.Population(10, coronet_neuron)
s1 = sim.Population(10, sim.SpikeSourcePoisson, {"rate": 20})
s2 = sim.Population(10, sim.SpikeSourcePoisson, {"rate": 20})
sim.Projection(s1, p1, sim.OneToOneConnector(weights=0.02), target="EX")
sim.Projection(s2, p1, sim.OneToOneConnector(weights=0.01), target="IN")

p1.initialize("V_m", -76.0)  # this works as expected

p1.record()
p1._record("V_m")  # ugly
sim.run(1000)
id, t, v = p1.recorders["V_m"].get().T  # ugly

import pylab as pl
import numpy as np

pl.figure()
sl = p1.getSpikes()
pl.plot(sl[:, 1], sl[:, 0], ".")
pl.figure()
id_is_0 = np.where(id == 0)
pl.plot(t[id_is_0], v[id_is_0])
pl.show()
def run_retina(params):
    """Run the retina using the specified parameters."""

    print "Setting up simulation"
    timer = Timer()
    timer.start()  # start timer on construction
    pyNN.setup(timestep=params['dt'], max_delay=params['syn_delay'], threads=params['threads'], rng_seeds=params['kernelseeds'])

    N = params['N']
    phr_ON = pyNN.Population((N, N), pyNN.native_cell_type('dc_generator')())
    phr_OFF = pyNN.Population((N, N), pyNN.native_cell_type('dc_generator')())
    noise_ON = pyNN.Population((N, N), pyNN.native_cell_type('noise_generator')(mean=0.0, std=params['noise_std']))
    noise_OFF = pyNN.Population((N, N), pyNN.native_cell_type('noise_generator')(mean=0.0, std=params['noise_std']))

    phr_ON.set(start=params['simtime']/4, stop=params['simtime']/4*3,
               amplitude=params['amplitude'] * params['snr'])
    phr_OFF.set(start=params['simtime']/4, stop=params['simtime']/4*3,
                amplitude=-params['amplitude'] * params['snr'])

    # target ON and OFF populations
    v_init = params['parameters_gc'].pop('Vinit')
    out_ON = pyNN.Population((N, N), pyNN.native_cell_type('iaf_cond_exp_sfa_rr')(**params['parameters_gc']))
    out_OFF = pyNN.Population((N, N), pyNN.native_cell_type('iaf_cond_exp_sfa_rr')(**params['parameters_gc']))
    out_ON.initialize(v=v_init)
    out_OFF.initialize(v=v_init)

    #print "Connecting the network"

    retina_proj_ON = pyNN.Projection(phr_ON, out_ON, pyNN.OneToOneConnector())
    retina_proj_ON.set(weight=params['weight'])
    retina_proj_OFF = pyNN.Projection(phr_OFF, out_OFF, pyNN.OneToOneConnector())
    retina_proj_OFF.set(weight=params['weight'])

    noise_proj_ON = pyNN.Projection(noise_ON, out_ON, pyNN.OneToOneConnector())
    noise_proj_ON.set(weight=params['weight'])
    noise_proj_OFF = pyNN.Projection(noise_OFF, out_OFF, pyNN.OneToOneConnector())
    noise_proj_OFF.set(weight=params['weight'])

    out_ON.record('spikes')
    out_OFF.record('spikes')

    # reads out time used for building
    buildCPUTime = timer.elapsedTime()

    print "Running simulation"

    timer.start()  # start timer on construction
    pyNN.run(params['simtime'])
    simCPUTime = timer.elapsedTime()

    out_ON_DATA = out_ON.get_data().segments[0]
    out_OFF_DATA = out_OFF.get_data().segments[0]

    print "\nRetina Network Simulation:"
    print(params['description'])
    print "Number of Neurons : ", N**2
    print "Output rate  (ON) : ", out_ON.mean_spike_count(), \
        "spikes/neuron in ", params['simtime'], "ms"
    print "Output rate (OFF) : ", out_OFF.mean_spike_count(), \
        "spikes/neuron in ", params['simtime'], "ms"
    print "Build time        : ", buildCPUTime, "s"
    print "Simulation time   : ", simCPUTime, "s"

    return out_ON_DATA, out_OFF_DATA
Beispiel #13
0
 def test_create_native(self):
     cell_type = sim.native_cell_type('iaf_neuron')
     p = sim.Population(3, cell_type())
Beispiel #14
0
 def make_stim_pop(self, stimulus):
    if (stimulus['type'] == 'Poisson_E'):
       self.ext_stim = sim.Population(stimulus['N_E'], sim.native_cell_type('poisson_generator'), {'rate': stimulus['rate_E'], 'stop' : float(stimulus['duration'])})
import pyNN.nest as sim
import matplotlib.pyplot as plt

if __name__ == '__main__':
    params = {
        'VBits': 32,
        'VdecBits': 32,
        'Vdec_sig': 2**30,
        'V_th': 10000000,
        'wBits': 16,
        'wAccBits': 20,
        'wAccShift': 10,
        't_ref': 0.
    }
    sim.setup(timestep=0.1)
    cell_type = sim.native_cell_type('iaf_psc_delta_int')
    neuron = cell_type(**params)
    n = sim.Population(1, cell_type(**params))
    s = sim.Population(1, sim.SpikeSourceArray())
    o = sim.Population(1, cell_type(**params))
    s[0].spike_times = [10, 15, 20, 30, 40]
    p = sim.Projection(s, n, sim.FromListConnector([(0, 0, 25, 0.01)]))
    p1 = sim.Projection(n, o, sim.FromListConnector([(0, 0, 25, 0.01)]))
    o.record('V_m')
    sim.initialize(n, V_m=0)
    sim.run(128.0)

    vtrace = o.get_data(clear=True).segments[0].filter(name='V_m')[0]
    print p.get(['weight'], format='array')

    plt.figure()
import pyNN.nest as sim
sim.nest.Install('coronetmodule')
sim.setup()
sim.nest.SetKernelStatus({'dict_miss_is_error': False})

iaf_4_cond_exp = sim.native_cell_type('iaf_4_cond_exp')
cell_params=\
{'C_m': 250.0,
 'E_L': -70.0,
 'E_syn_1': 0.0,
 'E_syn_2': 0.0,
 'E_syn_3': -85.0,
 'E_syn_4': 0.0,
 'I_e': 0.0,
 'V_reset': -60.0,
 'V_th': -55.0,
 'g_L': 16.6667,
 't_ref': 2.0,
 'tau_syn_1': 5.0,
 'tau_syn_2': 5.0,
 'tau_syn_3': 25.0,
 'tau_syn_4': 0.2}
p1 = sim.Population(10, iaf_4_cond_exp, cell_params)
s1 = sim.Population(10, sim.SpikeSourcePoisson, {'rate':20})
s2 = sim.Population(10, sim.SpikeSourcePoisson, {'rate':20})
s3 = sim.Population(10, sim.SpikeSourcePoisson, {'rate':20})
sim.Projection(s1, p1, sim.OneToOneConnector(weights=0.02), target="SYN_1")
sim.Projection(s2, p1, sim.OneToOneConnector(weights=0.01), target="SYN_2")
sim.Projection(s3, p1, sim.OneToOneConnector(weights=0.01), target="SYN_3")

print iaf_4_cond_exp.synapse_types
Beispiel #17
0
 def test_create_native(self):
     cell_type = sim.native_cell_type('iaf_neuron')
     p = sim.Population(3, cell_type())
Beispiel #18
0
#!/usr/bin/env python

import faulthandler
from music_wizard.pynn import XmlFactory, Factory
import music
import pyNN.nest as sim

sim.setup()
music_setup = music.Setup()
xml = music_setup.config('xml')

detector = sim.Population(1, sim.native_cell_type('spike_detector'), {})
population_dict={'detector': detector}
model_factory = Factory.PyNNProxyFactory(sim, music_setup, acc_latency=10.0)
connector_factory = Factory.PyNNConnectorFactory(sim)
proxy_factory = XmlFactory.ProxyFactory("app1", connector_factory, model_factory, population_dict)

with open(xml, 'r') as xml_stream:
    proxys = proxy_factory.create_proxys(xml_stream.read())

for i in xrange(20):
    sim.run(20.0)
    print nest.GetStatus(detector, 'events')

Beispiel #19
0
sim.setup(timestep=resolution, min_delay=1.0, threads=n_threads)

# Set population dimensions
n_neurons_e = 800;
n_neurons_i = 200;
n_neurons = n_neurons_e + n_neurons_i;

# Set synaptic weights
max_syn_weight_e = 0.0005  # max magnitude of excitatory synaptic weights
max_syn_weight_i = 0.001   # max magnitude of inhibitory synaptic weights


#----------- Build --------------
#--------------------------------
# Create Izhikevich cell type (based on native NEST model)
Izhikevich = sim.native_cell_type('izhikevich')

# Create excitatory neurons
r = np.random.rand(n_neurons_e)
c = -65.0 + 15.0 * r**2
d = 8.0 - 6.0 * r**2
population_e = sim.Population(n_neurons_e, Izhikevich,
                              cellparams={'a': 0.02,
                                          'b': 0.2})
population_e.tset('c', c)
population_e.tset('d', d)
population_e.initialize('V_m', -65.0)
population_e.initialize('U_m', 0.2*(-65.0))

# Create inhibitory neurons
r = np.random.rand(n_neurons_i)
Beispiel #20
0
import pyNN.nest as pynn

pynn.nest.Install('brainscales_hw_module')
pynn.nest.Install('hmf_hw_module')

iaf_4_cond_exp = pynn.native_cell_type('iaf_4_cond_exp')
aeif_4_cond_exp = pynn.native_cell_type('aeif_4_cond_exp')
# __author__ = 'xxq'

import matplotlib.pyplot as plt
import numpy as np
import pyNN.nest as sim

parameters = {
 u'E_L': 0.0,
 u'I_e': 0.9, # 用这个参数来表示leaky
 u'V_reset': 0.0,
 u'V_th': 0.5,
 u't_ref': .0,
}

sim.setup(timestep=01.0)
nt = sim.native_cell_type('iaf_psc_delta_xxq')
n = sim.Population(1, nt(**parameters))
s = sim.Population(1, sim.SpikeSourceArray())
s[0].spike_times = [10, 15, 20, 30, 40]
p = sim.Projection(s, n, sim.FromListConnector([(0, 0, 0.00025, 0.01)]))
# p1 = sim.Projection(n, n, sim.FromListConnector([(0, 0, 0.00025, 1.0)]))
n.record('V_m')
n.record('V_m')
sim.initialize(n, V_m=0.)
sim.run(128.0)

vtrace = n.get_data(clear=True).segments[0].filter(name='V_m')[0]
print p.get(['weight'], format='array')

plt.figure()
plt.plot(vtrace.times, vtrace, 'o')
Beispiel #22
0
 def test_create_native(self):
     cell_type = sim.native_cell_type('iaf_psc_alpha')
     p = sim.Population(3, cell_type())