Main module

For more details regarding the main classes, see:

NNGT

Neural Networks Growth and Topology analyzing tool.

Provides algorithms for
  1. growing networks
  2. analyzing their activity
  3. studying the graph theoretical properties of those networks

Available subpackages

core
Contains the main network classes. These are loaded in nngt at import so specifying nngt.core is not necessary
generation
Functions to generate specific networks
lib
Basic functions used by several sub-packages.
io
@todo: Tools for input/output operations
nest
NEST integration tools
growth
@todo: Growing networks tools
plot
plot data or graphs (@todo) using matplotlib and graph_tool

Utilities

get_config
Show library _configuration
set_config
Set library _configuration (graph library, multithreading...)
version
NNGT version string

Units

Functions related to spatial embedding of networks are using milimeters (mm) as default unit; other units from the metric system can also be provided:

  • um for micrometers
  • cm centimeters
  • dm for decimeters
  • m for meters

Main classes and functions

class nngt.Connections[source]

The basic class that computes the properties of the connections between neurons for graphs.

static delays(graph=None, dlist=None, elist=None, distribution='constant', parameters=None, noise_scale=None)[source]

Compute the delays of the neuronal connections.

Parameters:
  • graph (class:~nngt.Graph or subclass) – Graph the nodes belong to.
  • dlist (class:numpy.array, optional (default: None)) – List of user-defined delays).
  • elist (class:numpy.array, optional (default: None)) – List of the edges which value should be updated.
  • distribution (class:string, optional (default: “constant”)) – Type of distribution (choose among “constant”, “uniform”, “lognormal”, “gaussian”, “user_def”, “lin_corr”, “log_corr”).
  • parameters (class:dict, optional (default: {})) – Dictionary containing the distribution parameters.
  • noise_scale (class:int, optional (default: None)) – Scale of the multiplicative Gaussian noise that should be applied on the weights.
Returns:

new_delays (class:scipy.sparse.lil_matrix) – A sparse matrix containing ONLY the newly-computed weights.

static distances(graph, elist=None, pos=None, dlist=None, overwrite=False)[source]

Compute the distances between connected nodes in the graph. Try to add only the new distances to the graph. If they overlap with previously computed distances, recomputes everything.

Parameters:
  • graph (class:~nngt.Graph or subclass) – Graph the nodes belong to.
  • elist (class:numpy.array, optional (default: None)) – List of the edges.
  • pos (class:numpy.array, optional (default: None)) – Positions of the nodes; note that if graph has a “position” attribute, pos will not be taken into account.
  • dlist (class:numpy.array, optional (default: None)) – List of distances (for user-defined distances)
Returns:

new_dist (class:numpy.array) – Array containing ONLY the newly-computed distances.

static types(graph, inhib_nodes=None, inhib_frac=None)[source]

@todo

Define the type of a set of neurons. If no arguments are given, all edges will be set as excitatory.

Parameters:
  • graph (Graph or subclass) – Graph on which edge types will be created.
  • inhib_nodes (int, float or list, optional (default: None)) – If inhib_nodes is an int, number of inhibitory nodes in the graph (all connections from inhibitory nodes are inhibitory); if it is a float, ratio of inhibitory nodes in the graph; if it is a list, ids of the inhibitory nodes.
  • inhib_frac (float, optional (default: None)) – Fraction of the selected edges that will be set as refractory (if inhib_nodes is not None, it is the fraction of the nodes’ edges that will become inhibitory, otherwise it is the fraction of all the edges in the graph).
Returns:

t_list (ndarray) – List of the edges’ types.

static weights(graph=None, elist=None, wlist=None, distribution='constant', parameters={}, noise_scale=None)[source]

Compute the weights of the graph’s edges. @todo: take elist into account

Parameters:
  • graph (class:~nngt.Graph or subclass) – Graph the nodes belong to.
  • elist (class:numpy.array, optional (default: None)) – List of the edges (for user defined weights).
  • wlist (class:numpy.array, optional (default: None)) – List of the weights (for user defined weights).
  • distribution (class:string, optional (default: “constant”)) – Type of distribution (choose among “constant”, “uniform”, “lognormal”, “gaussian”, “user_def”, “lin_corr”, “log_corr”).
  • parameters (class:dict, optional (default: {})) – Dictionary containing the distribution parameters.
  • noise_scale (class:int, optional (default: None)) – Scale of the multiplicative Gaussian noise that should be applied on the weights.
