Exemplo n.º 1
0
 def compute_transfer(self, i_mean=(0.0,100.0, 10.0), i_std=(0.0,100.0, 10.0)):
     self.i_range=numpy.arange(*i_mean)
     self.std_range=numpy.arange(*i_std)
     self.rate=numpy.zeros((self.i_range.size,self.std_range.size))
     nest.sr('M_WARNING setverbosity')
     for n,i in enumerate(self.i_range):
         print "I= %s"%i
         for m,std in enumerate(self.std_range):
             self.rate[n,m]=self.output_rate(i,std)
Exemplo n.º 2
0
    def test_StackUnderFlow(self):
        """Stack underflow"""

        nest.ResetKernel()
        try:
            nest.sr('clear ;')
            self.fail('an error should have risen!')  # should not be reached
        except nest.NESTError:
            info = sys.exc_info()[1]
            if not "StackUnderflow" in info.__str__():
                self.fail('wrong error message')
        # another error has been thrown, this is wrong
        except:
            self.fail('wrong error has been thrown')
Exemplo n.º 3
0
    def test_StackUnderFlow(self):
        """Stack underflow"""

        nest.ResetKernel()
        try:
            nest.sr('clear ;')
            self.fail('an error should have risen!') # should not be reached
        except nest.NESTError:
            info = sys.exc_info()[1]
            if not "StackUnderflow" in info.__str__():
                self.fail('wrong error message')              
        # another error has been thrown, this is wrong
        except: 
          self.fail('wrong error has been thrown')  
Exemplo n.º 4
0
    def test_DivisionByZero(self):
        """Division by zero"""

        nest.ResetKernel()
        try:
            nest.sr('1 0 div')
            self.fail('an error should have risen!')  # should not be reached
        except nest.NESTError:
            info = sys.exc_info()[1]
            if not "DivisionByZero" in info.__str__():
                self.fail('wrong error message')              
        # another error has been thrown, this is wrong
        except: 
          self.fail('wrong error has been thrown')  
Exemplo n.º 5
0
    def test_DivisionByZero(self):
        """Division by zero"""

        nest.ResetKernel()
        try:
            nest.sr('1 0 div')
            self.fail('an error should have risen!')  # should not be reached
        except nest.NESTError:
            info = sys.exc_info()[1]
            if not "DivisionByZero" in info.__str__():
                self.fail('wrong error message')
        # another error has been thrown, this is wrong
        except:
            self.fail('wrong error has been thrown')
Exemplo n.º 6
0
    def test_Threads(self):
        """Multiple threads"""

        # Test if we have a thread-enabled NEST
        nest.sr("statusdict /have_pthreads get")
        if not nest.spp(): return

        nest.ResetKernel()
        self.assertEqual(nest.GetKernelStatus()['local_num_threads'],1)

        nest.SetKernelStatus({'local_num_threads':8})
        n=nest.Create('iaf_neuron',8)
        st = nest.GetStatus(n,'vp')
        st.sort()        
        self.assertEqual(st,[0, 1, 2, 3, 4, 5, 6, 7])
Exemplo n.º 7
0
    def test_Threads(self):
        """Multiple threads"""

        # Test if we have a thread-enabled NEST
        nest.sr("statusdict /have_pthreads get")
        if not nest.spp(): return

        nest.ResetKernel()
        self.assertEqual(nest.GetKernelStatus()['local_num_threads'], 1)

        nest.SetKernelStatus({'local_num_threads': 8})
        n = nest.Create('iaf_neuron', 8)
        st = nest.GetStatus(n, 'vp')
        st.sort()
        self.assertEqual(st, [0, 1, 2, 3, 4, 5, 6, 7])
Exemplo n.º 8
0
    def test_EventsVoltage(self):
        """Voltage Events"""

        nest.ResetKernel()

        nest.sr('20 setverbosity')
        n  = nest.Create('iaf_neuron')
        vm = nest.Create('voltmeter',1,{'withtime':True, 'interval':1.})        

        nest.Connect(vm,n)
        nest.SetKernelStatus({'print_time':False})
        nest.Simulate(10)

        d  = nest.GetStatus(vm,'events')[0]

        self.assertEqual(len(d['V_m']), 9)
Exemplo n.º 9
0
    def test_EventsVoltage(self):
        """Voltage Events"""

        nest.ResetKernel()

        nest.sr('20 setverbosity')
        n = nest.Create('iaf_neuron')
        vm = nest.Create('voltmeter', 1, {'withtime': True, 'interval': 1.})

        nest.Connect(vm, n)
        nest.SetKernelStatus({'print_time': False})
        nest.Simulate(10)

        d = nest.GetStatus(vm, 'events')[0]

        self.assertEqual(len(d['V_m']), 9)
