Content¶
nngt.generation.connect_neural_groups (...) 
Function to connect excitatory and inhibitory population with a given graph model. 
nngt.generation.connect_neural_types (...) 
Function to connect excitatory and inhibitory population with a given graph model. 
nngt.generation.distance_rule (scale[, rule, ...]) 
Create a graph using a 2D distance rule to create the connection between neurons. 
nngt.generation.erdos_renyi ([density, ...]) 
Generate a random graph as defined by Erdos and Renyi but with a reciprocity that can be chosen. 
nngt.generation.fixed_degree (degree[, ...]) 
Generate a random graph with constant in or outdegree. 
nngt.generation.gaussian_degree (avg, std[, ...]) 
Generate a random graph with constant in or outdegree. 
nngt.generation.newman_watts (coord_nb, ...) 
Generate a smallworld graph using the NewmanWatts algorithm. 
nngt.generation.price_scale_free (m[, c, ...]) 
@todo 
nngt.generation.random_scale_free (in_exp, ...) 
Generate a freescale graph of given reciprocity and otherwise devoid of correlations. 
Details¶

nngt.generation.
connect_neural_groups
(network, source_groups, target_groups, graph_model, model_param)[source]¶ Function to connect excitatory and inhibitory population with a given graph model.
 @todo
 make the modifications for only a set of edges
Parameters:  network (
Network
orSpatialNetwork
) – The network to connect.  source_groups (str or tuple) – Names of the source groups (which contain the presynaptic neurons)
 target_groups (str or tuple) – Names of the target groups (which contain the postsynaptic neurons)
 graph_model (string) – The name of the connectivity model (among “erdos_renyi”, “random_scale_free”, “price_scale_free”, and “newman_watts”).
 model_param (dict) – Dictionary containing the model parameters (the keys are the keywords of the associated generation function — see above).

nngt.generation.
connect_neural_types
(network, source_type, target_type, graph_model, model_param)[source]¶ Function to connect excitatory and inhibitory population with a given graph model.
 @todo
 make the modifications for only a set of edges
Parameters:  network (
Network
orSpatialNetwork
) – The network to connect.  source_type (int) – The type of source neurons (
1
for excitatory,1
for inhibitory neurons).  source_type (int) – The type of target neurons.
 graph_model (string) – The name of the connectivity model (among “erdos_renyi”, “random_scale_free”, “price_scale_free”, and “newman_watts”).
 model_param (dict) – Dictionary containing the model parameters (the keys are the keywords of the associated generation function — see above).

nngt.generation.
distance_rule
(scale, rule='exp', shape=None, neuron_density=1000.0, nodes=0, density=1.0, edges=1, avg_deg=1.0, unit='um', weighted=True, directed=True, multigraph=False, name='DR', positions=None, population=None, from_graph=None, **kwargs)[source]¶ Create a graph using a 2D distance rule to create the connection between neurons. Available rules are linear and exponential.
Parameters:  scale (float) – Characteristic scale for the distance rule. E.g for linear distance rule, \(P(i,j) \propto (1d_{ij}/scale))\), whereas for the exponential distancerule, \(P(i,j) \propto e^{d_{ij}/scale}\).
 rule (string, optional (default: ‘exp’)) – Rule that will be apply to draw the connections between neurons. Choose among “exp” (exponential), “lin” (linear), “power” (powerlaw, not implemented yet).
 shape (
Shape
, optional (default: None)) – Shape of the neurons’ environment. If not specified, a square will be created with the appropriate dimensions for the number of neurons and the neuron spatial density.  neuron_density (float, optional (default: 1000.)) – Density of neurons in space (\(neurons \cdot mm^{2}\)).
 nodes (int, optional (default: None)) – The number of nodes in the graph.
 density (double, optional (default: 0.1)) – Structural density given by edges / (nodes * nodes).
 edges (int (optional)) – The number of edges between the nodes
 avg_deg (double, optional) – Average degree of the neurons given by edges / nodes.
 unit (string (default: ‘um’)) – Unit for the length scale among ‘um’ (\(\mu m\)), ‘mm’, ‘cm’, ‘dm’, ‘m’.
 weighted (bool, optional (default: True)) – @todo Whether the graph edges have weights.
 directed (bool, optional (default: True)) – Whether the graph is directed or not.
 multigraph (bool, optional (default: False)) – Whether the graph can contain multiple edges between two nodes.
 name (string, optional (default: “DR”)) – Name of the created graph.
 positions (
numpy.ndarray
, optional (default: None)) – A 2D (N, 2) or 3D (N, 3) shaped array containing the positions of the neurons in space.  population (
NeuralPop
, optional (default: None)) – Population of neurons defining their biological properties (to create aNetwork
).  from_graph (
Graph
or subclass, optional (default: None)) – Initial graph whose nodes are to be connected.

