Esempio n. 1
0
def get_Izh_FS_component():
    """
    Load Fast spiking Izhikevich XML definition from file and parse into
    Abstraction Layer of Python API.
    """
    izhi_fs = al.Dynamics(
        name='IzhikevichFS',
        parameters=[
            al.Parameter('a', un.per_time),
            al.Parameter('b', un.conductance / (un.voltage**2)),
            al.Parameter('c', un.voltage),
            al.Parameter('k', un.conductance / un.voltage),
            al.Parameter('Vr', un.voltage),
            al.Parameter('Vt', un.voltage),
            al.Parameter('Vb', un.voltage),
            al.Parameter('Vpeak', un.voltage),
            al.Parameter('Cm', un.capacitance)
        ],
        analog_ports=[
            al.AnalogReducePort('iSyn', un.current, operator="+"),
            al.AnalogReducePort('iExt', un.current, operator="+"),
            al.AnalogSendPort('U', un.current),
            al.AnalogSendPort('V', un.voltage)
        ],
        event_ports=[al.EventSendPort("spikeOutput")],
        state_variables=[
            al.StateVariable('V', un.voltage),
            al.StateVariable('U', un.current)
        ],
        regimes=[
            al.Regime('dU/dt = a * (b * pow(V - Vb, 3) - U)',
                      'dV/dt = V_deriv',
                      transitions=[
                          al.On('V > Vpeak',
                                do=['V = c',
                                    al.OutputEvent('spikeOutput')],
                                to='subthreshold')
                      ],
                      name="subthreshold"),
            al.Regime('dU/dt = - U * a',
                      'dV/dt = V_deriv',
                      transitions=[al.On('V > Vb', to="subthreshold")],
                      name="subVb")
        ],
        aliases=[
            "V_deriv := (k * (V - Vr) * (V - Vt) - U + iExt + iSyn) / Cm"
        ])  # @IgnorePep8
    return izhi_fs
 def spiking_component_type_to_nineml(cls):
     """Return a 9ML ComponentClass describing the neuron model."""
     iaf = al.ComponentClass(
         name="iaf_tau",
         regimes=[
             al.Regime(
                 name="subthreshold_regime",
                 time_derivatives=["dv/dt = (v_rest - v)/tau_m + (i_offset + i_syn)/cm"],
                 transitions=al.On("v > v_thresh",
                                   do=["t_spike = t",
                                       "v = v_reset",
                                       al.OutputEvent('spike_output')],
                                   to="refractory_regime"),
             ),  
             al.Regime(
                 name="refractory_regime",
                 time_derivatives=["dv/dt = 0"],
                 transitions=[al.On("t >= t_spike + tau_refrac",
                                    to="subthreshold_regime")],
             )
         ],
         state_variables=[
             al.StateVariable('v'), #, dimension='[V]' # '[V]' should be an alias for [M][L]^2[T]^-3[I]^-1
             al.StateVariable('t_spike'), #, dimension='[T]'
         ],
         analog_ports=[al.AnalogSendPort("v"),
                       al.AnalogReducePort("i_syn", reduce_op="+"), ],
         event_ports=[al.EventSendPort('spike_output'), ],
         parameters=['cm', 'tau_refrac', 'tau_m', 'v_reset', 'v_rest', 'v_thresh', 'i_offset']  # add dimensions, or infer them from dimensions of variables
                                                                                                # in fact, we should be able to infer what are the parameters, without listing them
     )
     return iaf
Esempio n. 3
0
def create_leaky_integrate_and_fire():
    dyn = al.Dynamics(
        name='LeakyIntegrateAndFire',
        regimes=[
            al.Regime('dv/dt = (i_synaptic*R - v)/tau',
                      transitions=[al.On('v > v_threshold',
                                         do=[al.OutputEvent('spike_output'),
                                             al.StateAssignment(
                                                 'refractory_end',
                                                 't + refractory_period'),
                                             al.StateAssignment('v',
                                                                'v_reset')],
                                         to='refractory')],
                      name='subthreshold'),
            al.Regime(transitions=[al.On('t > refractory_end',
                                   to='subthreshold')],
                      name='refractory')],
        state_variables=[al.StateVariable('v', dimension=un.voltage),
                         al.StateVariable('refractory_end',
                                          dimension=un.time)],
        parameters=[al.Parameter('R', un.resistance),
                    al.Parameter('refractory_period', un.time),
                    al.Parameter('v_reset', un.voltage),
                    al.Parameter('v_threshold', un.voltage),
                    al.Parameter('tau', un.time)],
        analog_ports=[al.AnalogReducePort('i_synaptic', un.current,
                                          operator='+'),
                      al.AnalogSendPort('refractory_end', un.time),
                      al.AnalogSendPort('v', un.voltage)])

    return dyn