Exemplo n.º 10
0
    def test_EventsSpikes(self):
        """Spike Events"""

        nest.ResetKernel()

        nest.sr('20 setverbosity')
        
        n  = nest.Create('iaf_neuron',1,{'I_e':1000.})        
        sd = nest.Create('spike_detector',1,{'withtime':True})        

        nest.Connect(n,sd)
        nest.SetKernelStatus({'print_time':False})
        nest.Simulate(1000)

        d  = nest.GetStatus(sd,'events')[0]

        self.assert_(len(d['times'])>0)
Exemplo n.º 11
0
    def test_EventsSpikes(self):
        """Spike Events"""

        nest.ResetKernel()

        nest.sr('20 setverbosity')

        n = nest.Create('iaf_neuron', 1, {'I_e': 1000.})
        sd = nest.Create('spike_detector', 1, {'withtime': True})

        nest.Connect(n, sd)
        nest.SetKernelStatus({'print_time': False})
        nest.Simulate(1000)

        d = nest.GetStatus(sd, 'events')[0]

        self.assert_(len(d['times']) > 0)
Exemplo n.º 12
0
    def test_ThreadsFindConnections(self):
        """FindConnections with threads"""

        # Test if we have a thread-enabled NEST
        nest.sr("statusdict /have_pthreads get")
        if not nest.spp(): return

        nest.ResetKernel()
        nest.SetKernelStatus({'local_num_threads':8})
        pre = nest.Create("iaf_neuron")
        post = nest.Create("iaf_neuron", 6)

        nest.DivergentConnect(pre, post)

        conn = nest.FindConnections(pre)
        targets = nest.GetStatus(conn, "target")
        
        self.assertEqual(targets, post)
Exemplo n.º 13
0
    def test_ThreadsFindConnections(self):
        """FindConnections with threads"""

        # Test if we have a thread-enabled NEST
        nest.sr("statusdict /have_pthreads get")
        if not nest.spp(): return

        nest.ResetKernel()
        nest.SetKernelStatus({'local_num_threads': 8})
        pre = nest.Create("iaf_neuron")
        post = nest.Create("iaf_neuron", 6)

        nest.DivergentConnect(pre, post)

        conn = nest.FindConnections(pre)
        targets = nest.GetStatus(conn, "target")

        self.assertEqual(targets, post)
Exemplo n.º 14
0
    def test_ThreadsGetEvents(self):
        """ Gathering events across threads """

        # Test if we have a thread-enabled NEST
        nest.sr("statusdict /have_pthreads get")
        if not nest.spp(): return

        threads = [1, 2, 4, 8]

        n_events_sd = []
        n_events_vm = []

        N = 128
        Simtime = 1000.

        for t in threads:

            nest.ResetKernel()
            nest.SetKernelStatus({'local_num_threads': t})

            n = nest.Create('iaf_psc_alpha', N,
                            {'I_e': 2000.})  # force a lot of spike events
            sd = nest.Create('spike_detector')
            vm = nest.Create('voltmeter')

            nest.ConvergentConnect(n, sd)
            nest.DivergentConnect(vm, n)

            nest.Simulate(Simtime)

            n_events_sd.append(nest.GetStatus(sd, 'n_events')[0])
            n_events_vm.append(nest.GetStatus(vm, 'n_events')[0])

        ref_vm = N * (Simtime - 1)
        ref_sd = n_events_sd[0]

        # could be done more elegantly with any(), ravel(),
        # but we dont want to be dependent on numpy et al
        [self.assertEqual(x, ref_vm) for x in n_events_vm]
        [self.assertEqual(x, ref_sd) for x in n_events_sd]
Exemplo n.º 15
0
    def test_ThreadsGetEvents(self):
        """ Gathering events across threads """

        # Test if we have a thread-enabled NEST
        nest.sr("statusdict /have_pthreads get")
        if not nest.spp(): return

        threads = [1,2,4,8]

        n_events_sd = []
        n_events_vm = []

        N       = 128
        Simtime = 1000.

        for t in threads:

            nest.ResetKernel()
            nest.SetKernelStatus({'local_num_threads': t})

            n  = nest.Create('iaf_psc_alpha', N, {'I_e':2000.}) # force a lot of spike events
            sd = nest.Create('spike_detector')
            vm = nest.Create('voltmeter')

            nest.ConvergentConnect(n,sd)
            nest.DivergentConnect(vm,n)

            nest.Simulate(Simtime)

            n_events_sd.append(nest.GetStatus(sd, 'n_events')[0])
            n_events_vm.append(nest.GetStatus(vm, 'n_events')[0])

        ref_vm = N*(Simtime-1)
        ref_sd = n_events_sd[0]

        # could be done more elegantly with any(), ravel(),
        # but we dont want to be dependent on numpy et al
        [ self.assertEqual(x,ref_vm) for x in n_events_vm]
        [ self.assertEqual(x,ref_sd) for x in n_events_sd]