nngt.generation.
erdos_renyi
(density=1.0, nodes=0, edges=1, avg_deg=1.0, reciprocity=1.0, weighted=True, directed=True, multigraph=False, name='ER', shape=None, positions=None, population=None, from_graph=None, **kwargs)[source]¶ Generate a random graph as defined by Erdos and Renyi but with a reciprocity that can be chosen.
Parameters:  density (double, optional (default: 1.)) – Structural density given by edges / nodes\(^2\). It is also the probability for each possible edge in the graph to exist.
 nodes (int, optional (default: None)) – The number of nodes in the graph.
 edges (int (optional)) – The number of edges between the nodes
 avg_deg (double, optional) – Average degree of the neurons given by edges / nodes.
 reciprocity (double, optional (default: 1 to let it free)) – Fraction of edges that are bidirectional (only for directed graphs – undirected graphs have a reciprocity of 1 by definition)
 weighted (bool, optional (default: True)) – Whether the graph edges have weights.
 directed (bool, optional (default: True)) – Whether the graph is directed or not.
 multigraph (bool, optional (default: False)) – Whether the graph can contain multiple edges between two nodes.
 name (string, optional (default: “ER”)) – Name of the created graph.
 shape (
Shape
, optional (default: None)) – Shape of the neurons’ environment.  positions (
numpy.ndarray
, optional (default: None)) – A 2D or 3D array containing the positions of the neurons in space.  population (
NeuralPop
, optional (default: None)) – Population of neurons defining their biological properties (to create aNetwork
).  from_graph (
Graph
or subclass, optional (default: None)) – Initial graph whose nodes are to be connected.
Returns: graph_er (
Graph
, or subclass) – A new generated graph or the modified from_graph.Note
nodes is required unless from_graph or population is provided. If an from_graph is provided, all preexistant edges in the object will be deleted before the new connectivity is implemented.

nngt.generation.
fixed_degree
(degree, degree_type='in', nodes=0, reciprocity=1.0, weighted=True, directed=True, multigraph=False, name='FD', shape=None, positions=None, population=None, from_graph=None, **kwargs)[source]¶ Generate a random graph with constant in or outdegree.
Parameters: degree (int) – The value of the constant degree.
degree_type (str, optional (default: ‘in’)) – The type of the fixed degree, among
'in'
,'out'
or'total'
. @todo
‘total’ not implemented yet.
nodes (int, optional (default: None)) – The number of nodes in the graph.
reciprocity (double, optional (default: 1 to let it free)) – @todo: not implemented yet. Fraction of edges that are bidirectional (only for directed graphs – undirected graphs have a reciprocity of 1 by definition)
weighted (bool, optional (default: True)) – Whether the graph edges have weights.
directed (bool, optional (default: True)) – @todo: only for directed graphs for now. Whether the graph is directed or not.
multigraph (bool, optional (default: False)) – Whether the graph can contain multiple edges between two nodes.
name (string, optional (default: “ER”)) – Name of the created graph.
shape (
Shape
, optional (default: None)) – Shape of the neurons’ environment.positions (
numpy.ndarray
, optional (default: None)) – A 2D or 3D array containing the positions of the neurons in space.population (
NeuralPop
, optional (default: None)) – Population of neurons defining their biological properties (to create aNetwork
).from_graph (
Graph
or subclass, optional (default: None)) – Initial graph whose nodes are to be connected.
Note
nodes is required unless from_graph or population is provided. If an from_graph is provided, all preexistant edges in the object will be deleted before the new connectivity is implemented.
Returns: graph_fd ( Graph
, or subclass) – A new generated graph or the modified from_graph.