Esempio n. 4
0
def create_izhikevich():
    subthreshold_regime = al.Regime(
        name="subthreshold_regime",
        time_derivatives=[
            "dV/dt = alpha*V*V + beta*V + zeta - U + Isyn / C_m",
            "dU/dt = a*(b*V - U)",
        ],
        transitions=[
            al.On("V > theta",
                  do=["V = c", "U =  U+ d",
                      al.OutputEvent('spike')],
                  to='subthreshold_regime')
        ])

    ports = [
        al.AnalogSendPort("V", un.voltage),
        al.AnalogReducePort("Isyn", un.current, operator="+")
    ]

    parameters = [
        al.Parameter('theta', un.voltage),
        al.Parameter('a', un.per_time),
        al.Parameter('b', un.per_time),
        al.Parameter('c', un.voltage),
        al.Parameter('d', old_div(un.voltage, un.time)),
        al.Parameter('C_m', un.capacitance),
        al.Parameter('alpha', old_div(un.dimensionless,
                                      (un.voltage * un.time))),
        al.Parameter('beta', un.per_time),
        al.Parameter('zeta', old_div(un.voltage, un.time))
    ]

    state_variables = [
        al.StateVariable('V', un.voltage),
        al.StateVariable('U', old_div(un.voltage, un.time))
    ]

    c1 = al.Dynamics(name="Izhikevich",
                     parameters=parameters,
                     state_variables=state_variables,
                     regimes=[subthreshold_regime],
                     analog_ports=ports)
    return c1
Esempio n. 5
0
def create_hodgkin_huxley():
    """A Hodgkin-Huxley single neuron model.
    Written by Andrew Davison.
    See http://phobos.incf.ki.se/src_rst/
              examples/examples_al_python.html#example-hh
    """
    aliases = [
        "q10 := 3.0**((celsius - qfactor)/tendegrees)",  # temperature correction factor @IgnorePep8
        "m_alpha := m_alpha_A*(V-m_alpha_V0)/(exp(-(V-m_alpha_V0)/m_alpha_K) - 1.0)",  # @IgnorePep8
        "m_beta := m_beta_A*exp(-(V-m_beta_V0)/m_beta_K)",
        "mtau := 1.0/(q10*(m_alpha + m_beta))",
        "minf := m_alpha/(m_alpha + m_beta)",
        "h_alpha := h_alpha_A*exp(-(V-h_alpha_V0)/h_alpha_K)",
        "h_beta := h_beta_A/(exp(-(V-h_beta_V0)/h_beta_K) + 1.0)",
        "htau := 1.0/(q10*(h_alpha + h_beta))",
        "hinf := h_alpha/(h_alpha + h_beta)",
        "n_alpha := n_alpha_A*(V-n_alpha_V0)/(exp(-(V-n_alpha_V0)/n_alpha_K) - 1.0)",  # @IgnorePep8
        "n_beta := n_beta_A*exp(-(V-n_beta_V0)/n_beta_K)",
        "ntau := 1.0/(q10*(n_alpha + n_beta))",
        "ninf := n_alpha/(n_alpha + n_beta)",
        "gna := gnabar*m*m*m*h",
        "gk := gkbar*n*n*n*n",
        "ina := gna*(ena - V)",
        "ik := gk*(ek - V)",
        "il := gl*(el - V )"
    ]

    hh_regime = al.Regime("dn/dt = (ninf-n)/ntau",
                          "dm/dt = (minf-m)/mtau",
                          "dh/dt = (hinf-h)/htau",
                          "dV/dt = (ina + ik + il + isyn)/C",
                          transitions=al.On("V > v_threshold",
                                            do=al.SpikeOutputEvent()))

    state_variables = [
        al.StateVariable('V', un.voltage),
        al.StateVariable('m', un.dimensionless),
        al.StateVariable('n', un.dimensionless),
        al.StateVariable('h', un.dimensionless)
    ]

    # the rest are not "parameters" but aliases, assigned vars, state vars,
    # indep vars, analog_analog_ports, etc.
    parameters = [
        al.Parameter('el', un.voltage),
        al.Parameter('C', un.capacitance),
        al.Parameter('ek', un.voltage),
        al.Parameter('ena', un.voltage),
        al.Parameter('gkbar', un.conductance),
        al.Parameter('gnabar', un.conductance),
        al.Parameter('v_threshold', un.voltage),
        al.Parameter('gl', un.conductance),
        al.Parameter('celsius', un.temperature),
        al.Parameter('qfactor', un.temperature),
        al.Parameter('tendegrees', un.temperature),
        al.Parameter('m_alpha_A',
                     old_div(un.dimensionless, (un.time * un.voltage))),
        al.Parameter('m_alpha_V0', un.voltage),
        al.Parameter('m_alpha_K', un.voltage),
        al.Parameter('m_beta_A', old_div(un.dimensionless, un.time)),
        al.Parameter('m_beta_V0', un.voltage),
        al.Parameter('m_beta_K', un.voltage),
        al.Parameter('h_alpha_A', old_div(un.dimensionless, un.time)),
        al.Parameter('h_alpha_V0', un.voltage),
        al.Parameter('h_alpha_K', un.voltage),
        al.Parameter('h_beta_A', old_div(un.dimensionless, un.time)),
        al.Parameter('h_beta_V0', un.voltage),
        al.Parameter('h_beta_K', un.voltage),
        al.Parameter('n_alpha_A',
                     old_div(un.dimensionless, (un.time * un.voltage))),
        al.Parameter('n_alpha_V0', un.voltage),
        al.Parameter('n_alpha_K', un.voltage),
        al.Parameter('n_beta_A', old_div(un.dimensionless, un.time)),
        al.Parameter('n_beta_V0', un.voltage),
        al.Parameter('n_beta_K', un.voltage)
    ]

    analog_ports = [
        al.AnalogSendPort("V", un.voltage),
        al.AnalogReducePort("isyn", un.current, operator="+")
    ]

    dyn = al.Dynamics("HodgkinHuxley",
                      parameters=parameters,
                      state_variables=state_variables,
                      regimes=(hh_regime, ),
                      aliases=aliases,
                      analog_ports=analog_ports)
    return dyn
