C++ code references

Base spiking dynamics

Defines

MAX_POTENTIAL_SLOPE

Cutoff value of potential slope [mV/ms].

OSCILLATORY_AMPLITUDE_MIN

Minimal value for an oscillatory input to be considered valid [pA].

Typedefs

typedef std::vector<double> dynamical_state
class Spike
#include <neurons_base.hpp>

A spike object is a weight and arrival time.

This object is the one through which neurons communicate. The overriden ‘operator <’ is used to insert the spike in the priority queue of the neuron.

Public Functions

inline Spike(float weight, double arrival_time)
inline bool operator<(const Spike &other) const

Priority function of the spike queue.

The greater the time of arrival, the less the importance. This operator is called when inserting spikes in spike queues.

Public Members

float weight

Increase in postsynaptic conductance.

float arrival_time

The (absolute) time of arrival.

bool processed

Flag to check missed spikes.

class Synapse
#include <neurons_base.hpp>

A weight-delay connection object between two neurons.

The method fire() of the synapse creates a spike and adds it to the spike queue of the postsynaptic neuron.

Public Functions

inline Synapse(Neuron *presynaptic, Neuron *postsynaptic, float weight, float delay)
void fire(EvolutionContext *evo)
inline void set_delay(float new_delay)
inline float get_delay()
int get_efferent_pop_id()

Public Static Attributes

static float min_delay = std::numeric_limits<float>::infinity()

Smallest synaptic delay of the model. Used to check timestep.

Private Members

Neuron *presynaptic

Pointer to the postsynaptic neuron.

Neuron *postsynaptic

Pointer to the presynaptic neuron.

float weight

Synapse weight. Each spike produced from this synapse will have this weight.

float delay

Synapse delay. Each spike produced from this synapse will have this delay.

class Neuron
#include <neurons_base.hpp>

The base spiking dynamical object.

This class is a virtual base class. The explicit dynamic model must override the evolve_state() method.

The main method of Neuron is evolve(), in which are called in sequence:

To declare a new neuron:

  • override the evolve_state method

  • add the neuron to neuron_type enum class

After profiling, it became evident that spike processing has a significantly greater impact on computational cost than I had initially anticipated. Therefore, each improvement attempt should start with an analysis of handle_incoming_spikes().

Subclassed by aeif_neuron, aqif2_neuron, aqif_neuron, izhikevich_neuron

Public Functions

inline dynamical_state get_state()
Neuron(Population *population)
virtual ~Neuron() = default
void evolve()

The evolution function

void connect(Neuron *neuron, double weight, double delay)

Connection function. Adds an efferent synapse to the synapse list.

void handle_incoming_spikes()

Manages the incoming spikes.

void emit_spike()

Makes the neuron’s efferent synapses fire

inline double getV()
inline void set_evolution_context(EvolutionContext *evo)
virtual void on_spike()

The actions to take when the model has a spike

inline virtual void evolve_state(const dynamical_state&, dynamical_state&, const double)

The differential equations of the neuron

Public Members

string nt = "base_neuron"
HierarchicalID id
Population *population
std::vector<Synapse> efferent_synapses
std::priority_queue<Spike> incoming_spikes
double last_spike_time

Protected Attributes

dynamical_state state
bool spike_flag
EvolutionContext *evo
class NeuroParam
#include <neurons_base.hpp>

A container for the parameters of each neuron type.

This class is necessary to store population-wise the information about the neurons and to grant efficient access to parameter values

Subclassed by aeif_param, aqif_param, izhikevich_param

Public Functions

NeuroParam()

Builds the default neuroparam. External currents are set to zero.

NeuroParam(ParaMap &paramap)

Constructor of NeuroParam given a ParaMap

inline string get_neuron_type()
void add(const std::string &key, float value)

Public Members

ParaMap paramap
float E_l

Rest potential [mV].

float V_reset

Reset potential [mV].

float V_peak

Spike-emission threshold [mV].

float E_ex

Excitatory synaptic potential [mV].

float E_in

Inhibitory synaptic potential [mV].

float C_m

Membrane potential [pF].

float tau_ex

Excitatory synapse decay time [ms].

float tau_in

Inhibitory synapse decay time [ms].

float tau_refrac

Refractory time.

float I_e

External current (constant) amplitude [nA].

float I_osc

External current (oscillatory) amplitude [nA].

float omega_I

