The balanced random network model

From NEST

Jump to: navigation, search

[ Example networks ]

The following example implements a balanced random network (Brunel, 2000), using integrate and fire neurons with synaptic currents modeled as alpha functions.

This version uses numpy to generate the random connections. Pylab is used for the raster plot of the spike data.

The file can be found in the nest source directory under

pynest/examples

   #! /usr/bin/env python
   
   import nest
   import nest.raster_plot
   
   import numpy
   import time
   
   nest.ResetKernel()
   
   startbuild= time.time()
   
   dt=0.1       # the resolution in ms
   simtime=1000.0 # Simulation time in ms
   delay= 1.5     # the delay in ms
   
   # Parameters for asynchronous irregular firing
   g=5.0
   eta=2.0
   epsilon=0.1    # connection probability
   
   order=2500
   NE= 4*order
   NI= 1*order
   N_neurons= NE+NI
   N_rec = 50 # record from 50 neurons
   
   CE= epsilon*NE   # number of excitatory synapses per neuron
   CI= epsilon*NI   # number of inhibitory synapses per neuron  
   C_tot= int(CI+CE)  # total number of synapses per neuron
   
   # Initialize the parameters of the integrate and fire neuron
   tauSyn= 0.5
   tauMem=20.0
   theta = 20.0
   J=0.1
   
   fudge=0.41363506632638
   J_ex= J/tauSyn*fudge
   J_in= -g*J_ex
   
   nu_th= theta/(J*CE*tauMem)
   nu_ex= eta*nu_th
   p_rate= 1000.0*nu_ex*CE
   
   nest.SetStatus([0],[{"resolution": dt}])
   
   print "Building network"
   
   neuron_params= {"C_m"       : 1.0,
                   "tau_m"     : tauMem,
                   "tau_syn_ex": tauSyn,
                   "tau_syn_in": tauSyn,
                   "t_ref"     : 2.0,
                   "E_L"       : 0.0,
                   "V_th"      : theta}
   
   nest.SetModelStatus("iaf_psc_alpha", neuron_params)
   
   nodes_ex=nest.Create("iaf_psc_alpha",NE)
   nodes_in=nest.Create("iaf_psc_alpha",NI)
   
   nest.SetModelStatus("poisson_generator",{"rate": p_rate})
   noise=nest.Create("poisson_generator")
   
   espikes=nest.Create("spike_detector")
   ispikes=nest.Create("spike_detector")
   
   nest.SetStatus([espikes],[{"label": "brunel-py-ex",
                      "withgid": True,
                      "to_file": True}])
   
   nest.SetStatus([ispikes],[{"label": "brunel-py-in",
                      "withtime": True,
                      "withgid": True,
                      "to_file": True}])
   
   print "Connecting devices."
   
   nest.CopySynapseType("static_synapse","excitatory")
   nest.SetSynapseDefaults("excitatory",{"weight":J_ex, "delay":delay})
   
   nest.CopySynapseType("static_synapse","inhibitory")
   nest.SetSynapseDefaults("inhibitory",{"weight":J_in, "delay":delay})
    
   nest.SetSynapseContext("excitatory")
   nest.DivergentConnect(noise,nodes_ex)
   nest.DivergentConnect(noise,nodes_in)
   
   nest.ConvergentConnect(range(1,N_rec+1),espikes)
   nest.ConvergentConnect(range(NE+1,NE+1+N_rec),ispikes)
   
   print "Connecting network."
   
   # Here, we create the connections from the excitatory neurons to all other
   # neurons. We exploit that the neurons have consecutive IDs, running from
   # 1,...,NE           for the excitatory neurons and from
   # (NE+1),...,(NE+NI) for the inhibitory neurons.
   
   numpy.random.seed(1234)
   
   sources_ex = numpy.random.random_integers(1,NE,(N_neurons,CE))
   sources_in = numpy.random.random_integers(NE+1,N_neurons,(N_neurons,CI))
   
   # We now iterate over all neuron IDs, and connect the neuron to
   # the sources from our array. The first loop connects the excitatory neurons
   # and the second loop the inhibitory neurons.
   
   
   for n in xrange(N_neurons):
       nest.ConvergentConnect(list(sources_ex[n]),[n+1])
   
   nest.SetSynapseContext("inhibitory")
   
   for n in xrange(N_neurons):
       nest.ConvergentConnect(list(sources_in[n]),[n+1])
   
   endbuild=time.time()
   
   print "Simulating."
   
   nest.Simulate(simtime)
   
   endsimulate= time.time()
   
   events_ex= nest.GetStatus(espikes,"n_events")[0]
   rate_ex= events_ex/simtime*1000.0/N_rec
   events_in= nest.GetStatus(ispikes,"n_events")[0]
   rate_in= events_in/simtime*1000.0/N_rec
   
   num_synapses= nest.GetSynapseDefaults("excitatory")["num_connections"]+\
   nest.GetSynapseDefaults("inhibitory")["num_connections"]
   
   build_time= endbuild-startbuild
   sim_time  = endsimulate-endbuild
   
   print "Brunel network simulation (Python)"
   print "Number of neurons :", N_neurons
   print "Number of synapses:", num_synapses
   print "       Exitatory  :", int(CE*N_neurons)+N_neurons
   print "       Inhibitory :", int(CI*N_neurons)
   print "Excitatory rate   : %.2f Hz" % rate_ex
   print "Inhibitory rate   : %.2f Hz" % rate_in
   print "Building time     : %.2f s" % build_time
   print "Simulation time   : %.2f s" % sim_time
       
   nest.raster_plot.from_device(espikes)
Views
Personal tools