Returns:

new_weights (class:scipy.sparse.lil_matrix) – A sparse matrix containing ONLY the newly-computed weights.

nngt.generate(di_instructions, **kwargs)[source]

Generate a Graph or one of its subclasses from a dict containing all the relevant informations.

Parameters:
  • di_instructions (dict) – Dictionary containing the instructions to generate the graph. It must have at least "graph_type" in its keys, with a value among "distance_rule", "erdos_renyi", "fixed_degree", "newman_watts", "price_scale_free", "random_scale_free". Depending on the type, di_instructions should also contain at least all non-optional arguments of the generator function.
  • .. seealso – Generator functions are detailed in generation.
class nngt.Graph(nodes=0, name='Graph', weighted=True, directed=True, from_graph=None, **kwargs)[source]

The basic class that contains a graph_tool.Graph and some of is properties or methods to easily access them.

Initialize Graph instance

Parameters:
  • nodes (int, optional (default: 0)) – Number of nodes in the graph.
  • name (string, optional (default: “Graph”)) – The name of this Graph instance.
  • weighted (bool, optional (default: True)) – Whether the graph edges have weight properties.
  • directed (bool, optional (default: True)) – Whether the graph is directed or undirected.
  • from_graph (GraphObject, optional) – An optional GraphObject to serve as base.
  • kwargs (optional keywords arguments) – Optional arguments that can be passed to the graph, e.g. a dict containing information on the synaptic weights (weights={"distribution": "constant", "value": 2.3} which is equivalent to weights=2.3), the synaptic delays, or a type information.
Returns:

self (Graph)

attributes(edge=None, name=None)[source]

Attributes of the graph’s edges.

Parameters:
  • edge (tuple, optional (default: None)) – Edge whose attribute should be displayed.
  • name (str, optional (default: None)) – Name of the desired attribute.
Returns:

  • List containing the names of the graph’s attributes (synaptic weights,
  • delays...) if edge is None, else a dict containing the
  • attributes of the edge (or the value of attribute name if it is not
  • None).

copy()[source]

Returns a deepcopy of the current Graph instance

edge_attribute

Access edge attributes

static from_file(filename, format='auto', delimiter=' ', secondary=';', attributes=None, notifier='@', ignore='#', from_string=False)[source]

Import a saved graph from a file. @todo: implement population and shape loading, implement gml, dot, xml, gt

Parameters:
  • filename (str) – The path to the file.
  • format (str, optional (default: “neighbour”)) – The format used to save the graph. Supported formats are: “neighbour” (neighbour list, default if format cannot be deduced automatically), “ssp” (scipy.sparse), “edge_list” (list of all the edges in the graph, one edge per line, represented by a source target-pair), “gml” (gml format, default if filename ends with ‘.gml’), “graphml” (graphml format, default if filename ends with ‘.graphml’ or ‘.xml’), “dot” (dot format, default if filename ends with ‘.dot’), “gt” (only when using graph_tool`<http://graph-tool.skewed.de/>_ as library, detected if `filename ends with ‘.gt’).
  • delimiter (str, optional (default ” ”)) – Delimiter used to separate inputs in the case of custom formats (namely “neighbour” and “edge_list”)
  • secondary (str, optional (default: ”;”)) – Secondary delimiter used to separate attributes in the case of custom formats.
  • attributes (list, optional (default: [])) – List of names for the attributes present in the file. If a notifier is present in the file, names will be deduced from it; otherwise the attributes will be numbered.
  • notifier (str, optional (default: “@”)) – Symbol specifying the following as meaningfull information. Relevant information is formatted @info_name=info_value, where info_name is in (“attributes”, “directed”, “name”, “size”) and associated info_value``s are of type (``list, bool, str, int). Additional notifiers are @type=SpatialGraph/Network/ SpatialNetwork, which must be followed by the relevant notifiers among @shape, @population, and @graph.
  • from_string (bool, optional (default: False)) – Load from a string instead of a file.
