def simulate(self,
                current=input_factory.get_zero_current(),
                time=10 * b2.ms,
                rheo_threshold=None,
                v_rest=None,
                v_reset=None,
                delta_t=None,
                time_scale=None,
                resistance=None,
                threshold=None,
                adapt_volt_c=None,
                adapt_tau=None,
                adapt_incr=None):
       if (v_rest == None):
           v_rest = self.rest_pot
       if (v_reset == None):
           v_reset = self.reset_pot
       if (rheo_threshold == None):
           rheo_threshold = self.rheo_threshold
       if (delta_t == None):
           delta_t = self.delta_t
       if (time_scale == None):
           time_scale = self.time_scale
       if (resistance == None):
           resistance = self.resistance
       if (threshold == None):
           threshold = self.threshold
       if (adapt_volt_c == None):
           adapt_volt_c = self.adapt_volt_c
       if (adapt_tau == None):
           adapt_tau = self.adapt_tau
       if (adapt_incr == None):
           adapt_incr = self.adapt_incr
       v_spike_str = "v>{:f}*mvolt".format(threshold / b2.mvolt)
       eqs = """
 			dv/dt = (-(v-v_rest) +delta_t*exp((v-rheo_threshold)/delta_t)+ resistance * current(t,i) - resistance * w)/(time_scale) : volt
       	dw/dt=(adapt_volt_c*(v-v_rest)-w)/adapt_tau : amp
       	"""
       neuron = b2.NeuronGroup(1,
                               model=eqs,
                               threshold=v_spike_str,
                               reset="v=v_reset;w+=adapt_incr",
                               method="euler")
       neuron.v = v_rest
       neuron.w = 0.0 * b2.pA
       state_monitor = b2.StateMonitor(neuron, ["v", "w"], record=True)
       spike_monitor = b2.SpikeMonitor(neuron)
       b2.run(time)
       return state_monitor, spike_monitor
def simulate_exponential_IF_neuron(tau=MEMBRANE_TIME_SCALE_tau,
                                   R=MEMBRANE_RESISTANCE_R,
                                   v_rest=V_REST,
                                   v_reset=V_RESET,
                                   v_rheobase=RHEOBASE_THRESHOLD_v_rh,
                                   v_spike=FIRING_THRESHOLD_v_spike,
                                   delta_T=SHARPNESS_delta_T,
                                   I_stim=input_factory.get_zero_current(),
                                   simulation_time=200 * b2.ms):
    """
    Implements the dynamics of the exponential Integrate-and-fire model

    Args:
        tau (Quantity): Membrane time constant
        R (Quantity): Membrane resistance
        v_rest (Quantity): Resting potential
        v_reset (Quantity): Reset value (vm after spike)
        v_rheobase (Quantity): Rheobase threshold
        v_spike (Quantity) : voltage threshold for the spike condition
        delta_T (Quantity): Sharpness of the exponential term
        I_stim (TimedArray): Input current
        simulation_time (Quantity): Duration for which the model is simulated

    Returns:
        (voltage_monitor, spike_monitor):
        A b2.StateMonitor for the variable "v" and a b2.SpikeMonitor
    """

    eqs = """
    dv/dt = (-(v-v_rest) +delta_T*exp((v-v_rheobase)/delta_T)+ R * I_stim(t,i))/(tau) : volt
    """
    neuron = b2.NeuronGroup(1,
                            model=eqs,
                            reset="v=v_reset",
                            threshold="v>v_spike",
                            method="euler")
    neuron.v = v_rest
    # monitoring membrane potential of neuron and injecting current
    voltage_monitor = b2.StateMonitor(neuron, ["v"], record=True)
    spike_monitor = b2.SpikeMonitor(neuron)

    # run the simulation
    net = b2.Network(neuron, voltage_monitor, spike_monitor)
    net.run(simulation_time)

    return voltage_monitor, spike_monitor