Esempio n. 6
0
def get_HH_component():
    """A Hodgkin-Huxley single neuron model.
    Written by Andrew Davison.
    See http://phobos.incf.ki.se/src_rst/
              examples/examples_al_python.html#example-hh
    """
    aliases = [
        "q10 := 3.0**((celsius - qfactor)/tendegrees)",  # temperature correction factor @IgnorePep8
        "alpha_m := alpha_m_A*(V-alpha_m_V0)/(exp(-(V-alpha_m_V0)/alpha_m_K) - 1.0)",  # @IgnorePep8
        "beta_m := beta_m_A*exp(-(V-beta_m_V0)/beta_m_K)",
        "mtau := 1.0/(q10*(alpha_m + beta_m))",
        "minf := alpha_m/(alpha_m + beta_m)",
        "alpha_h := alpha_h_A*exp(-(V-alpha_h_V0)/alpha_h_K)",
        "beta_h := beta_h_A/(exp(-(V-beta_h_V0)/beta_h_K) + 1.0)",
        "htau := 1.0/(q10*(alpha_h + beta_h))",
        "hinf := alpha_h/(alpha_h + beta_h)",
        "alpha_n := alpha_n_A*(V-alpha_n_V0)/(exp(-(V-alpha_n_V0)/alpha_n_K) - 1.0)",  # @IgnorePep8
        "beta_n := beta_n_A*exp(-(V-beta_n_V0)/beta_n_K)",
        "ntau := 1.0/(q10*(alpha_n + beta_n))",
        "ninf := alpha_n/(alpha_n + beta_n)",
        "gna := gnabar*m*m*m*h",
        "gk := gkbar*n*n*n*n",
        "ina := gna*(ena - V)",
        "ik := gk*(ek - V)",
        "il := gl*(el - V )"
    ]

    hh_regime = al.Regime("dn/dt = (ninf-n)/ntau",
                          "dm/dt = (minf-m)/mtau",
                          "dh/dt = (hinf-h)/htau",
                          "dV/dt = (ina + ik + il + Isyn)/C",
                          transitions=al.On("V > theta",
                                            do=al.SpikeOutputEvent()))

    state_variables = [
        al.StateVariable('V', un.voltage),
        al.StateVariable('m', un.dimensionless),
        al.StateVariable('n', un.dimensionless),
        al.StateVariable('h', un.dimensionless)
    ]

    # the rest are not "parameters" but aliases, assigned vars, state vars,
    # indep vars, analog_analog_ports, etc.
    parameters = [
        al.Parameter('el', un.voltage),
        al.Parameter('C', un.capacitance),
        al.Parameter('ek', un.voltage),
        al.Parameter('ena', un.voltage),
        al.Parameter('gkbar', un.conductance),
        al.Parameter('gnabar', un.conductance),
        al.Parameter('theta', un.voltage),
        al.Parameter('gl', un.conductance),
        al.Parameter('celsius', un.temperature),
        al.Parameter('qfactor', un.temperature),
        al.Parameter('tendegrees', un.temperature),
        al.Parameter('alpha_m_A', un.dimensionless / (un.time * un.voltage)),
        al.Parameter('alpha_m_V0', un.voltage),
        al.Parameter('alpha_m_K', un.voltage),
        al.Parameter('beta_m_A', un.dimensionless / un.time),
        al.Parameter('beta_m_V0', un.voltage),
        al.Parameter('beta_m_K', un.voltage),
        al.Parameter('alpha_h_A', un.dimensionless / un.time),
        al.Parameter('alpha_h_V0', un.voltage),
        al.Parameter('alpha_h_K', un.voltage),
        al.Parameter('beta_h_A', un.dimensionless / un.time),
        al.Parameter('beta_h_V0', un.voltage),
        al.Parameter('beta_h_K', un.voltage),
        al.Parameter('alpha_n_A', un.dimensionless / (un.time * un.voltage)),
        al.Parameter('alpha_n_V0', un.voltage),
        al.Parameter('alpha_n_K', un.voltage),
        al.Parameter('beta_n_A', un.dimensionless / un.time),
        al.Parameter('beta_n_V0', un.voltage),
        al.Parameter('beta_n_K', un.voltage)
    ]

    analog_ports = [
        al.AnalogSendPort("V", un.voltage),
        al.AnalogReducePort("Isyn", un.current, operator="+")
    ]

    c1 = al.Dynamics("HodgkinHuxley",
                     parameters=parameters,
                     state_variables=state_variables,
                     regimes=(hh_regime, ),
                     aliases=aliases,
                     analog_ports=analog_ports)
    return c1