External current (oscillatory) angular frequency [rad/s].

Protected Attributes

string neur_type
class NeuroFactory
#include <neurons_base.hpp>

A factory for generating neuron objects.

Public Types

typedef std::function<Neuron*(Population*)> neuron_constructor
typedef std::function<NeuroParam*(ParaMap)> neuroparam_constructor

Public Functions

inline void add_neuron(string neuron_model, neuron_constructor nc, neuroparam_constructor npc)
inline NeuroParam *get_neuroparam(string neuron_model, ParaMap &params)
inline Neuron *get_neuron(string neuron_model, Population *pop)

Public Static Functions

static inline NeuroFactory *get_neuro_factory()
template<class N>
static inline Neuron *neuron_maker(Population *pop)
template<class NP>
static inline NeuroParam *neuroparam_maker(ParaMap params)

Private Functions

inline NeuroFactory()

Private Members

map<string, neuron_constructor> neuro_constructors_
map<string, neuroparam_constructor> neuroparam_constructors_

Private Static Attributes

static NeuroFactory *instance = nullptr

Devices

Devices for the quilt multiscale simulator.

This file contains the declarations of:

Author

Gianluca Becuzzi (becuzzigianluca@gmail.com)

Copyright

Copyright (c) 2024 Gianluca Becuzzi

Typedefs

typedef std::vector<double> dynamical_state
class PopulationMonitor
#include <devices.hpp>

Base class for population monitors.

Subclassed by PopulationRateMonitor, PopulationSpikeMonitor, PopulationStateMonitor

Public Functions

inline PopulationMonitor(Population *population)
inline virtual void gather()
inline void set_evolution_context(EvolutionContext *evo)
inline virtual ~PopulationMonitor()

Protected Attributes

Population *monitored_population
EvolutionContext *evo
class PopulationRateMonitor : public PopulationMonitor

Public Functions

inline PopulationRateMonitor(Population *population)
virtual void gather() override

Disclaimer: this section is cumbersome due to the redundancy of the ‘get_history()’ methods. For now this is somewhat a patch, in future I will make it more clean (for the procrastination demon: today is feb 29 - 2024 )

vector<float> get_history()

Protected Attributes

vector<float> history
class PopulationSpikeMonitor : public PopulationMonitor
#include <devices.hpp>

Monitor for the variable Population::n_spikes_last_step

Monitor for the variables Population::neurons::state

Public Functions

inline PopulationSpikeMonitor(Population *pop)
virtual void gather()
vector<int> get_history()

Protected Attributes

vector<int> history
class PopulationStateMonitor : public PopulationMonitor

Public Functions

inline PopulationStateMonitor(Population *pop)
virtual void gather()
vector<vector<dynamical_state>> get_history()

Protected Attributes

vector<vector<dynamical_state>> history
class PopInjector
#include <devices.hpp>

Virtual base class for population injectors.

Subclassed by InhomPoissonSpikeSource, PoissonSpikeSource, PopCurrentInjector

Public Functions

inline PopInjector(Population *pop)
virtual ~PopInjector() = default
inline virtual void inject(EvolutionContext*)

Public Members

Population *pop
class PopCurrentInjector : public PopInjector
#include <devices.hpp>

Constant current population injector.

Public Functions

inline PopCurrentInjector(Population *pop, float I, float t_min, float t_max)
virtual void inject(EvolutionContext *evo) override

Private Members

double I
double t_min
double t_max
bool activated
bool deactivated
class PoissonSpikeSource : public PopInjector
#include <devices.hpp>

Source of poisson-distributed spikes.

For now only one-to-one connection is implemented

Public Functions

PoissonSpikeSource(Population *pop, float rate, float weight, float weight_delta, double t_min, double t_max)
virtual void inject(EvolutionContext *evo) override

Generates spikes until a spike is generated in another time bin to prevent the spike queue from being uselessly too long.

void set_rate(float new_rate)

Private Members

float rate

Rate of the Poisson process [Hz].

float weight

Weight of the spikes.

float weight_delta

Semidispersion of the weight of the spikes.

double t_min
double t_max
std::vector<float> weights
std::vector<double> next_spike_times
RNG rng
class InhomPoissonSpikeSource : public PopInjector
#include <devices.hpp>

Source of poisson-distributed spikes with time-dependent rate.

For now only one-to-one connection is implemented

Param pop:

Target spiking population of the source

Param rate_function:

The rate function r(t). Must be double(double)

Param weight:

Param weight_delta:

Param generation_window_length:

The length of the generation windos in ms

Public Functions

InhomPoissonSpikeSource(Population *pop, std::function<double(double)> rate_function, float weight, float weight_delta, double generation_window_length)

Initializes a Inhomogeneous Poisson Spike Source

Parameters:
  • pop – The spiking population

  • rate_function – The rate function. It must have double(double) signature, given a time returns the rate.

void _inject_partition(const vector<double> &rate_buffer, double now, double dt, int start_id, int end_id, RNGDispatcher *rng_disp)

Generate one spike for neuron given the current rate

Injects a partition of the target population. For multithreading.

virtual void inject(EvolutionContext *evo) override

Creates (easy) population partitions and start threads to generate spikes using InhomogeneousPoissonSPikeSource::_inject_partition()

Public Members

std::shared_ptr<PerformanceManager> perf_mgr

Private Members

std::function<double(double)> rate_function
float weight

Weight of the spikes.

float weight_delta

Semidispersion of the weight of the spikes.

std::vector<float> weights
double generation_window_length
double currently_generated_time
RNG rng
std::vector<double> integration_start
std::vector<double> integration_leftovers
std::vector<double> integration_thresholds

Private Static Attributes

static ThreadSafeFile outfile

Neuron models

class aqif_neuron : public Neuron
#include <neuron_models.hpp>

The adaptive quadratic integrate-and-fire neuron.

Parameters are hold in an aqif_param object

\[ C_m \frac{dV}{dt} = k(V-V_{rest})(V - V_{thr}) - w \]

\[ \tau_w \frac{dw}{dt} = -w + a(V-V_{rest}) \]

On spike:

\[ V\rightarrow V_{reset} \]
\[ w \rightarrow w + b \]

Public Functions

aqif_neuron(Population *population)
void evolve_state(const dynamical_state &x, dynamical_state &dxdt, const double t) override
virtual void on_spike() override

The actions to take when the model has a spike

class aqif_param : public NeuroParam
#include <neuron_models.hpp>

Container for parameters of aqif_neuron

Subclassed by aqif2_param

Public Functions

inline aqif_param(ParaMap &paramap)

Public Members

float k

Quadratic term constant.

float V_th

Quadratic term shift.

float ada_a

Adaptive variable drift term.

float ada_b

Adaptive variable jump term.

float ada_tau_w

Adaptive variable decay time.

class izhikevich_neuron : public Neuron
#include <neuron_models.hpp>

The adaptive quadratic neuron model of Izhikevich.

Parameters are hold in izhikevich_param object

\[ C_m\frac{dV}{dt} = 0.04 V^2 + 5V + 140 - w \]
\[ \frac{dw}{dt} = a(b(V-V_{rest})-w) \]

Public Functions

izhikevich_neuron(Population *population)
void evolve_state(const dynamical_state &x, dynamical_state &dxdt, const double t) override
virtual void on_spike() override

The actions to take when the model has a spike

class izhikevich_param : public NeuroParam
#include <neuron_models.hpp>

Container for parameters of izhikevich_neuron

Public Functions

inline izhikevich_param(ParaMap &paramap)

Public Members

float a
float b
float d
class aeif_neuron : public Neuron
#include <neuron_models.hpp>

The adaptive exponential integrate-and-fire model.

Parameters are hold in aeif_param object

\[ \frac{dV}{dt} = - (V - V_{rest}) + \Delta \exp{\left(\frac{V - V_{expthresh}}{\Delta}\right)} - w \]

\[ \tau_w \frac{dw}{dt} = -w + a(V-V_{rest}) \]

Public Functions

aeif_neuron(Population *population)
void evolve_state(const dynamical_state &x, dynamical_state &dxdt, const double t) override
virtual void on_spike() override

The actions to take when the model has a spike

class aeif_param : public NeuroParam
#include <neuron_models.hpp>

Container for parameters of aeif_neuron

Public Functions

inline aeif_param(ParaMap &paramap)

Public Members

float delta_T

exponential width factor [mV]

float V_th

threshold value of the exponential factor [mV]

float ada_a

drift coefficient of the recovery variable

float ada_b

jump coefficient of the recovery variable

float ada_tau_w

timescale parameter of the recovery variable [ms]

