Side classes#

nngt.GroupProperty(size[, constraints, …]) Class defining the properties needed to create groups of neurons from an existing Graph or one of its subclasses.
nngt.MetaGroup([nodes, name]) Class defining a meta-group of neurons.
nngt.NeuralGroup([nodes, neuron_type, …]) Class defining groups of neurons.
nngt.NeuralPop([size, parent, meta_groups, …]) The basic class that contains groups of neurons and their properties.

Details#

class nngt.GroupProperty(size, constraints={}, neuron_model=None, neuron_param={}, syn_model=None, syn_param={})[source]#

Class defining the properties needed to create groups of neurons from an existing Graph or one of its subclasses.

Variables:
  • sizeint Size of the group.
  • constraintsdict, optional (default: {}) Constraints to respect when building the NeuralGroup .
  • neuron_model – str, optional (default: None) name of the model to use when simulating the activity of this group.
  • neuron_param – dict, optional (default: {}) the parameters to use (if they differ from the model’s defaults)

Create a new instance of GroupProperties.

Notes

The constraints can be chosen among:
  • “avg_deg”, “min_deg”, “max_deg” (int) to constrain the total degree of the nodes
  • “avg/min/max_in_deg”, “avg/min/max_out_deg”, to work with the in/out-degrees
  • “avg/min/max_betw” (double) to constrain the betweenness centrality
  • “in_shape” (nngt.geometry.Shape) to chose neurons inside a given spatial region

Examples

>>> di_constrain = { "avg_deg": 10, "min_betw": 0.001 }
>>> group_prop = GroupProperties(200, constraints=di_constrain)
class nngt.MetaGroup(nodes=None, name=None, **kwargs)[source]#

Class defining a meta-group of neurons.

Its main variables are:

Variables:
  • idslist of int the ids of the neurons in this group.
  • is_metagroupbool whether the group is a meta-group or not (neuron_type is None for meta-groups)

Calling the class creates a group of neurons. The default is an empty group but it is not a valid object for most use cases.

Parameters:
  • nodes (int or array-like, optional (default: None)) – Desired size of the group or, a posteriori, NNGT indices of the neurons in an existing graph.
  • name (str, optional (default: “Group N”)) – Name of the meta-group.
Returns:

A new MetaGroup object.

excitatory#

Return the ids of all excitatory nodes inside the meta-group.

inhibitory#

Return the ids of all inhibitory nodes inside the meta-group.

class nngt.NeuralGroup(nodes=None, neuron_type=1, neuron_model=None, neuron_param=None, name=None)[source]#

Class defining groups of neurons.

Its main variables are:

Variables:
  • idslist of int the ids of the neurons in this group.
  • neuron_typeint the default is 1 for excitatory neurons; -1 is for inhibitory neurons; meta-groups must have neuron_type set to None
  • neuron_model – str, optional (default: None) the name of the model to use when simulating the activity of this group
  • neuron_param – dict, optional (default: {}) the parameters to use (if they differ from the model’s defaults)
  • is_metagroupbool whether the group is a meta-group or not (neuron_type is None for meta-groups)

Warning

Equality between NeuralGroup`s only compares the  size and neuronal type, ``model` and param attributes. This means that groups differing only by their ids will register as equal.

Calling the class creates a group of neurons. The default is an empty group but it is not a valid object for most use cases.

Changed in version 0.8: Removed syn_model and syn_param.

Parameters:
  • nodes (int or array-like, optional (default: None)) – Desired size of the group or, a posteriori, NNGT indices of the neurons in an existing graph.
  • neuron_type (int, optional (default: 1)) – Type of the neurons (1 for excitatory, -1 for inhibitory) or None if not relevant (only allowed for metag roups).
  • neuron_model (str, optional (default: None)) – NEST model for the neuron.
  • neuron_param (dict, optional (default: model defaults)) – Dictionary containing the parameters associated to the NEST model.
Returns:

A new NeuralGroup instance.

copy()[source]#

Return a deep copy of the group.

has_model#
ids#
is_metagroup#
is_valid#

i.e. if it has either a size or some ids associated to it.

New in version 1.0.

