snnib.simulations.brian2_simulation

simple spiking neural network simulation in brian2

  • used to generate an input file for snnib

  • the whole experiment is based on an example from the KU Principles of Brain Computation at Graz University of Technology

Exceptions

Classes

Functions
  • poisson_generator() – draws events from a poisson point process

  • generate_stimulus() – generates input spikes

  • truncnorm() – truncated normal distribution

  • get_rates() – returns spike rates

  • get_spiketrains() – returns spiketrains

  • lif_ng() – base definition of a LIF neuron group

  • stp_syn() – base definition of STP synapse group

  • analyze() – executes analysis of the simulated network

  • check_stp() – check if STP is implemented as expected

  • experiment() – run the entire experiment

Other Objects

Functions

analyze(t_sim, spike_mon_E, spike_mon_I, ...)

runs a brief analysis of the simulation

check_stp()

creates plot to check if STP is implemented correctly

experiment([idx])

runs the experiment as a whole

generate_stimulus(t_sim[, stim_len, ...])

Generate input spikes.

get_rates(spike_mon, t_max[, bin_size])

returns spike rates in the interval bin_size

lif_ng(n, u_rest, u_reset, u_th, R_m, tau_m, ...)

returns generated LIF neuron group

poisson_generator(rate, t_lim[, unit_ms])

draw events from a poisson point process.

stp_syn(ng_pre, ng_post, w_mean, w_std, ...)

returns generated STP synapses

truncnorm([mu, sigma, xmin, xmax, size])

returns samples from truncated normal distribution

snnib.simulations.brian2_simulation.analyze(t_sim: Quantity, spike_mon_E: SpikeMonitor, spike_mon_I: SpikeMonitor, spike_mon_in: SpikeMonitor)[source]

runs a brief analysis of the simulation

Parameters
  • t_sim
    • simulation time

  • spike_mon_E
    • brian2.SpikeMonitor

    • spike monitor of the excitatory neurons

  • spike_mon_I
    • brian2.SpikeMonitor

    • spike monitor of the inhibitory neurons

  • spike_mon_in
    • brian2.SpikeMonitor

    • spike monitor of the input neurons

Raises

Returns

Dependencies
  • brian2

  • plotly

snnib.simulations.brian2_simulation.check_stp()[source]

creates plot to check if STP is implemented correctly

Parameters

Raises

Returns

Dependencies
  • brian2

  • plotly

snnib.simulations.brian2_simulation.experiment(idx: int = -1)[source]

runs the experiment as a whole

Parameters
  • idx
    • int, optional

    • which configuration of the experiment to run

    • configurations
      • 0: “default”

      • 1: “optimized” (huge)

      • 2: “medium”

      • 3: “small”

      • 4: “tiny”

    • the default is -1

Raises

Returns
  • net
    • brian2.Network

    • created network

  • t_sim
    • brian2.Quantity

    • simulation time

  • dt
    • brian2.Quantity

    • simulation time step

  • params
    • dict

    • parameters of the configuration

  • parts
    • list

    • parts of net

    • also present within net

Dependencies
  • brian2

  • numpy

  • plotly

snnib.simulations.brian2_simulation.generate_stimulus(t_sim, stim_len=50, stim_dt=500, num_input=3, rate=200, dt=0.1)[source]

Generate input spikes.

Parameters:
  • t_sim – total time for stimulus generation in ms

  • stim_len – duration of each stimulus

  • stim_dt – stimulus spacing

  • num_input – number of input signals (i.e. number of input neurons)

  • rate – firing rate of active neurons in Hz

  • dt – simulation time step for rounding

Returns:

list contain a list of spike times for each input neuron

snnib.simulations.brian2_simulation.get_rates(spike_mon: SpikeMonitor, t_max: Quantity, bin_size: Quantity = 20. * msecond) Tuple[List[Quantity], List[Quantity]][source]

returns spike rates in the interval bin_size