Esempio n. 7
0
def get_aeIF_component():
    """
    Adaptive exponential integrate-and-fire neuron as described in
    A. Destexhe, J COmput Neurosci 27: 493--506 (2009)

    Author B. Kriener (Jan 2011)

    ## neuron model: aeIF

    ## variables:
    ## V: membrane potential
    ## w: adaptation variable

    ## parameters:
    ## C_m     # specific membrane capacitance [muF/cm**2]
    ## g_L     # leak conductance [mS/cm**2]
    ## E_L     # resting potential [mV]
    ## Delta   # steepness of exponential approach to threshold [mV]
    ## V_T     # spike threshold [mV]
    ## S       # membrane area [mum**2]
    ## trefractory # refractory time [ms]
    ## tspike  # spike time [ms]
    ## tau_w   # adaptation time constant
    ## a, b    # adaptation parameters [muS, nA]
    """
    aeIF = al.Dynamics(
        name="aeIF",
        parameters=[
            al.Parameter('C_m', un.capacitance),
            al.Parameter('g_L', un.conductance),
            al.Parameter('E_L', un.voltage),
            al.Parameter('Delta', un.voltage),
            al.Parameter('V_T', un.voltage),
            al.Parameter('S'),
            al.Parameter('trefractory', un.time),
            al.Parameter('tspike', un.time),
            al.Parameter('tau_w', un.time),
            al.Parameter('a', un.dimensionless / un.voltage),
            al.Parameter('b')
        ],
        state_variables=[
            al.StateVariable('V', un.voltage),
            al.StateVariable('w')
        ],
        regimes=[
            al.Regime(
                name="subthresholdregime",
                time_derivatives=[
                    "dV/dt = -g_L*(V-E_L)/C_m + Isyn/C_m + g_L*Delta*exp((V-V_T)/Delta-w/S)/C_m",  # @IgnorePep8
                    "dw/dt = (a*(V-E_L)-w)/tau_w",
                ],
                transitions=al.On(
                    "V > V_T",
                    do=["V = E_L", "w = w + b",
                        al.OutputEvent('spikeoutput')],
                    to="refractoryregime")),
            al.Regime(name="refractoryregime",
                      transitions=al.On("t>=tspike+trefractory",
                                        to="subthresholdregime"))
        ],
        analog_ports=[al.AnalogReducePort("Isyn", un.current, operator="+")])
    return aeIF
Esempio n. 8
0
                              ],
                              to="refractory"),
        ),
        al.Regime(
            name="refractory",
            transitions=[al.On("t > refractory_end", to="subthreshold")],
        )
    ],
    state_variables=[
        al.StateVariable('v', dimension=voltage),
        al.StateVariable('refractory_end', dimension=time)
    ],
    analog_ports=[
        al.AnalogSendPort("v", dimension=voltage),
        al.AnalogSendPort("refractory_end", dimension=time),
        al.AnalogReducePort("i_synaptic", operator="+", dimension=current)
    ],
    event_ports=[
        al.EventSendPort('spike_output'),
    ],
    parameters=[
        al.Parameter('tau', time),
        al.Parameter('v_threshold', voltage),
        al.Parameter('refractory_period', time),
        al.Parameter('v_reset', voltage),
        al.Parameter('R', resistance)
    ])

if __name__ == "__main__":
    import nineml
    filename = __file__[0].upper() + __file__[1:].replace(".py", ".xml")