Type:Whether the group can be used in a population
name#
nest_gids#
neuron_model#
neuron_param#
neuron_type#
parent#

Return the parent NeuralPop of the group

properties#
size#
class nngt.NeuralPop(size=None, parent=None, meta_groups=None, with_models=True, *args, **kwargs)[source]#

The basic class that contains groups of neurons and their properties.

Variables:
  • has_modelsbool, True if every group has a model attribute.
  • sizeint, Returns the number of neurons in the population.
  • syn_specdict, Dictionary containing informations about the synapses between the different groups in the population.
  • is_validbool, Whether this population can be used to create a network in NEST.

Initialize NeuralPop instance.

Parameters:
  • size (int, optional (default: 0)) – Number of neurons that the population will contain.
  • parent (Network, optional (default: None)) – Network associated to this population.
  • meta_groups (dict of str/NeuralGroup items) – Optional set of groups. Contrary to the primary groups which define the population and must be disjoint, meta groups can overlap: a neuron can belong to several different meta groups.
  • with_models (bool) – whether the population’s groups contain models to use in NEST
  • *args (items for OrderedDict parent)
  • **kwargs (dict)
Returns:

pop (NeuralPop object.)

add_meta_group(group, name=None, replace=False)[source]#

Add an existing meta group to the population.

Parameters:
  • group (NeuralGroup) – Meta group.
  • name (str, optional (default: group name)) – Name of the meta group.
  • replace (bool, optional (default: False)) – Whether to override previous exiting meta group with same name.

Note

The name of the group is automatically updated to match the name argument.

add_to_group(group_name, ids)[source]#

Add neurons to a specific group.

Parameters:
  • group_name (str or int) – Name or index of the group.
  • ids (list or 1D-array) – Neuron ids.
copy()[source]#

Return a deep copy of the population.

create_group(neurons, name, neuron_type=1, neuron_model=None, neuron_param=None, replace=False)[source]#

Create a new group in the population.

Parameters:
  • neurons (int or array-like) – Desired number of neurons or list of the neurons indices.
  • name (str) – Name of the group.
  • neuron_type (int, optional (default: 1)) – Type of the neurons : 1 for excitatory, -1 for inhibitory.
  • neuron_model (str, optional (default: None)) – Name of a neuron model in NEST.
  • neuron_param (dict, optional (default: None)) – Parameters for neuron_model in the NEST simulator. If None, default parameters will be used.
  • replace (bool, optional (default: False)) – Whether to override previous exiting meta group with same name.
create_meta_group(neurons, name, neuron_param=None, replace=False)[source]#

Create a new meta group and add it to the population.

Parameters:
  • neurons (int or array-like) – Desired number of neurons or list of the neurons indices.
  • name (str) – Name of the group.
  • neuron_type (int, optional (default: 1)) – Type of the neurons : 1 for excitatory, -1 for inhibitory.
  • neuron_model (str, optional (default: None)) – Name of a neuron model in NEST.
  • neuron_param (dict, optional (default: None)) – Parameters for neuron_model in the NEST simulator. If None, default parameters will be used.
  • replace (bool, optional (default: False)) – Whether to override previous exiting meta group with same name.
classmethod exc_and_inhib(size, iratio=0.2, en_model='aeif_cond_alpha', en_param=None, in_model='aeif_cond_alpha', in_param=None, syn_spec=None, parent=None, meta_groups=None)[source]#

Make a NeuralPop with a given ratio of inhibitory and excitatory neurons.

Changed in version 0.8: Added syn_spec parameter.

Changed in version 1.2: Added meta_groups parameter