Returns:

graph (Graph or subclass) – Loaded graph.

classmethod from_matrix(matrix, weighted=True, directed=True)[source]

Creates a Graph from a scipy.sparse matrix or a dense matrix.

Parameters:
  • matrix (scipy.sparse matrix or numpy.array) – Adjacency matrix.
  • weighted (bool, optional (default: True)) – Whether the graph edges have weight properties.
  • directed (bool, optional (default: True)) – Whether the graph is directed or undirected.
Returns:

Graph

get_attribute_type(attribute_name)[source]

Return the type of an attribute

get_betweenness(btype='both', use_weights=False)[source]

Betweenness centrality sequence of all nodes and edges.

Parameters:
  • btype (str, optional (default: "both")) – Type of betweenness to return ("edge", "node"-betweenness, or "both").
  • use_weights (bool, optional (default: False)) – Whether to use weighted (True) or simple degrees (False).
Returns:

  • node_betweenness (numpy.array) – Betweenness of the nodes (if btype is "node" or "both").
  • edge_betweenness (numpy.array) – Betweenness of the edges (if btype is "edge" or "both").

get_degrees(deg_type='total', node_list=None, use_weights=False)[source]

Degree sequence of all the nodes.

Parameters:
  • deg_type (string, optional (default: “total”)) – Degree type (among ‘in’, ‘out’ or ‘total’).
  • node_list (list, optional (default: None)) – List of the nodes which degree should be returned
  • use_weights (bool, optional (default: False)) – Whether to use weighted (True) or simple degrees (False).
Returns:

numpy.array or None (if an invalid type is asked).

get_delays()[source]

Returns the delay adjacency matrix as a scipy.sparse.lil_matrix if delays are present; else raises an error.

get_density()[source]

Density of the graph: \(\frac{E}{N^2}\), where E is the number of edges and N the number of nodes.

get_graph_type()[source]

Return the type of the graph (see nngt.generation)

get_name()[source]

Get the name of the graph

get_weights()[source]

Returns the weighted adjacency matrix as a scipy.sparse.lil_matrix.

graph_id

Unique int identifying the instance.

is_directed()[source]

Whether the graph is directed or not

is_network()[source]

Whether the graph is a subclass of Network (i.e. if it has a NeuralPop attribute).

is_spatial()[source]

Whether the graph is embedded in space (i.e. if it has a Shape attribute). Returns True is the graph is a subclass of SpatialGraph.

is_weighted()[source]

Whether the edges have weights

static make_network(graph, neural_pop, copy=False, **kwargs)[source]

Turn a Graph object into a Network, or a SpatialGraph into a SpatialNetwork.

Parameters:
  • graph (Graph or SpatialGraph) – Graph to convert
  • neural_pop (NeuralPop) – Population to associate to the new Network
  • copy (bool, optional (default: False)) – Whether the operation should be made in-place on the object or if a new object should be returned.

Notes

In-place operation that directly converts the original graph if copy is False, else returns the copied Graph turned into a Network.

static make_spatial(graph, shape, positions=None, copy=False)[source]

Turn a Graph object into a SpatialGraph, or a Network into a SpatialNetwork.

Parameters:
  • graph (Graph or SpatialGraph) – Graph to convert.
  • shape (Shape, optional) – Shape to associate to the new SpatialGraph.
  • positions ((N, 2) array) – Positions, in a 2D space, of the N neurons.
  • copy (bool, optional (default: False)) – Whether the operation should be made in-place on the object or if a new object should be returned.

Notes

In-place operation that directly converts the original graph if copy is False, else returns the copied Graph turned into a SpatialGraph.

name

Name of the graph.

node_attributes

Access node attributes

classmethod num_graphs()[source]

Returns the number of alive instances.

set_delays(delay=None, elist=None, distribution=None, parameters=None, noise_scale=None)[source]

Set the delay for spike propagation between neurons. ..todo :: take elist into account in Connections.delays