def simulate_exponential_IF_neuron(
        tau=MEMBRANE_TIME_SCALE_tau,
        R=MEMBRANE_RESISTANCE_R,
        v_rest=V_REST,
        v_reset=V_RESET,
        v_rheobase=RHEOBASE_THRESHOLD_v_rh,
        v_spike=FIRING_THRESHOLD_v_spike,
        delta_T=SHARPNESS_delta_T,
        I_stim=input_factory.get_zero_current(),
        simulation_time=200 * b2.ms):
    """
    Implements the dynamics of the exponential Integrate-and-fire model

    Args:
        tau (Quantity): Membrane time constant
        R (Quantity): Membrane resistance
        v_rest (Quantity): Resting potential
        v_reset (Quantity): Reset value (vm after spike)
        v_rheobase (Quantity): Rheobase threshold
        v_spike (Quantity) : voltage threshold for the spike condition
        delta_T (Quantity): Sharpness of the exponential term
        I_stim (TimedArray): Input current
        simulation_time (Quantity): Duration for which the model is simulated

    Returns:
        (voltage_monitor, spike_monitor):
        A b2.StateMonitor for the variable "v" and a b2.SpikeMonitor
    """

    eqs = """
    dv/dt = (-(v-v_rest) +delta_T*exp((v-v_rheobase)/delta_T)+ R * I_stim(t,i))/(tau) : volt
    """
    neuron = b2.NeuronGroup(1, model=eqs, reset="v=v_reset", threshold="v>v_spike", method="euler")
    neuron.v = v_rest
    # monitoring membrane potential of neuron and injecting current
    voltage_monitor = b2.StateMonitor(neuron, ["v"], record=True)
    spike_monitor = b2.SpikeMonitor(neuron)

    # run the simulation
    net = b2.Network(neuron, voltage_monitor, spike_monitor)
    net.run(simulation_time)

    return voltage_monitor, spike_monitor
def getting_started():
    """
    Simple example to get started
    """

    from neurodynex.tools import plot_tools
    current = input_factory.get_step_current(10, 200, 1. * b2.ms, 500 * b2.pA)
    ic = input_factory.get_zero_current()
    state_monitor, spike_monitor = simulate_AdEx_neuron(I_stim=current,
                                                        simulation_time=300 *
                                                        b2.ms)
    # plot_tools.plot_network_activity(rate_monitor, spike_monitor, state_monitor)
    # plt.show()

    plot_tools.plot_voltage_and_current_traces(state_monitor,
                                               current,
                                               title="AdEx neuron simulations")
    plt.show()
    plot_adex_state(state_monitor)

    print("nr of spikes: {}".format(spike_monitor.count[0]))
Exemple #5
0
 def simulate(self,
              current=input_factory.get_zero_current(),
              time=10 * b2.ms,
              rheo_threshold=None,
              v_rest=None,
              v_reset=None,
              delta_t=None,
              time_scale=None,
              resistance=None,
              threshold=None):
     if (v_rest == None):
         v_rest = self.rest_pot
     if (v_reset == None):
         v_reset = self.reset_pot
     if (rheo_threshold == None):
         rheo_threshold = self.rheo_threshold
     if (delta_t == None):
         delta_t = self.delta_t
     if (time_scale == None):
         time_scale = self.time_scale
     if (resistance == None):
         resistance = self.resistance
     if (threshold == None):
         threshold = self.threshold
     eqs = "dv/dt = (-(v-v_rest) +delta_t*exp((v-rheo_threshold)/delta_t)+ resistance * current(t,i))/(time_scale) : volt"
     neuron = b2.NeuronGroup(1,
                             model=eqs,
                             reset="v=v_reset",
                             threshold="v>threshold",
                             method="euler")
     neuron.v = v_rest
     voltage_monitor = b2.StateMonitor(neuron, ["v"], record=True)
     spike_monitor = b2.SpikeMonitor(neuron)
     net = b2.Network(neuron, voltage_monitor, spike_monitor)
     net.run(time)
     return voltage_monitor, spike_monitor