float G_L

Membrane leak conductance [nS].

class aqif2_neuron : public Neuron

Public Functions

aqif2_neuron(Population *population)
void evolve_state(const dynamical_state &x, dynamical_state &dxdt, const double t) override
virtual void on_spike() override

The actions to take when the model has a spike

class aqif2_param : public aqif_param

Public Functions

inline aqif2_param(ParaMap &paramap)

Public Members

float V_b

Oscillators

Warning

This section is under construction. The code is not well defined yet.

A network of oscillators is defined by a matrix of weights \(W_{ij}\) and a matrix of delays \(\Delta_{ij}\).

Functions

template<class OSC>
Oscillator *oscillator_maker(ParaMap *params, OscillatorNetwork *osc)

Builder method for creating an oscillator instance of a specific type.

Parameters:
  • OSC – Type of the oscillator.

  • params – Parameter map for the oscillator.

  • osc – Pointer to the oscillator network.

Returns:

Raw pointer to the created oscillator.

OscillatorFactory &get_oscillator_factory()

Singleton method to return a unique instance of OscillatorFactory.

Returns:

Reference to the OscillatorFactory instance.

class Oscillator
#include <oscillators.hpp>

Base class of oscillators.

The evolve_state() method defines the oscillator dynamics and must be overridden.

Subclassed by Transducer, harmonic_oscillator, jansen_rit_oscillator, leon_jansen_rit_oscillator, noisy_jansen_rit_oscillator, test_oscillator

Public Functions

Oscillator(ParaMap *params, OscillatorNetwork *oscnet)

Constructor for the Oscillator class.

Parameters:
  • params – Parameter map for the oscillator.

  • oscnet – Pointer to the oscillator network.

inline ~Oscillator()
inline string get_type()
inline unsigned int get_space_dimension()
inline vector<dynamical_state> get_history()
inline double get_past(unsigned int axis, double t)
inline vector<double> get_eeg()
inline virtual vector<double> get_rate_history()
void set_evolution_context(EvolutionContext *evo)
void print_info()

Public Members

HierarchicalID id

Unique identifier for the oscillator.

ParaMap *params

Pointer to parameter map for the oscillator.

OscillatorNetwork *oscnet

Pointer to the oscillator network to which the oscillator belongs.

ContinuousRK memory_integrator

Continuous Runge-Kutta integrator for storing state history.

string oscillator_type = "base"

Type of the oscillator. Default is “base”.

unsigned int space_dimension = 2

Dimension of the oscillator’s state space. Default is 2.

vector<Link*> incoming_osc

Vector of incoming links to the oscillator.

vector<double> input_history

Vector of the history of inputs

std::function<void(const dynamical_state &x, dynamical_state &dxdt, double t)> evolve_state

Virtual function representing the evolution of the oscillator’s state.

Param x:

Current state of the oscillator.

Param dxdt:

Output for the derivative of the state.

Param t:

Current time.

std::function<double(const dynamical_state &x)> eeg_voi

Virtual function representing the variable of interest for EEG of the oscillator.

Private Members

EvolutionContext *evo

Pointer to the evolution context for the oscillator.

class OscillatorFactory
#include <oscillators.hpp>

Factory class for creating oscillators of different types.

Public Functions

inline bool add_constructor(string const &oscillator_type, constructor const &lker)

Adds a constructor for a specific oscillator type.

Parameters:
  • oscillator_type – Type of the oscillator.

  • lker – Constructor function for the oscillator type.

Returns:

True if the constructor was added successfully.

Oscillator *get_oscillator(string const &oscillator_type, ParaMap *params, OscillatorNetwork *osc_net)

Gets an oscillator instance based on the type.

Parameters:
  • oscillator_type – Type of the oscillator.

  • params – Parameter map for the oscillator.

  • osc_net – Pointer to the oscillator network.

Returns:

Pointer to the created oscillator.

OscillatorFactory()

Constructor for the OscillatorFactory class.

Private Types

typedef std::function<Oscillator*(ParaMap*, OscillatorNetwork*)> constructor

Private Members

map<string, constructor> _constructor_map

Map of oscillator types to their corresponding constructors.

class harmonic_oscillator : public Oscillator

Public Functions

harmonic_oscillator(ParaMap *params, OscillatorNetwork *oscnet)

Public Members

float k
class test_oscillator : public Oscillator

Public Functions