nngt.generation.
gaussian_degree
(avg, std, degree_type='in', nodes=0, reciprocity=1.0, weighted=True, directed=True, multigraph=False, name='GD', shape=None, positions=None, population=None, from_graph=None, **kwargs)[source]¶ Generate a random graph with constant in or outdegree. @todo: adapt it for undirected graphs!
Parameters:  avg (float) – The value of the average degree.
 std (float) – The standard deviation of the Gaussian distribution.
 degree_type (str, optional (default: ‘in’)) – The type of the fixed degree, among ‘in’, ‘out’ or ‘total’ @todo: Implement ‘total’ degree
 nodes (int, optional (default: None)) – The number of nodes in the graph.
 reciprocity (double, optional (default: 1 to let it free)) – @todo: not implemented yet. Fraction of edges that are bidirectional (only for directed graphs – undirected graphs have a reciprocity of 1 by definition)
 weighted (bool, optional (default: True)) – Whether the graph edges have weights.
 directed (bool, optional (default: True)) – @todo: only for directed graphs for now. Whether the graph is directed or not.
 multigraph (bool, optional (default: False)) – Whether the graph can contain multiple edges between two nodes.
 name (string, optional (default: “ER”)) – Name of the created graph.
 shape (
Shape
, optional (default: None)) – Shape of the neurons’ environment.  positions (
numpy.ndarray
, optional (default: None)) – A 2D or 3D array containing the positions of the neurons in space.  population (
NeuralPop
, optional (default: None)) – Population of neurons defining their biological properties (to create aNetwork
).  from_graph (
Graph
or subclass, optional (default: None)) – Initial graph whose nodes are to be connected.
Returns: graph_gd (
Graph
, or subclass) – A new generated graph or the modified from_graph.Note
nodes is required unless from_graph or population is provided. If an from_graph is provided, all preexistant edges in the object will be deleted before the new connectivity is implemented.

nngt.generation.
random_scale_free
(in_exp, out_exp, nodes=0, density=0.1, edges=1, avg_deg=1, reciprocity=0.0, weighted=True, directed=True, multigraph=False, name='RandomSF', shape=None, positions=None, population=None, from_graph=None, **kwargs)[source]¶ Generate a freescale graph of given reciprocity and otherwise devoid of correlations.
Parameters:  in_exp (float) – Absolute value of the indegree exponent \(\gamma_i\), such that \(p(k_i) \propto k_i^{\gamma_i}\)
 out_exp (float) – Absolute value of the outdegree exponent \(\gamma_o\), such that \(p(k_o) \propto k_o^{\gamma_o}\)
 nodes (int, optional (default: None)) – The number of nodes in the graph.
 density (double, optional (default: 0.1)) – Structural density given by edges / (nodes*nodes).
 edges (int (optional)) – The number of edges between the nodes
 avg_deg (double, optional) – Average degree of the neurons given by edges / nodes.
 weighted (bool, optional (default: True)) – @todo Whether the graph edges have weights.
 directed (bool, optional (default: True)) – Whether the graph is directed or not.
 multigraph (bool, optional (default: False)) – Whether the graph can contain multiple edges between two nodes. can contain multiple edges between two
 name (string, optional (default: “ER”)) – Name of the created graph.
 shape (
Shape
, optional (default: None)) – Shape of the neurons’ environment.  positions (
numpy.ndarray
, optional (default: None)) – A 2D or 3D array containing the positions of the neurons in space.  population (
NeuralPop
, optional (default: None)) – Population of neurons defining their biological properties (to create aNetwork
)  from_graph (
Graph
or subclass, optional (default: None)) – Initial graph whose nodes are to be connected.
Returns: graph_fs (
Graph
)Note
As reciprocity increases, requested values of in_exp and out_exp will be less and less respected as the distribution will converge to a common exponent \(\gamma = (\gamma_i + \gamma_o) / 2\). Parameter nodes is required unless from_graph or population is provided.

