Exemplo n.º 1
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
Exemplo n.º 2
0
def create_alpha():
    dyn = al.Dynamics(
        name="Alpha",
        aliases=["Isyn := A"],
        regimes=[
            al.Regime(
                name="default",
                time_derivatives=[
                    "dA/dt = (B - A)/tau",  # TGC 4/15 changed from "B - A/tau_syn" as dimensions didn't add up @IgnorePep8
                    "dB/dt = -B/tau"
                ],
                transitions=al.On('spike', do=["B = B + q"]))
        ],
        state_variables=[
            al.StateVariable('A', dimension=un.current),
            al.StateVariable('B', dimension=un.current),
        ],
        analog_ports=[
            al.AnalogSendPort("Isyn", dimension=un.current),
            al.AnalogSendPort("A", dimension=un.current),
            al.AnalogSendPort("B", dimension=un.current),
            al.AnalogReceivePort("q", dimension=un.current)
        ],
        parameters=[al.Parameter('tau', dimension=un.time)])
    return dyn
Exemplo n.º 3
0
def create_static():
    dyn = al.Dynamics(
        name="Static",
        aliases=["fixed_weight := weight"],
        regimes=[al.Regime(name="default")],
        analog_ports=[al.AnalogSendPort("fixed_weight", dimension=un.current)],
        parameters=[al.Parameter('weight', dimension=un.current)])
    return dyn
Exemplo n.º 4
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
Exemplo n.º 5
0
def create_stdp_guetig():
    dyn = al.Dynamics(
        name="StdpGuetig",
        parameters=[
            al.Parameter(name='tauLTP', dimension=un.time),
            al.Parameter(name='aLTD', dimension=un.dimensionless),
            al.Parameter(name='wmax', dimension=un.dimensionless),
            al.Parameter(name='muLTP', dimension=un.dimensionless),
            al.Parameter(name='tauLTD', dimension=un.time),
            al.Parameter(name='aLTP', dimension=un.dimensionless)
        ],
        analog_ports=[
            al.AnalogReceivePort(dimension=un.dimensionless, name="w"),
            al.AnalogSendPort(dimension=un.dimensionless, name="wsyn")
        ],
        event_ports=[al.EventReceivePort(name="incoming_spike")],
        state_variables=[
            al.StateVariable(name='tlast_post', dimension=un.time),
            al.StateVariable(name='tlast_pre', dimension=un.time),
            al.StateVariable(name='deltaw', dimension=un.dimensionless),
            al.StateVariable(name='interval', dimension=un.time),
            al.StateVariable(name='M', dimension=un.dimensionless),
            al.StateVariable(name='P', dimension=un.dimensionless),
            al.StateVariable(name='wsyn', dimension=un.dimensionless)
        ],
        regimes=[
            al.Regime(
                name="sole",
                al.On('incoming_spike',
                      target_regime="sole",
                      do=[
                          al.StateAssignment(
                              'tlast_post',
                              '((w >= 0) ? ( tlast_post ) : ( t ))'),
                          al.StateAssignment(
                              'tlast_pre',
                              '((w >= 0) ? ( t ) : ( tlast_pre ))'),
                          al.StateAssignment(
                              'deltaw', '((w >= 0) ? '
                              '( 0.0 ) : '
                              '( P*pow(wmax - wsyn, muLTP) * '
                              'exp(-interval/tauLTP) + deltaw ))'),
                          al.StateAssignment(
                              'interval', '((w >= 0) ? ( -t + tlast_post ) : '
                              '( t - tlast_pre ))'),
                          al.StateAssignment(
                              'M', '((w >= 0) ? ( M ) : '
                              '( M*exp((-t + tlast_post)/tauLTD) - aLTD ))'),
                          al.StateAssignment(
                              'P', '((w >= 0) ? '
                              '( P*exp((-t + tlast_pre)/tauLTP) + aLTP ) : '
                              '( P ))'),
                          al.StateAssignment(
                              'wsyn', '((w >= 0) ? ( deltaw + wsyn ) : '
                              '( wsyn ))')
                      ]))
        ])
    return dyn
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
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
Exemplo n.º 9
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
Exemplo n.º 10
0
        ),
        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")
    nineml.write(model, filename)
Exemplo n.º 11
0
"""

"""

import nineml.abstraction as al
from nineml.units import time

model = al.Dynamics(
    name="Tonic",
    regimes=[
        al.Regime(name="default",
                  transitions=al.On("t > t_next",
                                    do=[
                                        "t_next = t + interval",
                                        al.OutputEvent('spikeOutput')
                                    ]))
    ],
    event_ports=[al.EventSendPort('spikeOutput')],
    state_variables=[al.StateVariable('t_next', dimension=time)],
    parameters=[al.Parameter('interval', dimension=time)],
)

if __name__ == "__main__":
    import nineml
    filename = __file__[0].upper() + __file__[1:].replace(".py", ".xml")
    nineml.write(model, filename)
Exemplo n.º 12
0
"""

import nineml.abstraction as al
from nineml.units import per_time, time, ms, per_ms

model = al.Dynamics(
    name="Poisson",
    regimes=[
        al.Regime(
            name="default",
            transitions=al.
            On("t > t_next",
               do=[
                   "t_next = t + one_ms * random.exponential(thousand_per_millisecond / rate)",
                   al.OutputEvent('spikeOutput')
               ]))
    ],
    event_ports=[al.EventSendPort('spikeOutput')],
    state_variables=[al.StateVariable('t_next', dimension=time)],
    parameters=[al.Parameter('rate', dimension=per_time)],
    constants=[
        al.Constant('thousand_per_millisecond', value=1000.0, units=per_ms),
        al.Constant('one_ms', value=1.0, units=ms)
    ])

if __name__ == "__main__":
    import nineml
    filename = __file__[0].upper() + __file__[1:].replace(".py", ".xml")
    nineml.write(model, filename)
Exemplo n.º 13
0
model = al.Dynamics(
    name="Alpha",
    aliases=["i_synaptic := a"],
    regimes=[
        al.Regime(
            name="sole",
            time_derivatives=[
                "da/dt = (b - a)/tau",
                "db/dt = -b/tau"],
            transitions=al.On('spike',
                              do=["b = b + weight"]),
        )
    ],
    state_variables=[
        al.StateVariable('a', dimension=current),
        al.StateVariable('b', dimension=current),
    ],
    analog_ports=[al.AnalogSendPort("i_synaptic", dimension=current),
                  al.AnalogSendPort("a", dimension=current),
                  al.AnalogSendPort("b", dimension=current),
                  al.AnalogReceivePort("weight", dimension=current)],
    parameters=[al.Parameter('tau', dimension=time)]
)


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