Parameters:
  • delay (float or class:numpy.array, optional (default: None)) – Value or list of delays (for user defined delays).
  • elist (class:numpy.array, optional (default: None)) – List of the edges (for user defined delays).
  • distribution (class:string, optional (default: None)) – Type of distribution (choose among “constant”, “uniform”, “gaussian”, “lognormal”, “lin_corr”, “log_corr”).
  • parameters (dict, optional (default: {})) – Dictionary containing the properties of the delay distribution.
  • noise_scale (class:int, optional (default: None)) – Scale of the multiplicative Gaussian noise that should be applied on the delays.
set_edge_attribute(attribute, values=None, val=None, value_type=None, edges=None)[source]

Set attributes to the connections between neurons.

Warning

The special “type” attribute cannot be modified when using graphs that inherit from the Network class. This is because for biological networks, neurons make only one kind of synapse, which is determined by the nngt.NeuralGroup they belong to.

set_name(name='')[source]

set graph name

set_types(syn_type, nodes=None, fraction=None)[source]

Set the synaptic/connection types.

Warning

The special “type” attribute cannot be modified when using graphs that inherit from the Network class. This is because for biological networks, neurons make only one kind of synapse, which is determined by the nngt.NeuralGroup they belong to.

Parameters:
  • syn_type (int or string) – Type of the connection among ‘excitatory’ (also 1) or ‘inhibitory’ (also -1).
  • nodes (int, float or list, optional (default: None)) – If nodes is an int, number of nodes of the required type that will be created in the graph (all connections from inhibitory nodes are inhibitory); if it is a float, ratio of syn_type nodes in the graph; if it is a list, ids of the syn_type nodes.
  • fraction (float, optional (default: None)) – Fraction of the selected edges that will be set as syn_type (if nodes is not None, it is the fraction of the specified nodes’ edges, otherwise it is the fraction of all edges in the graph).
Returns:

t_list (numpy.ndarray) – List of the types in an order that matches the edges attribute of the graph.

set_weights(weight=None, elist=None, distribution=None, parameters=None, noise_scale=None)[source]

Set the synaptic weights.

..todo ::
take elist into account in Connections.weights
Parameters:
  • weight (float or class:numpy.array, optional (default: None)) – Value or list of the weights (for user defined weights).
  • elist (class:numpy.array, optional (default: None)) – List of the edges (for user defined weights).
  • distribution (class:string, optional (default: None)) – Type of distribution (choose among “constant”, “uniform”, “gaussian”, “lognormal”, “lin_corr”, “log_corr”).
  • parameters (dict, optional (default: {})) – Dictionary containing the properties of the weight distribution.
  • noise_scale (class:int, optional (default: None)) – Scale of the multiplicative Gaussian noise that should be applied on the weights.
to_file(filename, format='auto', delimiter=' ', secondary=';', attributes=None, notifier='@')[source]

Save graph to file; options detailed below.

See also

nngt.lib.save_to_file() function for options.

type

Type of the graph.

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 GraphClass or one of its subclasses.

Variables:
  • sizeint Size of the group.
  • constraintsdict, optional (default: {}) Constraints to respect when building the NeuralGroup .
  • neuron_modelstring, optional (default: None) name of the model to use when simulating the activity of this group.
  • neuron_paramdict, 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.Network(name='Network', weighted=True, directed=True, from_graph=None, population=None, **kwargs)[source]

The detailed class that inherits from Graph and implements additional properties to describe various biological functions and interact with the NEST simulator.

Initializes Network instance.

Parameters:
  • nodes (int, optional (default: 0)) – Number of nodes in the graph.
  • name (string, optional (default: “Graph”)) – The name of this Graph instance.
  • weighted (bool, optional (default: True)) – Whether the graph edges have weight properties.
  • directed (bool, optional (default: True)) – Whether the graph is directed or undirected.
  • from_graph (GraphObject, optional (default: None)) – An optional GraphObject to serve as base.
  • population (nngt.NeuralPop, (default: None)) – An object containing the neural groups and their properties: model(s) to use in NEST to simulate the neurons as well as their parameters.
Returns:

self (Network)

classmethod ei_network(size, ei_ratio=0.2, en_model='aeif_cond_alpha', en_param=None, es_model='static_synapse', es_param=None, in_model='aeif_cond_alpha', in_param=None, is_model='static_synapse', is_param=None)[source]