nngt.generation.
price_scale_free
(m, c=None, gamma=1, nodes=0, weighted=True, directed=True, seed_graph=None, multigraph=False, name='PriceSF', shape=None, positions=None, population=None, from_graph=None, **kwargs)[source]¶ @todo make the algorithm.
Generate a Price graph model (BarabasiAlbert if undirected).
Parameters: m (int) – The number of edges each new node will make.
c (double) – Constant added to the probability of a vertex receiving an edge.
gamma (double) – Preferential attachment power.
nodes (int, optional (default: None)) – The number of nodes in the graph.
weighted (bool, optional (default: True)) –
 @todo
Whether the graph edges have weights.
directed (bool, optional (default: True)) – Whether the graph is directed or not.
multigraph (bool, optional (default: False)) – Whether the graph can contain multiple edges between two nodes.
name (string, optional (default: “ER”)) – Name of the created graph.
shape (
Shape
, optional (default: None)) – Shape of the neurons’ environmentpositions (
numpy.ndarray
, optional (default: None)) – A 2D or 3D array containing the positions of the neurons in space.population (
NeuralPop
, optional (default: None)) – Population of neurons defining their biological properties (to create aNetwork
).from_graph (
Graph
or subclass, optional (default: None)) – Initial graph whose nodes are to be connected.
Returns: graph_price (
Graph
or subclass.)Note
nodes is required unless from_graph or population is provided.

nngt.generation.
newman_watts
(coord_nb, proba_shortcut, nodes=0, weighted=True, directed=True, multigraph=False, name='NW', shape=None, positions=None, population=None, from_graph=None, **kwargs)[source]¶ Generate a smallworld graph using the NewmanWatts algorithm.
 @todo
 generate the edges of a circular graph to not replace the graph of the from_graph and implement chosen reciprocity.
Parameters:  coord_nb (int) – The number of neighbours for each node on the initial topological lattice.
 proba_shortcut (double) – Probability of adding a new random (shortcut) edge for each existing edge on the initial lattice.
 nodes (int, optional (default: None)) – The number of nodes in the graph.
 density (double, optional (default: 0.1)) – Structural density given by edges / (nodes`*`nodes).
 edges (int (optional)) – The number of edges between the nodes
 avg_deg (double, optional) – Average degree of the neurons given by edges / nodes.
 weighted (bool, optional (default: True)) – @todo Whether the graph edges have weights.
 directed (bool, optional (default: True)) – Whether the graph is directed or not.
 multigraph (bool, optional (default: False)) – Whether the graph can contain multiple edges between two nodes.
 name (string, optional (default: “ER”)) – Name of the created graph.
 shape (
Shape
, optional (default: None)) – Shape of the neurons’ environment  positions (
numpy.ndarray
, optional (default: None)) – A 2D or 3D array containing the positions of the neurons in space.  population (
NeuralPop
, optional (default: None)) – Population of neurons defining their biological properties (to create aNetwork
).  from_graph (
Graph
or subclass, optional (default: None)) – Initial graph whose nodes are to be connected.
Returns: graph_nw (
Graph
or subclass)Note
nodes is required unless from_graph or population is provided.