Parameters:
  • size (int) – Number of neurons contained by the population.

  • iratio (float, optional (default: 0.2)) – Fraction of the neurons that will be inhibitory.

  • en_model (str, optional (default: default_neuron)) – Name of the NEST model that will be used to describe excitatory neurons.

  • en_param (dict, optional (default: default NEST parameters)) – Parameters of the excitatory neuron model.

  • in_model (str, optional (default: default_neuron)) – Name of the NEST model that will be used to describe inhibitory neurons.

  • in_param (dict, optional (default: default NEST parameters)) – Parameters of the inhibitory neuron model.

  • syn_spec (dict, optional (default: static synapse)) – Dictionary containg a directed edge between groups as key and the associated synaptic parameters for the post-synaptic neurons (i.e. those of the second group) as value. If provided, all connections between groups will be set according to the values contained in syn_spec. Valid keys are:

    • (‘excitatory’, ‘excitatory’)
    • (‘excitatory’, ‘inhibitory’)
    • (‘inhibitory’, ‘excitatory’)
    • (‘inhibitory’, ‘inhibitory’)
  • parent (Network, optional (default: None)) – Network associated to this population.

  • meta_groups (list dict of str/NeuralGroup items) – Additional set of groups which can overlap: a neuron can belong to several different meta groups. Contrary to the primary ‘excitatory’ and ‘inhibitory’ groups, meta groups are therefore no necessarily disjoint. If all meta-groups have a name, they can be passed directly through a list; otherwise a dict is necessary.

See also

nest.Connect(), as()

excitatory#

Return the ids of all excitatory nodes inside the population.

New in version 1.3.

classmethod from_groups(groups, names=None, syn_spec=None, parent=None, meta_groups=None, with_models=True)[source]#

Make a NeuralPop object from a (list of) NeuralGroup object(s).

Parameters:
  • groups (list of NeuralGroup objects) – Groups that will be used to form the population. Note that a given neuron can only belong to a single group, so the groups should form pairwise disjoints complementary sets.
  • names (list of str, optional (default: None)) – Names that can be used as keys to retreive a specific group. If not provided, keys will be the group name (if not empty) or the position of the group in groups, stored as a string. In the latter case, the first group in a population named pop will be retreived by either pop[0] or pop[‘0’].
  • parent (Graph, optional (default: None)) – Parent if the population is created from an exiting graph.
  • syn_spec (dict, optional (default: static synapse)) – Dictionary containg a directed edge between groups as key and the associated synaptic parameters for the post-synaptic neurons (i.e. those of the second group) as value. If a ‘default’ entry is provided, all unspecified connections will be set to its value.
  • meta_groups (list or dict of str/NeuralGroup items) – Additional set of groups which can overlap: a neuron can belong to several different meta groups. Contrary to the primary groups, meta groups do therefore no need to be disjoint. If all meta-groups have a name, they can be passed directly through a list; otherwise a dict is necessary.
  • with_model (bool, optional (default: True)) – Whether the groups require models (set to False to use populations for graph theoretical purposes, without NEST interaction)

Example

For synaptic properties, if provided in syn_spec, all connections between groups will be set according to the values. Keys can be either group names or types (1 for excitatory, -1 for inhibitory). Because of this, several combination can be available for the connections between two groups. Because of this, priority is given to source (presynaptic properties), i.e. NNGT will look for the entry matching the first group name as source before looking for entries matching the second group name as target.

