Generation module¶
Functions that generates the underlying connectivity of graphs, as well as the synaptic properties (weight/strength and delay).
Content¶
-
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 (tuple of strings) – Names of the source groups (which contain the pre-synaptic neurons)
- target_groups (tuple of strings) – Names of the target groups (which contain the post-synaptic 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).
- network (
-
nngt.generation.
connect_neural_types
(network, source_type, target_type, graph_model, model_param, weighted=True)[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).
- weighted (bool, optional (default: True)) – @todo Whether the graph edges have weights.
- network (
-
nngt.generation.
distance_rule
(scale, rule='exp', shape=None, neuron_density=1000.0, nodes=0, density=0.1, edges=-1, avg_deg=-1.0, 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 (1-d_{ij}/scale))\), whereas for the exponential distance-rule, \(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, not implemented yet), “power” (power-law, 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.
- 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 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.
-
nngt.generation.
erdos_renyi
(nodes=0, density=0.1, 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: - nodes (int, optional (default: None)) – The number of nodes in the graph.
- density (double, optional (default: 0.1)) – Structural density given by edges / nodes\(^2\).
- 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.Notes
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='ER', shape=None, positions=None, population=None, from_graph=None, **kwargs)[source]¶ Generate a random graph with constant in- or out-degree.
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: 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.
Returns: graph_er (
Graph
, or subclass) – A new generated graph or the modified from_graph.Notes
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 free-scale graph of given reciprocity and otherwise devoid of correlations.
- in_exp : float
- Absolute value of the in-degree exponent \(\gamma_i\), such that :math:`p(k_i) propto k_i^{-gamma_i}
- out_exp : float
- Absolute value of the out-degree exponent \(\gamma_o\), such that :math:`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 a
Network
) - from_graph :
Graph
or subclass, optional (default: None) - Initial graph whose nodes are to be connected.
graph_fs :
Graph
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 :math:`gamma =
- rac{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]¶ Generate a Price graph model (Barabasi-Albert 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’ 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_price (
Graph
or subclass.)Notes
nodes is required unless from_graph or population is provided.
-
nngt.generation.
newman_watts
(coord_nb, proba_shortcut, nodes=0, directed=True, multigraph=False, name='NW', shape=None, positions=None, population=None, from_graph=None, **kwargs)[source]¶ Generate a small-world graph using the Newman-Watts 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)Notes
nodes is required unless from_graph or population is provided.