Esempio n. 1
0
def test_model_definition():
    ''' Tests various ways of defining models.
    Note that this test only checks for whether the interface accepts what it
    is supposed to accept, not whether the Synapses class actually does what
    it is supposed to do... '''
    G = NeuronGroup(1, model='v:1', threshold=NoThreshold())
    
    # model, pre and post string
    syn = Synapses(G, model='w:1', pre='v+=w', post='v+=w')
    # list of pre codes
    syn = Synapses(G, model='w:1', pre=['v+=w', 'v+=1'])
    
    # an equation object
    model = SynapticEquations('w:1')
    syn = Synapses(G, model=model, pre='v+=w')
    
    ############################################################################
    # Some more complex examples from the docs
    ############################################################################
    
    # event-driven simulations
    
    model='''w:1
             dApre/dt=-Apre/taupre : 1 (event-driven)
             dApost/dt=-Apost/taupost : 1 (event-driven)'''
    syn = Synapses(G, model=model)
    
    model ='''w : 1
              p : 1'''
    syn = Synapses(G, model=model, pre="v+=w*(rand()<p)")
    
    syn = Synapses(G,
                   model='''x : 1
                            u : 1
                            w : 1''',
                    pre='''u=U+(u-U)*exp(-(t-lastupdate)/tauf)
                           x=1+(x-1)*exp(-(t-lastupdate)/taud)
                           i+=w*u*x
                           x*=(1-u)
                           u+=U*(1-u)''')
    
    # lumped variables
    a = 1 / (10 * ms)
    b = 1 / (20 * ms)
    c = 1 / (30 * ms)
    neurons = NeuronGroup(1, model="""dv/dt=(gtot-v)/(10*ms) : 1
                                  gtot : 1""")
    S=Synapses(neurons,
               model='''dg/dt=-a*g+b*x*(1-g) : 1
                    dx/dt=-c*x : 1
                    w : 1 # synaptic weight
                 ''',
                 pre='x+=w')    
    neurons.gtot = S.g
    
    v0 = 0
    tau = 5 * ms
    neurons = NeuronGroup(1, model='''dv/dt=(v0-v+Igap)/tau : 1
                                      Igap : 1''')
    S=Synapses(neurons, model='''w:1 # gap junction conductance
                                 Igap=w*(v_pre-v_post): 1''')
    neurons.Igap = S.Igap

    # static equations in synaptic model
    V_L = -70 * mV
    C_m = 0.5 * nF
    g_m = 25 * nS
    V_E1 = 0 * mV
    V_E2 = -20 * mV
    g_1 = 0.1 * nS
    g_2 = 0.2 * nS
    tau1 = 5 * ms
    tau2 = 50 * ms
    neurons = NeuronGroup(1, model='''dV/dt = (-1/C_m)*((g_m)*(V-V_L) + I_tot) : volt
                                      I_tot : amp''', reset=-55*mV, threshold=-50*mV)
    S=Synapses(neurons, model='''I_tot = I_1 + I_2 : amp
                                 I_1 = sI_1*g_1*(V_post-V_E1) : amp
                                 dsI_1/dt = -sI_1 / tau1 : 1
                                 I_2 = sI_2*g_2*(V_post-V_E2) : amp
                                 dsI_2/dt = -sI_2 / tau1 : 1
                              ''', pre='sI_1 += 1; sI_2 += 1')
    S[:, :] = True
    neurons.I_tot = S.I_tot
Esempio n. 2
0
def test_model_definition():
    ''' Tests various ways of defining models.
    Note that this test only checks for whether the interface accepts what it
    is supposed to accept, not whether the Synapses class actually does what
    it is supposed to do... '''
    G = NeuronGroup(1, model='v:1', threshold=NoThreshold())

    # model, pre and post string
    syn = Synapses(G, model='w:1', pre='v+=w', post='v+=w')
    # list of pre codes
    syn = Synapses(G, model='w:1', pre=['v+=w', 'v+=1'])

    # an equation object
    model = SynapticEquations('w:1')
    syn = Synapses(G, model=model, pre='v+=w')

    ############################################################################
    # Some more complex examples from the docs
    ############################################################################

    # event-driven simulations

    model = '''w:1
             dApre/dt=-Apre/taupre : 1 (event-driven)
             dApost/dt=-Apost/taupost : 1 (event-driven)'''
    syn = Synapses(G, model=model)

    model = '''w : 1
              p : 1'''
    syn = Synapses(G, model=model, pre="v+=w*(rand()<p)")

    syn = Synapses(G,
                   model='''x : 1
                            u : 1
                            w : 1''',
                   pre='''u=U+(u-U)*exp(-(t-lastupdate)/tauf)
                           x=1+(x-1)*exp(-(t-lastupdate)/taud)
                           i+=w*u*x
                           x*=(1-u)
                           u+=U*(1-u)''')

    # lumped variables
    a = 1 / (10 * ms)
    b = 1 / (20 * ms)
    c = 1 / (30 * ms)
    neurons = NeuronGroup(1,
                          model="""dv/dt=(gtot-v)/(10*ms) : 1
                                  gtot : 1""")
    S = Synapses(neurons,
                 model='''dg/dt=-a*g+b*x*(1-g) : 1
                    dx/dt=-c*x : 1
                    w : 1 # synaptic weight
                 ''',
                 pre='x+=w')
    neurons.gtot = S.g

    v0 = 0
    tau = 5 * ms
    neurons = NeuronGroup(1,
                          model='''dv/dt=(v0-v+Igap)/tau : 1
                                      Igap : 1''')
    S = Synapses(neurons,
                 model='''w:1 # gap junction conductance
                                 Igap=w*(v_pre-v_post): 1''')
    neurons.Igap = S.Igap

    # static equations in synaptic model
    V_L = -70 * mV
    C_m = 0.5 * nF
    g_m = 25 * nS
    V_E1 = 0 * mV
    V_E2 = -20 * mV
    g_1 = 0.1 * nS
    g_2 = 0.2 * nS
    tau1 = 5 * ms
    tau2 = 50 * ms
    neurons = NeuronGroup(
        1,
        model='''dV/dt = (-1/C_m)*((g_m)*(V-V_L) + I_tot) : volt
                                      I_tot : amp''',
        reset=-55 * mV,
        threshold=-50 * mV)
    S = Synapses(neurons,
                 model='''I_tot = I_1 + I_2 : amp
                                 I_1 = sI_1*g_1*(V_post-V_E1) : amp
                                 dsI_1/dt = -sI_1 / tau1 : 1
                                 I_2 = sI_2*g_2*(V_post-V_E2) : amp
                                 dsI_2/dt = -sI_2 / tau1 : 1
                              ''',
                 pre='sI_1 += 1; sI_2 += 1')
    S[:, :] = True
    neurons.I_tot = S.I_tot