Graph classes#
-
class
nngt.
Graph
(nodes=0, name='Graph', weighted=True, directed=True, from_graph=None, **kwargs)[source]# The basic graph class, which inherits from a library class such as
gt.Graph
,networkx.DiGraph
, or igraph.Graph.The objects provides several functions to easily access some basic properties.
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 optionalGraphObject
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 toweights=2.3
), the synaptic delays, or atype
information.
Returns: self (
Graph
)-
adjacency_matrix
(types=True, weights=True)# Return the graph adjacency matrix. NB : source nodes are represented by the rows, targets by the corresponding columns.
Parameters: - types (bool, optional (default: True)) – Wether the edge types should be taken into account (negative values for inhibitory connections).
- weights (bool or string, optional (default: True)) – Whether the adjacecy matrix should be weighted. If True, all connections are multiply bythe associated synaptic strength; if weight is a string, the connections are scaled bythe corresponding edge attribute.
Returns: mat (
scipy.sparse.csr
matrix) – The adjacency matrix of the graph.
-
clear_all_edges
()# Remove all edges from the graph
-
edge_id
(edge)# Return the ID a given edge or a list of edges in the graph. Raises an error if the edge is not in the graph or if one of the vertices in the edge is nonexistent.
Parameters: edge (2-tuple or array of edges) – Edge descriptor (source, target). Returns: index (int or array of ints) – Index of the given edge.
-
edge_nb
()# Number of edges in the graph
-
edges_array
# Edges of the graph, sorted by order of creation, as an array of 2-tuple.
-
edges_attributes
# Access edge attributes
New in version 0.7.
-
static
from_file
(filename, fmt='auto', separator=' ', 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.
- fmt (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’). - separator (str, optional (default ” “)) – separator used to separate inputs in the case of custom formats (namely “neighbour” and “edge_list”)
- secondary (str, optional (default: “;”)) – Secondary separator 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. This argument can also be used to load only a subset of the saved attributes.
- notifier (str, optional (default: “@”)) – Symbol specifying the following as meaningfull information.
Relevant information is formatted
@info_name=info_value
, whereinfo_name
is in (“attributes”, “directed”, “name”, “size”) and associatedinfo_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 ascipy.sparse
matrix or a dense matrix.Parameters: - matrix (
scipy.sparse
matrix ornumpy.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: - matrix (
-
get_attribute_type
(attribute_name, attribute_class=None)[source]# Return the type of an attribute (e.g. string, double, int).
Changed in version 1.0: Added attribute_class parameter.
Parameters: - attribute_name (str) – Name of the attribute.
- attribute_class (str, optional (default: both)) – Whether attribute_name is a “node” or an “edge” attribute.
Returns: type (str) – Type of the 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"
).
- btype (str, optional (default:
-
get_degrees
(deg_type='total', node_list=None, use_weights=False, syn_type='all')[source]# Degree sequence of all the nodes.
- ..versionchanged :: 0.9
- Added syn_type keyword.
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).
- syn_type (int or str, optional (default: all)) – Restrict to a given synaptic type (“excitatory”, 1, or “inhibitory”, -1).
Returns: numpy.array
or None (if an invalid type is asked).
-
get_delays
(edges=None)[source]# Returns the delays of all or a subset of the edges.
Changed in version 1.0.1: Added the possibility to ask for a subset of edges.
Parameters: edges ((E, 2) array, optional (default: all edges)) – Edges for which the type should be returned. Returns: the list of delays
-
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_edge_attributes
(edges=None, name=None)[source]# Attributes of the graph’s edges.
Changed in version 1.0: Returns the full dict of edges attributes if called without arguments.
New in version 0.8.
Parameters: - edge (tuple or list of tuples, optional (default:
None
)) – Edge whose attribute should be displayed. - name (str, optional (default:
None
)) – Name of the desired attribute.
Returns: - Dict containing all graph’s attributes (synaptic weights, delays…)
- by default. If edge is specified, returns only the values for these
- edges. If name is specified, returns value of the attribute for each
- edge.
Note
The attributes values are ordered as the edges in
edges_array()
.- edge (tuple or list of tuples, optional (default:
-
get_edge_types
(edges=None)[source]# Return the type of all or a subset of the edges.
Changed in version 1.0.1: Added the possibility to ask for a subset of edges.
Parameters: edges ((E, 2) array, optional (default: all edges)) – Edges for which the type should be returned. Returns: the list of types (1 for excitatory, -1 for inhibitory)
-
get_node_attributes
(nodes=None, name=None)[source]# Attributes of the graph’s edges.
Changed in version 1.0.1: Corrected default behavior and made it the same as
get_edge_attributes()
.New in version 0.9.
Parameters: - nodes (list of ints, optional (default:
None
)) – Nodes whose attribute should be displayed. - name (str, optional (default:
None
)) – Name of the desired attribute.
Returns: - Dict containing all nodes attributes by default. If nodes is
- specified, returns a
dict
containing only the attributes of these - nodes. If name is specified, returns a list containing the values of
- the specific attribute for the required nodes (or all nodes if
- unspecified).
- nodes (list of ints, optional (default:
-
get_weights
(edges=None)[source]# Returns the weights of all or a subset of the edges.
Changed in version 1.0.1: Added the possibility to ask for a subset of edges.
Parameters: edges ((E, 2) array, optional (default: all edges)) – Edges for which the type should be returned. Returns: the list of weights
-
is_multigraph
()# Return True if graph is a multigraph, False otherwise.
-
is_network
()[source]# Whether the graph is a subclass of
Network
(i.e. if it has aNeuralPop
attribute).
-
is_spatial
()[source]# Whether the graph is embedded in space (i.e. if it has a
Shape
attribute). ReturnsTrue
is the graph is a subclass ofSpatialGraph
.
-
static
make_network
(graph, neural_pop, copy=False, **kwargs)[source]# Turn a
Graph
object into aNetwork
, or aSpatialGraph
into aSpatialNetwork
.Parameters: - graph (
Graph
orSpatialGraph
) – Graph to convert - neural_pop (
NeuralPop
) – Population to associate to the newNetwork
- 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 copiedGraph
turned into aNetwork
.- graph (
-
static
make_spatial
(graph, shape=None, positions=None, copy=False)[source]# Turn a
Graph
object into aSpatialGraph
, or aNetwork
into aSpatialNetwork
.Parameters: - graph (
Graph
orSpatialGraph
) – Graph to convert. - shape (
Shape
, optional (default: None)) – Shape to associate to the newSpatialGraph
. - 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 copiedGraph
turned into aSpatialGraph
. The shape argument can be skipped if positions are given; in that case, the neurons will be embedded in a rectangle that contains them all.- graph (
-
name
# Name of the graph.
-
neighbours
(node, mode='all')# Return the neighbours of node.
Parameters: - node (int) – Index of the node of interest.
- mode (string, optional (default: “all”)) – Type of neighbours that will be returned: “all” returns all the neighbours regardless of directionality, “in” returns the in-neighbours (also called predecessors) and “out” retruns the out-neighbours (or successors).
Returns: neighbours (tuple) – The neighbours of node.
-
new_edge
(source, target, attributes=None, ignore=False)# Adding a connection to the graph, with optional properties.
Parameters: - source (
int/node
) – Source node. - target (
int/node
) – Target node. - attributes (
dict
, optional (default:{}
)) – Dictionary containing optional edge properties. If the graph is weighted, defaults to{"weight": 1.}
, the unit weight for the connection (synaptic strength in NEST). - ignore (bool, optional (default: False)) – If set to True, ignore attempts to add an existing edge, otherwise raises an error.
Returns: The new connection.
- source (
-
new_edge_attribute
(name, value_type, values=None, val=None)[source]# Create a new attribute for the edges.
New in version 0.7.
Parameters: - name (str) – The name of the new attribute.
- value_type (str) – Type of the attribute, among ‘int’, ‘double’, ‘string’
- values (array, optional (default: None)) – Values with which the edge attribute should be initialized. (must have one entry per node in the graph)
- val (int, float or str , optional (default: None)) – Identical value for all edges.
-
new_edges
(edge_list, attributes=None, check_edges=True)# Add a list of edges to the graph.
Changed in version 1.0: new_edges checks for duplicate edges and self-loops
Warning
This function currently does not check for duplicate edges between the existing edges and the added ones, but only inside edge_list!
Parameters: - edge_list (list of 2-tuples or np.array of shape (edge_nb, 2)) – List of the edges that should be added as tuples (source, target)
- attributes (
dict
, optional (default:{}
)) – Dictionary containing optional edge properties. If the graph is weighted, defaults to{"weight": ones}
, whereones
is an array the same length as the edge_list containing a unit weight for each connection (synaptic strength in NEST). - check_edges (bool, optional (default: True)) – Check for duplicate edges and self-loops.
- @todo (add example)
Returns: Returns new edges only.
-
new_node
(n=1, ntype=1, attributes=None, value_types=None, positions=None, groups=None)# Adding a node to the graph, with optional properties.
Parameters: - n (int, optional (default: 1)) – Number of nodes to add.
- ntype (int, optional (default: 1)) – Type of neuron (1 for excitatory, -1 for inhibitory)
Returns: The node or a list of the nodes created.
-
new_node_attribute
(name, value_type, values=None, val=None)[source]# Create a new attribute for the nodes.
New in version 0.7.
Parameters: - name (str) – The name of the new attribute.
- value_type (str) – Type of the attribute, among ‘int’, ‘double’, ‘string’
- values (array, optional (default: None)) – Values with which the node attribute should be initialized. (must have one entry per node in the graph)
- val (int, float or str , optional (default: None)) – Identical value for all nodes.
-
node_nb
()# Number of nodes in the graph
-
nodes_attributes
# Access node attributes
New in version 0.7.
-
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 thenngt.NeuralGroup
they belong to.Parameters: - attribute (str) – The name of the attribute.
- value_type (str) – Type of the attribute, among ‘int’, ‘double’, ‘string’
- values (array, optional (default: None)) – Values with which the edge attribute should be initialized. (must have one entry per node in the graph)
- val (int, float or str , optional (default: None)) – Identical value for all edges.
- value_type (str, optional (default: None)) – Type of the attribute, among ‘int’, ‘double’, ‘string’. Only used if the attribute does not exist and must be created.
- edges (list of edges or array of shape (E, 2), optional (default: all)) – Edges whose attributes should be set. Others will remain unchanged.
-
set_node_attribute
(attribute, values=None, val=None, value_type=None, nodes=None)[source]# Set attributes to the connections between neurons.
New in version 0.9.
Parameters: - attribute (str) – The name of the attribute.
- value_type (str) – Type of the attribute, among ‘int’, ‘double’, ‘string’
- values (array, optional (default: None)) – Values with which the edge attribute should be initialized. (must have one entry per node in the graph)
- val (int, float or str , optional (default: None)) – Identical value for all edges.
- value_type (str, optional (default: None)) – Type of the attribute, among ‘int’, ‘double’, ‘string’. Only used if the attribute does not exist and must be created.
- nodes (list of nodes, optional (default: all)) – Nodes whose attributes should be set. Others will remain unchanged.
-
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 thenngt.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. Properties are as follow for the distributions
- ‘constant’: ‘value’
- ‘uniform’: ‘lower’, ‘upper’
- ‘gaussian’: ‘avg’, ‘std’
- ‘lognormal’: ‘position’, ‘scale’
noise_scale (class:int, optional (default: None)) – Scale of the multiplicative Gaussian noise that should be applied on the weights.
-
to_directed_class
()[source]# Returns the class to use for empty directed copies.
If you subclass the base classes, use this to designate what directed class to use for to_directed() copies.
-
to_file
(filename, fmt='auto', separator=' ', secondary=';', attributes=None, notifier='@')[source]# Save graph to file; options detailed below.
See also
nngt.lib.save_to_file()
function for options.
-
to_undirected_class
()[source]# Returns the class to use for empty undirected copies.
If you subclass the base classes, use this to designate what directed class to use for to_directed() copies.
-
type
# Type of the graph.
-
update
(edges=None, nodes=None)[source]# Update the graph using nodes/edges/graphs as input.
Like dict.update, this method takes a graph as input, adding the graph’s noes and edges to this graph. It can also take two inputs: edges and nodes. Finally it can take either edges or nodes. To specify only nodes the keyword nodes must be used.
The collections of edges and nodes are treated similarly to the add_edges_from/add_nodes_from methods. When iterated, they should yield 2-tuples (u, v) or 3-tuples (u, v, datadict).
Parameters: - edges (Graph object, collection of edges, or None) – The first parameter can be a graph or some edges. If it has attributes nodes and edges, then it is taken to be a Graph-like object and those attributes are used as collections of nodes and edges to be added to the graph. If the first parameter does not have those attributes, it is treated as a collection of edges and added to the graph. If the first argument is None, no edges are added.
- nodes (collection of nodes, or None) – The second parameter is treated as a collection of nodes to be added to the graph unless it is None. If edges is None and nodes is None an exception is raised. If the first parameter is a Graph, then nodes is ignored.
Examples
>>> G = nx.path_graph(5) >>> G.update(nx.complete_graph(range(4,10))) >>> from itertools import combinations >>> edges = ((u, v, {'power': u * v}) ... for u, v in combinations(range(10, 20), 2) ... if u * v < 225) >>> nodes = [1000] # for singleton, use a container >>> G.update(edges, nodes)
Notes
It you want to update the graph using an adjacency structure it is straightforward to obtain the edges/nodes from adjacency. The following examples provide common cases, your adjacency may be slightly different and require tweaks of these examples.
>>> # dict-of-set/list/tuple >>> adj = {1: {2, 3}, 2: {1, 3}, 3: {1, 2}} >>> e = [(u, v) for u, nbrs in adj.items() for v in nbrs] >>> G.update(edges=e, nodes=adj)
>>> DG = nx.DiGraph() >>> # dict-of-dict-of-attribute >>> adj = {1: {2: 1.3, 3: 0.7}, 2: {1: 1.4}, 3: {1: 0.7}} >>> e = [(u, v, {'weight': d}) for u, nbrs in adj.items() ... for v, d in nbrs.items()] >>> DG.update(edges=e, nodes=adj)
>>> # dict-of-dict-of-dict >>> adj = {1: {2: {'weight': 1.3}, 3: {'color': 0.7, 'weight':1.2}}} >>> e = [(u, v, {'weight': d}) for u, nbrs in adj.items() ... for v, d in nbrs.items()] >>> DG.update(edges=e, nodes=adj)
>>> # predecessor adjacency (dict-of-set) >>> pred = {1: {2, 3}, 2: {3}, 3: {3}} >>> e = [(v, u) for u, nbrs in pred.items() for v in nbrs]
>>> # MultiGraph dict-of-dict-of-dict-of-attribute >>> MDG = nx.MultiDiGraph() >>> adj = {1: {2: {0: {'weight': 1.3}, 1: {'weight': 1.2}}}, ... 3: {2: {0: {'weight': 0.7}}}} >>> e = [(u, v, ekey, d) for u, nbrs in adj.items() ... for v, keydict in nbrs.items() ... for ekey, d in keydict.items()] >>> MDG.update(edges=e)
See also
add_edges_from()
- add multiple edges to a graph
add_nodes_from()
- add multiple nodes to a graph
-
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 theShape
object of the instance. - **kwargs (keyword arguments for
Graph
or) –Shape
if no shape was given.
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.
-
shape
#
-
class
nngt.
Network
(name='Network', weighted=True, directed=True, from_graph=None, population=None, inh_weight_factor=1.0, **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 optionalGraphObject
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. - inh_weight_factor (float, optional (default: 1.)) – Factor to apply to inhibitory synapses, to compensate for example the strength difference due to timescales between excitatory and inhibitory synapses.
Returns: self (
Network
)-
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, **kwargs)[source]# Generate a network containing a population of two neural groups: inhibitory and excitatory neurons.
New in version 1.0.
Changed in version 0.8: Removed es_{model, param} and is_{model, param} in favour of syn_spec parameter. Renamed ei_ratio to iratio to match
exc_and_inhib()
.Parameters: size (int) – Number of neurons in the network.
i_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.
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.
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’)
Returns: net (
Network
or subclass) – Network of disconnected excitatory and inhibitory neurons.See also
-
classmethod
from_gids
(gids, get_connections=True, get_params=False, neuron_model='aeif_cond_alpha', neuron_param=None, syn_model='static_synapse', syn_param=None, **kwargs)[source]# Generate a network from gids.
Warning
Unless get_connections and get_params is True, or if your population is homogeneous and you provide the required information, the information contained by the network and its population attribute will be erroneous! To prevent conflicts the
to_nest()
function is not available. If you know what you are doing, you should be able to find a workaround…Parameters: - gids (array-like) – Ids of the neurons in NEST or simply user specified ids.
- get_params (bool, optional (default: True)) – Whether the parameters should be obtained from NEST (can be very slow).
- neuron_model (string, optional (default: None)) – 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.
-
get_edge_types
()[source]# Return the type of all or a subset of the edges.
Changed in version 1.0.1: Added the possibility to ask for a subset of edges.
Parameters: edges ((E, 2) array, optional (default: all edges)) – Edges for which the type should be returned. Returns: the list of types (1 for excitatory, -1 for inhibitory)
-
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.
-
nest_gid
#
-
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.
-
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 thenngt.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.
-
to_nest
(send_only=None, use_weights=True)[source]# Send the network to NEST.
See also
make_nest_network()
for parameters
-
classmethod
uniform
(size, neuron_model='aeif_cond_alpha', neuron_param=None, syn_model='static_synapse', syn_param=None, **kwargs)[source]# Generate a network containing only one type of neurons.
New in version 1.0.
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.
SpatialNetwork
(population, name='Graph', weighted=True, directed=True, shape=None, from_graph=None, positions=None, **kwargs)[source]# Class that inherits from
Network
andSpatialGraph
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 theShape
object of the instance. - population (class:~nngt.NeuralPop, optional (default: None)) – Population from which the network will be built.
Returns: self (
SpatialNetwork
)-
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 thenngt.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.
- name (string, optional (default: “Graph”)) – The name of this