Exemplo n.º 16
0
    def test_Count(self):
        """Object count"""

        nest.ResetKernel()
        nest.sr('clear')
        
        for i in range(100):
            nest.sps(i)

        nest.sr('count')
        self.assertEqual(nest.spp(), 100)

        for i in range(100):
            self.assertEqual(nest.spp(), (99-i))
        
        nest.sr('count')
        self.assertEqual(nest.spp(), 0)
Exemplo n.º 17
0
    def test_Count(self):
        """Object count"""

        nest.ResetKernel()
        nest.sr('clear')

        for i in range(100):
            nest.sps(i)

        nest.sr('count')
        self.assertEqual(nest.spp(), 100)

        for i in range(100):
            self.assertEqual(nest.spp(), (99 - i))

        nest.sr('count')
        self.assertEqual(nest.spp(), 0)
Exemplo n.º 18
0
This example is also shown in the article Eppler et al. (2009) PyNEST:
A convenient interface to the {NEST} simulator, Front. Neuroinform.
doi:10.3389/neuro.11.012.2008
'''

# First, we import all necessary modules for simulation, analysis and
# plotting. Additionally, we set the verbosity to suppress info
# messages

from scipy.optimize import bisect

import cynest as nest
import cynest.voltage_trace

nest.sr("M_WARNING setverbosity")
nest.ResetKernel()

# Second, the simulation parameters are assigned to variables.

t_sim = 25000.0    # how long we simulate
n_ex  = 16000      # size of the excitatory population
n_in  =  4000      # size of the inhibitory population
r_ex  =     5.0    # mean rate of the excitatory population
r_in  =    20.5    # initial rate of the inhibitory population
epsc  =    45.0    # peak amplitude of excitatory synaptic currents
ipsc  =   -45.0    # peak amplitude of inhibitory synaptic currents
d     =     1.0    # synaptic delay
lower =    15.0    # lower bound of the search interval
upper =    25.0    # upper bound of the search interval
prec  =     0.01   # how close need the excitatory rates be
Exemplo n.º 19
0
ll = (V0*mV  - mu) / (sigma)/sqrt(2)                        
interval = (ul-ll)/num_iterations                           
tmpsum = 0.0                                                
for cu in range(0,num_iterations+1):                        
  u = ll + cu * interval                                    
  f = exp(u**2)*(1+erf(u))                                  
  tmpsum += interval * sqrt(pi) * f                         
                                                            
r =  1. / (tref*ms + tau_m*ms * tmpsum)                       


########################################################################################
# Simulation section
nest.ResetKernel()

nest.sr('20 setverbosity')
neurondict = {'V_th':Vth, 'tau_m':tau_m, 'tau_syn_ex':tau_syn_ex,'tau_syn_in':tau_syn_in,  'C_m':Cm, 'E_L':V0, 't_ref':tref, 'V_m': V0, 'V_reset': V0}

if (mu*1000) < Vth:
    neurondict['V_m'] = mu*1000.
    
nest.SetDefaults('iaf_psc_alpha', neurondict)
n      = nest.Create('iaf_psc_alpha', n_neurons)
n_free = nest.Create('iaf_psc_alpha', 1 ,[{'V_th':999999.}]) # high threshold as we want free membrane potential
pg     = nest.Create('poisson_generator', len(rates), [ {'rate':float(rate_i)} for rate_i in rates]   )
vm     = nest.Create('voltmeter', 1,     [{'record_to':['memory'], 'withtime':True, 'withgid':True, 'interval':.1}])
sd     = nest.Create('spike_detector',1, [{'record_to':['memory'], 'withtime':True, 'withgid':True}])

for i, currentpg in enumerate(pg):
    nest.DivergentConnect([currentpg],n,weight=float(J[i]), delay=0.1)
    nest.Connect([currentpg],n_free,      {'weight':J[i]})
Exemplo n.º 20
0
This example is also shown in the article Eppler et al. (2009) PyNEST:
A convenient interface to the {NEST} simulator, Front. Neuroinform.
doi:10.3389/neuro.11.012.2008
'''

# First, we import all necessary modules for simulation, analysis and
# plotting. Additionally, we set the verbosity to suppress info
# messages

from scipy.optimize import bisect

import cynest as nest
import cynest.voltage_trace

nest.sr("M_WARNING setverbosity")
nest.ResetKernel()

# Second, the simulation parameters are assigned to variables.

t_sim = 25000.0  # how long we simulate
n_ex = 16000  # size of the excitatory population
n_in = 4000  # size of the inhibitory population
r_ex = 5.0  # mean rate of the excitatory population
r_in = 20.5  # initial rate of the inhibitory population
epsc = 45.0  # peak amplitude of excitatory synaptic currents
ipsc = -45.0  # peak amplitude of inhibitory synaptic currents
d = 1.0  # synaptic delay
lower = 15.0  # lower bound of the search interval
upper = 25.0  # upper bound of the search interval
prec = 0.01  # how close need the excitatory rates be