# we created groups `g1`, `g2`, and `g3`
prop = {
    ('g1', 'g2'): {'model': 'tsodyks2_synapse', 'tau_fac': 50.},
    ('g1', g3'): {'weight': 100.},
    ...
}
pop = NeuronalPop.from_groups(
    [g1, g2, g3], names=['g1', 'g2', 'g3'], syn_spec=prop)

Note

If the population is not generated from an existing Graph and the groups do not contain explicit ids, then the ids will be generated upon population creation: the first group, of size N0, will be associated the indices 0 to N0 - 1, the second group (size N1), will get N0 to N0 + N1 - 1, etc.

classmethod from_network(graph, *args)[source]#

Make a NeuralPop object from a network. The groups of neurons are determined using instructions from an arbitrary number of GroupProperties.

get_group(neurons, numbers=False)[source]#

Return the group of the neurons.

Parameters:
  • neurons (int or array-like) – IDs of the neurons for which the group should be returned.
  • numbers (bool, optional (default: False)) – Whether the group identifier should be returned as a number; if False, the group names are returned.
get_param(groups=None, neurons=None, element='neuron')[source]#

Return the element (neuron or synapse) parameters for neurons or groups of neurons in the population.

Parameters:
  • groups (str, int or array-like, optional (default: None)) – Names or numbers of the groups for which the neural properties should be returned.
  • neurons (int or array-like, optional (default: None)) – IDs of the neurons for which parameters should be returned.
  • element (list of str, optional (default: "neuron")) – Element for which the parameters should be returned (either "neuron" or "synapse").
Returns:

param (list) – List of all dictionaries with the elements’ parameters.

has_models#
ids#

Return all the ids of the nodes inside the population.

New in version 1.2.

inhibitory#

Return the ids of all inhibitory nodes inside the population.

New in version 1.3.

is_valid#

Whether the population can be used to create a NEST network.

meta_groups#
nest_gids#

Return the NEST gids of the nodes inside the population.

New in version 1.3.

parent#

Parent Network, if it exists, otherwise None.

set_model(model, group=None)[source]#

Set the groups’ models.

Parameters:
  • model (dict) – Dictionary containing the model type as key (“neuron” or “synapse”) and the model name as value (e.g. {“neuron”: “iaf_neuron”}).
  • group (list of strings, optional (default: None)) – List of strings containing the names of the groups which models should be updated.

Note

By default, synapses are registered as “static_synapse”s in NEST; because of this, only the neuron_model attribute is checked by the has_models function: it will answer True if all groups have a ‘non-None’ neuron_model attribute.

Warning

No check is performed on the validity of the models, which means that errors will only be detected when building the graph in NEST.

set_neuron_param(params, neurons=None, group=None)[source]#

Set the parameters of specific neurons or of a whole group.

New in version 1.0.

Parameters:
  • params (dict) – Dictionary containing parameters for the neurons. Entries can be either a single number (same for all neurons) or a list (one entry per neuron).
  • neurons (list of ints, optional (default: None)) – Ids of the neurons whose parameters should be modified.
  • group (list of strings, optional (default: None)) – List of strings containing the names of the groups whose parameters should be updated. When modifying neurons from a single group, it is still usefull to specify the group name to speed up the pace.

Note

If both neurons and group are None, all neurons will be modified.

Warning

No check is performed on the validity of the parameters, which means that errors will only be detected when building the graph in NEST.

size#

Number of neurons in this population.

syn_spec#

The properties of the synaptic connections between groups. Returns a dict containing tuples as keys and dicts of parameters as values.

The keys are tuples containing the names of the groups in the population, with the projecting group first (presynaptic neurons) and the receiving group last (post-synaptic neurons).

Example

For a population of excitatory (“exc”) and inhibitory (“inh”) neurons.

syn_spec = {
    ("exc", "exc"): {'model': 'stdp_synapse', 'weight': 2.5},
    ("exc", "inh"): {'model': 'static_synapse'},
    ("exc", "inh"): {'model': 'stdp_synapse', 'delay': 5.},
    ("inh", "inh"): {
        'model': 'stdp_synapse', 'weight': 5.,
        'delay': ('normal', 5., 2.)}
    }
}

New in version 0.8.

classmethod uniform(size, neuron_type=1, neuron_model='aeif_cond_alpha', neuron_param=None, syn_model='static_synapse', syn_param=None, parent=None, meta_groups=None)[source]#

Make a NeuralPop of identical neurons belonging to a single “default” group.

Changed in version 1.2: Added neuron_type and meta_groups parameters

Parameters:
  • size (int) – Number of neurons in the population.
  • neuron_type (int, optional (default: 1)) – Type of the neurons in the population: 1 for excitatory or -1 for inhibitory.
  • neuron_model (str, optional (default: default neuron model)) – Neuronal model for the simulator.
  • neuron_param (dict, optional (default: default neuron parameters)) – Parameters associated to neuron_model.
  • syn_model (str, optional (default: default static synapse)) – Synapse model for the simulator.
  • syn_param (dict, optional (default: default synaptic parameters)) – Parameters associated to syn_model.
  • parent (Graph object, optional (default: None)) – Parent graph described by the population.
  • meta_groups (list or dict of str/NeuralGroup items) – Set of groups which can overlap: a neuron can belong to several different meta groups, i.e. they do no need to be disjoint. If all meta-groups have a name, they can be passed directly through a list; otherwise a dict is necessary.