test_oscillator(ParaMap *params, OscillatorNetwork *oscnet)

Public Members

float k
class jansen_rit_oscillator : public Oscillator
#include <oscillators.hpp>

The Jansen-Rit oscillator.

From Jansen, B.H., Rit, V.G. Electroencephalogram and visual evoked potential generation in a mathematical model of coupled cortical columns. Biol. Cybern. 73, 357–366 (1995). https://doi.org/10.1007/BF00199471

Public Functions

jansen_rit_oscillator(ParaMap *params, OscillatorNetwork *oscnet)
double sigm(double v)
virtual vector<double> get_rate_history() override

Public Members

float ke

Rate constant for postsynaptic population response to excitatory input [ms^(-1)]. Default 0.1.

float ki

Rate constant for postsynaptic population response to inhibitory input [ms^(-1)]. Default 0.05.

float He

Maximum amplitude of the excitatory postsynaptic population response [mV]. Default 3.25.

float Hi

Maximum amplitude of the inhibitory postsynaptic population response [mV]. Default 22.0.

float C

Connectivity constant: pyramidal to spiny stellate. Default 135.

float v0

Population mean firing threshold potential [mV]. Default 6.0.

float s

Firing rate sigmoid function voltage sensitivity parameter [mV]. Default 0.56.

float rmax

Maximum population mean firing rate [ms^(-1)]. Default 0.005.

float U

Bifurcation parameter: background constant input [ms^(-1)]. Default 0.13.

class noisy_jansen_rit_oscillator : public Oscillator

Public Functions

noisy_jansen_rit_oscillator(ParaMap *params, OscillatorNetwork *oscnet)
double sigm(double v)
virtual vector<double> get_rate_history() override

Public Members

float ke

Rate constant for postsynaptic population response to excitatory input [ms^(-1)]. Default 0.1.

float ki

Rate constant for postsynaptic population response to inhibitory input [ms^(-1)]. Default 0.05.

float He

Maximum amplitude of the excitatory postsynaptic population response [mV]. Default 3.25.

float Hi

Maximum amplitude of the inhibitory postsynaptic population response [mV]. Default 22.0.

float C

Connectivity constant: pyramidal to spiny stellate. Default 135.

float v0

Population mean firing threshold potential [mV]. Default 6.0.

float s

Firing rate sigmoid function voltage sensitivity parameter [mV]. Default 0.56.

float rmax

Maximum population mean firing rate [ms^(-1)]. Default 0.005.

float U

Bifurcation parameter: background constant input [ms^(-1)]. Default 0.13.

float sigma_noise

Variability of the uniformly distributed white noise. Default 0.0.

float epsC_exc_pre

Relative variation of connectivity: C1 -> (1+ delta)*1.0*C.

float epsC_exc_post

Relative variation of connectivity: C2 -> (1+ delta)*0.8*C.

float epsC_inh_pre

Relative variation of connectivity: C3 -> (1+delta)*0.25*C.

float epsC_inh_post

Relative variation of connectivity: C4 -> (1+delta)*0.25*C.

Private Members

RNG rng
class leon_jansen_rit_oscillator : public Oscillator

Public Functions

leon_jansen_rit_oscillator(ParaMap *params, OscillatorNetwork *oscnet)
double sigm(double v)

Public Members

float He
float Hi
float ke
float ki
float gamma_1
float gamma_2
float gamma_3
float gamma_4
float gamma_5
float gamma_1T
float gamma_2T
float gamma_3T
float e0
float rho1
float rho2
float U
float P
float Q
class OscillatorNetwork

Public Functions

OscillatorNetwork(int N, ParaMap *params)
OscillatorNetwork(vector<ParaMap*> params)
~OscillatorNetwork()
void build_connections(Projection *proj, ParaMap *link_params)
void build_connections(Projection *proj, vector<ParaMap*> links_params)
void initialize(EvolutionContext *evo, double tau, double vmin, double vmax)
void evolve()
void run(EvolutionContext *evo, double time, int verbosity)
inline void set_evolution_context(EvolutionContext *evo)
inline EvolutionContext *get_evolution_context()

Public Members

HierarchicalID id
vector<Oscillator*> oscillators
PerformanceManager perf_mgr
bool has_oscillators = false
bool has_links = false
bool is_initialized = false
float max_delay
float min_delay

Private Members

EvolutionContext *evo