Parameters
  • spike_mon
    • brian2.SpikeMonitor

    • spike monitor to compute rates for

  • t_max
    • brian2.Quantity

    • maximum time to compute rates up to

  • bin_size
    • brian2.Quantity, optional

    • size of the bins to use as reference for rate computation

    • the default is 20 * ms

Raises

Returns
  • t_
    • List[brian2.Quantity]

    • time representing a bin

  • f_
    • List[brian2.Quantity]

    • frequency in a bin

Dependencies
  • numpy

snnib.simulations.brian2_simulation.lif_ng(n: int, u_rest, u_reset, u_th, R_m, tau_m, delta_abs, tau_syn, u0=None) NeuronGroup[source]

returns generated LIF neuron group

  • base definition of simple LIF neuron for easy generation of several similar neuron groups

Parameters
  • n
    • int

    • number of neurons in the group

  • u_rest
    • resting potential

  • u_reset
    • reset potential

  • u_th
    • threshold voltage

  • R_m
    • membrane resistance

  • tau_m
    • membrane time constant

  • delta_abs
    • refractory period

  • tau_syn
    • synaptic time constant

  • u0
    • initial membrane potential

Raises

Returns
  • neurons
    • NeuronGroup

    • generated neuron group

Dependencies
  • brian2

snnib.simulations.brian2_simulation.poisson_generator(rate, t_lim, unit_ms=False)[source]

draw events from a poisson point process.

Note: the implementation assumes at t=t_lim[0], although this spike is not included in the spike list.

Parameters:
  • rate – the rate of the discharge in Hz

  • t_lim – tuple containing start and end time of the spike

  • unit_ms – use ms as unit for times in t_lim and resulting events

Returns:

numpy array containing spike times in s (or ms, if unit_ms is set)

snnib.simulations.brian2_simulation.stp_syn(ng_pre: NeuronGroup, ng_post: NeuronGroup, w_mean, w_std, w_min, w_max, delay: str, U, tau_fac, tau_rec, connect_i: Any = None, connect_j: Any = None, drive: Literal['event-driven', 'clock-driven'] = 'event-driven') Synapses[source]

returns generated STP synapses

  • base definition of simple STP synapses for easy generation of several similar synapse groups

Parameters
  • ng_pre
    • int

    • number of pre synaptic neurons

  • ng_post
    • int

    • number of post synaptic neurons

  • w_mean
    • mean of a truncated normal distribution

    • used for initializing synapse weights

  • w_min
    • minimum of a truncated normal distribution

    • used for initializing synapse weights

  • w_max
    • maximum of a truncated normal distribution

    • used for initializing synapse weights

  • delay
    • delay of the synapse

  • U
    • indicates fraction of resources to use fro some spike

  • tau_fac
    • facilitation time constant

  • tau_rec
    • recovery time constant

  • connect_i
    • expression defining connectivity for pre synaptic neurons

  • connect_i
    • expression defining connectivity for post synaptic neurons

  • drive
    • specifies simulation driver

Raises

Returns
  • syn
    • Synapses

    • generated synapses

Dependencies
  • brian2

snnib.simulations.brian2_simulation.truncnorm(mu: float = 0, sigma: float = 1, xmin: float = None, xmax: float = None, size: tuple = 1) ndarray[source]

returns samples from truncated normal distribution

  • function to generate samples from a truncated normal distribution

Parameters
  • mu
    • float, optional

    • mean

    • the default is 0

  • sigma
    • float, optional

    • standard deviation

    • the default is 1

  • xmin
    • float, optional

    • lower truncation bound

    • the default is None
      • no truncation

  • xmax
    • float, optional

    • upper truncation bound

    • the default is None
      • no truncation

  • size
    • tuple, optional

    • shape of the array to generate

    • the default is 1

  • ‘verbose’
    • int, optional

    • verbosity level

    • the default is 0

Returns
  • out
    • np.ndarray

    • samples drawn from a truncated normal distribution

Dependencies
  • numpy