def simulate_AdEx_neuron(tau_m=MEMBRANE_TIME_SCALE_tau_m,
                         R=MEMBRANE_RESISTANCE_R,
                         v_rest=V_REST,
                         v_reset=V_RESET,
                         v_rheobase=RHEOBASE_THRESHOLD_v_rh,
                         a=ADAPTATION_VOLTAGE_COUPLING_a,
                         b=SPIKE_TRIGGERED_ADAPTATION_INCREMENT_b,
                         v_spike=FIRING_THRESHOLD_v_spike,
                         delta_T=SHARPNESS_delta_T,
                         tau_w=ADAPTATION_TIME_CONSTANT_tau_w,
                         I_stim=input_factory.get_zero_current(),
                         simulation_time=200 * b2.ms):
    """
    Implementation of the AdEx model with a single adaptation variable w.

    The Brian2 model equations are:

    .. math::

        \frac{dv}{dt} = (-(v-v_rest) +delta_T*exp((v-v_rheobase)/delta_T)+ R * I_stim(t,i) - R * w)/(tau_m) : volt \\
        \frac{dw}{dt} = (a*(v-v_rest)-w)/tau_w : amp

    Args:
        tau_m (Quantity): membrane time scale
        R (Quantity): membrane restistance
        v_rest (Quantity): resting potential
        v_reset (Quantity): reset potential
        v_rheobase (Quantity): rheobase threshold
        a (Quantity): Adaptation-Voltage coupling
        b (Quantity): Spike-triggered adaptation current (=increment of w after each spike)
        v_spike (Quantity): voltage threshold for the spike condition
        delta_T (Quantity): Sharpness of the exponential term
        tau_w (Quantity): Adaptation time constant
        I_stim (TimedArray): Input current
        simulation_time (Quantity): Duration for which the model is simulated

    Returns:
        (state_monitor, spike_monitor):
        A b2.StateMonitor for the variables "v" and "w" and a b2.SpikeMonitor
    """

    v_spike_str = "v>{:f}*mvolt".format(v_spike / b2.mvolt)

    # EXP-IF
    eqs = """
        dv/dt = (-(v-v_rest) +delta_T*exp((v-v_rheobase)/delta_T)+ R * I_stim(t,i) - R * w)/(tau_m) : volt
        dw/dt=(a*(v-v_rest)-w)/tau_w : amp
        """

    neuron = b2.NeuronGroup(1,
                            model=eqs,
                            threshold=v_spike_str,
                            reset="v=v_reset;w+=b",
                            method="euler")

    # initial values of v and w is set here:
    neuron.v = v_rest
    neuron.w = 0.0 * b2.pA

    # Monitoring membrane voltage (v) and w
    state_monitor = b2.StateMonitor(neuron, ["v", "w"], record=True)
    spike_monitor = b2.SpikeMonitor(neuron)
    # rate_monitor = b2.PopulationRateMonitor(neuron)

    # running simulation
    b2.run(simulation_time)
    return state_monitor, spike_monitor
def simulate_AdEx_neuron(
        tau_m=MEMBRANE_TIME_SCALE_tau_m,
        R=MEMBRANE_RESISTANCE_R,
        v_rest=V_REST,
        v_reset=V_RESET,
        v_rheobase=RHEOBASE_THRESHOLD_v_rh,
        a=ADAPTATION_VOLTAGE_COUPLING_a,
        b=SPIKE_TRIGGERED_ADAPTATION_INCREMENT_b,
        v_spike=FIRING_THRESHOLD_v_spike,
        delta_T=SHARPNESS_delta_T,
        tau_w=ADAPTATION_TIME_CONSTANT_tau_w,
        I_stim=input_factory.get_zero_current(),
        simulation_time=200 * b2.ms):
    r"""
    Implementation of the AdEx model with a single adaptation variable w.

    The Brian2 model equations are:

    .. math::

        \frac{dv}{dt} = (-(v-v_rest) +delta_T*exp((v-v_rheobase)/delta_T)+ R * I_stim(t,i) - R * w)/(tau_m) : volt \\
        \frac{dw}{dt} = (a*(v-v_rest)-w)/tau_w : amp

    Args:
        tau_m (Quantity): membrane time scale
        R (Quantity): membrane restistance
        v_rest (Quantity): resting potential
        v_reset (Quantity): reset potential
        v_rheobase (Quantity): rheobase threshold
        a (Quantity): Adaptation-Voltage coupling
        b (Quantity): Spike-triggered adaptation current (=increment of w after each spike)
        v_spike (Quantity): voltage threshold for the spike condition
        delta_T (Quantity): Sharpness of the exponential term
        tau_w (Quantity): Adaptation time constant
        I_stim (TimedArray): Input current
        simulation_time (Quantity): Duration for which the model is simulated

    Returns:
        (state_monitor, spike_monitor):
        A b2.StateMonitor for the variables "v" and "w" and a b2.SpikeMonitor
    """

    v_spike_str = "v>{:f}*mvolt".format(v_spike / b2.mvolt)

    # EXP-IF
    eqs = """
        dv/dt = (-(v-v_rest) +delta_T*exp((v-v_rheobase)/delta_T)+ R * I_stim(t,i) - R * w)/(tau_m) : volt
        dw/dt=(a*(v-v_rest)-w)/tau_w : amp
        """

    neuron = b2.NeuronGroup(1, model=eqs, threshold=v_spike_str, reset="v=v_reset;w+=b", method="euler")

    # initial values of v and w is set here:
    neuron.v = v_rest
    neuron.w = 0.0 * b2.pA

    # Monitoring membrane voltage (v) and w
    state_monitor = b2.StateMonitor(neuron, ["v", "w"], record=True)
    spike_monitor = b2.SpikeMonitor(neuron)

    # running simulation
    b2.run(simulation_time)
    return state_monitor, spike_monitor