Generate a network containing a population of two neural groups: inhibitory and excitatory neurons.

Parameters:
  • size (int) – Number of neurons in the network.
  • ei_ratio (double, optional (default: 0.2)) – Ratio of inhibitory neurons: \(\frac{N_i}{N_e+N_i}\).
  • en_model (string, optional (default: ‘aeif_cond_alpha’)) – Nest model for the excitatory neuron.
  • en_param (dict, optional (default: {})) – Dictionary of parameters for the the excitatory neuron.
  • es_model (string, optional (default: ‘static_synapse’)) – NEST model for the excitatory synapse.
  • es_param (dict, optional (default: {})) – Dictionary containing the excitatory synaptic parameters.
  • in_model (string, optional (default: ‘aeif_cond_alpha’)) – Nest model for the inhibitory neuron.
  • in_param (dict, optional (default: {})) – Dictionary of parameters for the the inhibitory neuron.
  • is_model (string, optional (default: ‘static_synapse’)) – NEST model for the inhibitory synapse.
  • is_param (dict, optional (default: {})) – Dictionary containing the inhibitory synaptic parameters.
Returns:

net (Network or subclass) – Network of disconnected excitatory and inhibitory neurons.

get_neuron_type(neuron_ids)[source]

Return the type of the neurons (+1 for excitatory, -1 for inhibitory).

Parameters:neuron_ids (int or tuple) – NEST gids.
Returns:ids (int or tuple) – Ids in the network. Same type as the requested gids type.
id_from_nest_gid(gids)[source]

Return the ids of the nodes in the nngt.Network instance from the corresponding NEST gids.

Parameters:gids (int or tuple) – NEST gids.
Returns:ids (int or tuple) – Ids in the network. Same type as the requested gids type.
neuron_properties(idx_neuron)[source]

Properties of a neuron in the graph.

Parameters:idx_neuron (int) – Index of a neuron in the graph.
Returns:dict of the neuron’s properties.
classmethod num_networks()[source]

Returns the number of alive instances.

population

NeuralPop that divides the neurons into groups with specific properties.

to_nest(use_weights=True)[source]

Send the network to NEST.

See also

make_nest_network() for parameters

classmethod uniform_network(size, neuron_model='aeif_cond_alpha', neuron_param=None, syn_model='static_synapse', syn_param=None)[source]

Generate a network containing only one type of neurons.

Parameters:
  • size (int) – Number of neurons in the network.
  • neuron_model (string, optional (default: ‘aief_cond_alpha’)) – Name of the NEST neural model to use when simulating the activity.
  • neuron_param (dict, optional (default: {})) – Dictionary containing the neural parameters; the default value will make NEST use the default parameters of the model.
  • syn_model (string, optional (default: ‘static_synapse’)) – NEST synaptic model to use when simulating the activity.
  • syn_param (dict, optional (default: {})) – Dictionary containing the synaptic parameters; the default value will make NEST use the default parameters of the model.
Returns:

net (Network or subclass) – Uniform network of disconnected neurons.

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

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

Variables:has_modelsbool, True if every group has a model attribute.

Initialize NeuralPop instance

Parameters:
  • size (int) – Number of neurons that the population will contain.
  • parent (Network, optional (default: None)) – Network associated to this population.
  • with_models (bool) – whether the population’s groups contain models to use in NEST
  • **kwargs (dict)
Returns:

pop (NeuralPop object.)

classmethod copy(pop)[source]

Copy an existing NeuralPop

create_group(name, neurons, ntype=1, neuron_model=None, neuron_param=None, syn_model='static_synapse', syn_param=None)[source]

Create a new groupe from given properties.

Parameters:
  • name (str) – Name of the group.
  • neurons (array-like) – List of the neurons indices.
  • ntype (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.
  • syn_model (str, optional (default: “static_synapse”)) – Name of a synapse model in NEST.
  • syn_param (dict, optional (default: None)) – Parameters for syn_model in the NEST simulator. If None, default parameters will be used.
classmethod exc_and_inhib(size, iratio=0.2, parent=None, en_model='aeif_cond_alpha', en_param={}, es_model='static_synapse', es_param={}, in_model='aeif_cond_alpha', in_param={}, is_model='static_synapse', is_param={})[source]

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

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

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

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.

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_param(param, group=None)[source]

Set the groups’ parameters.

Parameters:
  • param (dict) – Dictionary containing the model type as key (“neuron” or “synapse”) and the model parameter as value (e.g. {“neuron”: {“C_m”: 125.}}).
  • group (list of strings, optional (default: None)) – List of strings containing the names of the groups which models should be updated.
  • .. 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.
classmethod uniform(size, parent=None, neuron_model='aeif_cond_alpha', neuron_param=None, syn_model='static_synapse', syn_param=None)[source]

Make a NeuralPop of identical neurons

nngt.seed(seed=None)[source]

Seed the random generator used by NNGT (i.e. the numpy RandomState: for details, see numpy.random.RandomState).

Parameters:seed (int or array_like, optional) – Seed for RandomState. Must be convertible to 32 bit unsigned integers.
nngt.set_config(config, value=None)[source]

Set NNGT’s configuration.

Parameters:
  • config (dict or str) – Either a full configuration dictionary or one key to be set together with its associated value.
  • value (object, optional (default: None)) – Value associated to config if config is a key.

Examples

>>> nngt.set_config({'multithreading': True, 'omp': 4})
>>> nngt.set_config('multithreading', False)

Note

See the config file nngt/nngt.conf.default or ~/.nngt/nngt.conf for details about your configuration.

See also

get_config()

class nngt.SpatialGraph(nodes=0, name='Graph', weighted=True, directed=True, from_graph=None, shape=None, positions=None, **kwargs)[source]

The detailed class that inherits from Graph and implements additional properties to describe spatial graphs (i.e. graph where the structure is embedded in space.

Initialize SpatialClass instance. .. todo:: see what we do with the from_graph argument

Parameters:
  • nodes (int, optional (default: 0)) – Number of nodes in the graph.
  • name (string, optional (default: “Graph”)) – The name of this Graph instance.
  • weighted (bool, optional (default: True)) – Whether the graph edges have weight properties.
  • directed (bool, optional (default: True)) – Whether the graph is directed or undirected.
  • shape (Shape, optional (default: None)) – Shape of the neurons’ environment (None leads to a square of side 1 cm)
  • positions (numpy.array (N, 2), optional (default: None)) – Positions of the neurons; if not specified and nodes is not 0, then neurons will be reparted at random inside the Shape object of the instance.
Returns:

self (SpatialGraph)

get_positions(neurons=None)[source]

Returns the neurons’ positions as a (N, 2) array.

Parameters:neurons (int or array-like, optional (default: all neurons)) – List of the neurons for which the position should be returned.
class nngt.SpatialNetwork(population, name='Graph', weighted=True, directed=True, shape=None, from_graph=None, positions=None, **kwargs)[source]

Class that inherits from Network and SpatialGraph to provide a detailed description of a real neural network in space, i.e. with positions and biological properties to interact with NEST.

Initialize Graph instance

Parameters:
  • name (string, optional (default: “Graph”)) – The name of this Graph instance.
  • weighted (bool, optional (default: True)) – Whether the graph edges have weight properties.
  • directed (bool, optional (default: True)) – Whether the graph is directed or undirected.
  • shape (Shape, optional (default: None)) – Shape of the neurons’ environment (None leads to a square of side 1 cm)
  • positions (numpy.array, optional (default: None)) – Positions of the neurons; if not specified and nodes != 0, then neurons will be reparted at random inside the Shape object of the instance.
  • population (class:~nngt.NeuralPop, optional (default: None))
Returns:

self (SpatialNetwork)

nngt.use_library(library, reloading=True)[source]

Allows the user to switch to a specific graph library.

Parameters:
  • library (string) – Name of a graph library among ‘graph_tool’, ‘igraph’, ‘networkx’.
  • reload_moduleing (bool, optional (default: True)) – Whether the graph objects should be reload_moduleed (this should always be set to True except when NNGT is first initiated!)