Content¶
nngt.analysis.adjacency_matrix (graph[, ...]) 
Adjacency matrix of the graph. 
nngt.analysis.assortativity (graph[, deg_type]) 
Assortativity of the graph. 
nngt.analysis.bayesian_blocks (t[, x, sigma, ...]) 
Bayesian Blocks Implementation 
nngt.analysis.betweenness_distrib (graph[, ...]) 
Betweenness distribution of a graph. 
nngt.analysis.binning (x[, bins, log]) 
Binning function providing automatic binning using Bayesian blocks in addition to standard linear and logarithmic uniform bins. 
nngt.analysis.closeness (graph[, nodes, ...]) 
Return the closeness centrality for each node in nodes. 
nngt.analysis.clustering (graph) 
Global clustering coefficient of the graph. 
nngt.analysis.degree_distrib (graph[, ...]) 
Degree distribution of a graph. 
nngt.analysis.diameter (graph) 
Pseudodiameter of the graph 
nngt.analysis.get_b2 ([network, ...]) 
Return the B2 coefficient for the neurons. 
nngt.analysis.get_firing_rate ([network, ...]) 
Return the average firing rate for the neurons. 
nngt.analysis.get_spikes ([recorder, ...]) 
Return a 2D sparse matrix, where: 
nngt.analysis.local_clustering (graph[, nodes]) 
Local clustering coefficient of the nodes. 
nngt.analysis.node_attributes (network, ...) 
Return node attributes for a set of nodes. 
nngt.analysis.num_iedges (graph) 
Returns the number of inhibitory connections. 
nngt.analysis.num_scc (graph[, listing]) 
Returns the number of strongly connected components (SCCs). 
nngt.analysis.num_wcc (graph[, listing]) 
Connected components if the directivity of the edges is ignored. 
nngt.analysis.reciprocity (graph) 
Graph reciprocity, defined as \(E^\leftrightarrow/E\), where \(E^\leftrightarrow\) and \(E\) are, respectively, the number of bidirectional edges and the total number of edges in the graph. 
nngt.analysis.spectral_radius (graph[, ...]) 
Spectral radius of the graph, defined as the eigenvalue of greatest module. 
nngt.analysis.subgraph_centrality (graph[, ...]) 
Subgraph centrality, accordign to [Estrada2005], for each node in the graph. 
nngt.analysis.total_firing_rate ([network, ...]) 
Computes the total firing rate of the network from the spike times. 
nngt.analysis.transitivity (graph) 
Same as nngt.analysis.clustering() (for networkx users) 
Details¶

nngt.analysis.
bayesian_blocks
(t, x=None, sigma=None, fitness='events', **kwargs)[source]¶ Bayesian Blocks Implementation
This is a flexible implementation of the Bayesian Blocks algorithm described in Scargle 2012 [1]
New in version 0.7.
Parameters: t (array_like) – data times (one dimensional, length N)
x (array_like (optional)) – data values
sigma (array_like or float (optional)) – data errors
fitness (str or object) – the fitness function to use. If a string, the following options are supported:
 ‘events’ : binned or unbinned event data
 extra arguments are p0, which gives the false alarm probability to compute the prior, or gamma which gives the slope of the prior on the number of bins.
 ‘regular_events’ : nonoverlapping events measured at multiples
 of a fundamental tick rate, dt, which must be specified as an additional argument. The prior can be specified through gamma, which gives the slope of the prior on the number of bins.
 ‘measures’ : fitness for a measured sequence with Gaussian errors
 The prior can be specified using gamma, which gives the slope of the prior on the number of bins. If gamma is not specified, then a simulationderived prior will be used.
Alternatively, the fitness can be a userspecified object of type derived from the FitnessFunc class.
Returns: edges (ndarray) – array containing the (N+1) bin edges
Examples
Event data:
>>> t = np.random.normal(size=100) >>> bins = bayesian_blocks(t, fitness='events', p0=0.01)
Event data with repeats:
>>> t = np.random.normal(size=100) >>> t[80:] = t[:20] >>> bins = bayesian_blocks(t, fitness='events', p0=0.01)
Regular event data:
>>> dt = 0.01 >>> t = dt * np.arange(1000) >>> x = np.zeros(len(t)) >>> x[np.random.randint(0, len(t), len(t) / 10)] = 1 >>> bins = bayesian_blocks(t, fitness='regular_events', dt=dt, gamma=0.9)
Measured point data with errors:
>>> t = 100 * np.random.random(100) >>> x = np.exp(0.5 * (t  50) ** 2) >>> sigma = 0.1 >>> x_obs = np.random.normal(x, sigma) >>> bins = bayesian_blocks(t, fitness='measures')
References
[1] Scargle, J et al. (2012) http://adsabs.harvard.edu/abs/2012arXiv1207.5578S See also
astroML.plotting.hist()
 histogram plotting function which can make use of bayesian blocks.

nngt.analysis.
adjacency_matrix
(graph, types=True, weights=True)[source]¶ Adjacency matrix of the graph.
Parameters:  graph (
Graph
or subclass) – Network to analyze.  types (bool, optional (default: True)) – Whether the excitatory/inhibitory type of the connnections should be considered (only if the weighing factor is the synaptic strength).
 weights (bool or string, optional (default: True)) – Whether weights should be taken into account; if True, then connections are weighed by their synaptic strength, if False, then a binary matrix is returned, if weights is a string, then the ponderation is the correponding value of the edge attribute (e.g. “distance” will return an adjacency matrix where each connection is multiplied by its length).
Returns: a
csr_matrix
. graph (

nngt.analysis.
assortativity
(graph, deg_type='total')[source]¶ Assortativity of the graph.
Parameters:  graph (
Graph
or subclass) – Network to analyze.  deg_type (string, optional (default: ‘total’)) – Type of degree to take into account (among ‘in’, ‘out’ or ‘total’).
Returns: a float quantifying the graph assortativity.
 graph (

nngt.analysis.
betweenness_distrib
(graph, use_weights=True, nodes=None, num_nbins='bayes', num_ebins='bayes', log=False)[source]¶ Betweenness distribution of a graph.
Changed in version 0.7.
Inclusion of automatic binning.
Parameters:  graph (
Graph
or subclass) – the graph to analyze.  use_weights (bool, optional (default: True)) – use weighted degrees (do not take the sign into account : all weights are positive).
 nodes (list or numpy.array of ints, optional (default: all nodes)) – Restrict the distribution to a set of nodes (only impacts the node attribute).
 log (bool, optional (default: False)) – use logspaced bins.
 num_bins (int, list or str, optional (default: ‘bayes’)) – Any of the automatic methodes from
numpy.histogram()
, or ‘bayes’ will provide automatic bin optimization. Otherwise, an int for the number of bins can be provided, or the direct bins list.
Returns:  ncounts (
numpy.array
) – number of nodes in each bin  nbetw (
numpy.array
) – bins for node betweenness  ecounts (
numpy.array
) – number of edges in each bin  ebetw (
numpy.array
) – bins for edge betweenness
 graph (

nngt.analysis.
binning
(x, bins='bayes', log=False)[source]¶ Binning function providing automatic binning using Bayesian blocks in addition to standard linear and logarithmic uniform bins.
New in version 0.7.
Parameters:  x (arraylike) – Array of data to be histogrammed
 bins (int, list or ‘auto’, optional (default: ‘bayes’)) – If bins is ‘bayes’, in use bayesian blocks for dynamic bin widths; if it is an int, the interval will be separated into
 log (bool, optional (default: False)) – Whether the bins should be evenly spaced on a logarithmic scale.

nngt.analysis.
closeness
(graph, nodes=None, use_weights=False)[source]¶ Return the closeness centrality for each node in nodes.
Parameters:  graph (
Graph
object) – Graph to analyze.  nodes (arraylike container with node ids, optional (default = all nodes)) – Nodes for which the local clustering coefficient should be computed.
 use_weights (bool, optional (default: False)) – Whether weighted closeness should be used.
 graph (

nngt.analysis.
clustering
(graph)[source]¶ Global clustering coefficient of the graph. Defined as:
\[c = 3 \times \frac{\text{triangles}}{\text{connected triples}}\]

nngt.analysis.
degree_distrib
(graph, deg_type='total', node_list=None, use_weights=False, log=False, num_bins='bayes')[source]¶ Degree distribution of a graph.
Changed in version 0.7.
Inclusion of automatic binning.
Parameters:  graph (
Graph
or subclass) – the graph to analyze.  deg_type (string, optional (default: “total”)) – type of degree to consider (“in”, “out”, or “total”).
 node_list (list or numpy.array of ints, optional (default: None)) – Restrict the distribution to a set of nodes (default: all nodes).
 use_weights (bool, optional (default: False)) – use weighted degrees (do not take the sign into account: all weights are positive).
 log (bool, optional (default: False)) – use logspaced bins.
 num_bins (int, list or str, optional (default: ‘bayes’)) – Any of the automatic methodes from
numpy.histogram()
, or ‘bayes’ will provide automatic bin optimization. Otherwise, an int for the number of bins can be provided, or the direct bins list.
See also
Returns:  counts (
numpy.array
) – number of nodes in each bin  deg (
numpy.array
) – bins
 graph (

nngt.analysis.
local_clustering
(graph, nodes=None)[source]¶ Local clustering coefficient of the nodes. Defined as
\[c_i = 3 \times \frac{\text{triangles}}{\text{connected triples}}\]Parameters:  graph (
Graph
object) – Graph to analyze.  nodes (arraylike container with node ids, optional (default = all nodes)) – Nodes for which the local clustering coefficient should be computed.
 graph (

nngt.analysis.
node_attributes
(network, attributes, nodes=None, data=None)[source]¶ Return node attributes for a set of nodes.
Parameters:  network (
Graph
) – The graph where the nodes belong.  attributes (str or list) – Attributes which should be returned, among: * “betweenness” * “clustering” * “indegree”, “outdegree”, “totaldegree” * “subgraph_centrality”
 nodes (list, optional (default: all nodes)) – Nodes for which the attributes should be returned.
 data (
numpy.array
of shape (N, 2), optional (default: None)) – Potential data on the spike events; if not None, it must contain the sender ids on the first column and the spike times on the second.
Returns: values (arraylike or dict) – Returns the attributes, either as an array if only one attribute is required (attributes is a
str
) or as adict
of arrays. network (

nngt.analysis.
num_scc
(graph, listing=False)[source]¶ Returns the number of strongly connected components (SCCs). SCC are ensembles where all contained nodes can reach any other node in the ensemble using the directed edges.
See also

nngt.analysis.
num_wcc
(graph, listing=False)[source]¶ Connected components if the directivity of the edges is ignored. (i.e. all edges are considered bidirectional).
See also

nngt.analysis.
reciprocity
(graph)[source]¶ Graph reciprocity, defined as \(E^\leftrightarrow/E\), where \(E^\leftrightarrow\) and \(E\) are, respectively, the number of bidirectional edges and the total number of edges in the graph.
Returns: a float quantifying the reciprocity.

nngt.analysis.
spectral_radius
(graph, typed=True, weighted=True)[source]¶ Spectral radius of the graph, defined as the eigenvalue of greatest module.
Parameters:  graph (
Graph
or subclass) – Network to analyze.  typed (bool, optional (default: True)) – Whether the excitatory/inhibitory type of the connnections should be considered.
 weighted (bool, optional (default: True)) – Whether the weights should be taken into account.
Returns: the spectral radius as a float.
 graph (

nngt.analysis.
subgraph_centrality
(graph, weights=True, normalize='max_centrality')[source]¶ Subgraph centrality, accordign to [Estrada2005], for each node in the graph.
[Estrada2005]: Ernesto Estrada and Juan A. RodríguezVelázquez, Subgraph centrality in complex networks, PHYSICAL REVIEW E 71, 056103 (2005), available on ArXiv.
Parameters:  graph (
Graph
or subclass) – Network to analyze.  weights (bool or string, optional (default: True)) – Whether weights should be taken into account; if True, then connections are weighed by their synaptic strength, if False, then a binary matrix is returned, if weights is a string, then the ponderation is the correponding value of the edge attribute (e.g. “distance” will return an adjacency matrix where each connection is multiplied by its length).
 normalize (str, optional (default: “max_centrality”)) – Whether the centrality should be normalized. Accepted normalizations are “max_eigenvalue” and “max_centrality”; the first rescales the adjacency matrix by the its largest eigenvalue before taking the exponential, the second sets the maximum centrality to one.
Returns: centralities (
numpy.ndarray
) – The subgraph centrality of each node. graph (

nngt.analysis.
transitivity
(graph)[source]¶ Same as
nngt.analysis.clustering()
(for networkx users)

nngt.analysis.
get_b2
(network=None, spike_detector=None, data=None, nodes=None)[source]¶ Return the B2 coefficient for the neurons.
Parameters:  network (
nngt.Network
, optional (default: None)) – Network for which the activity was simulated.  spike_detector (tuple of ints, optional (default: spike detectors)) – GID of the “spike_detector” objects recording the network activity.
 data (arraylike of shape (N, 2), optionale (default: None)) – Array containing the spikes data (first line must contain the NEST GID of the neuron that fired, second line must contain the associated spike time).
 nodes (arraylike, optional (default: all neurons)) – NNGT ids of the nodes for which the B2 should be computed.
Returns: b2 (arraylike) – B2 coefficient for each neuron in nodes.
 network (

nngt.analysis.
get_firing_rate
(network=None, spike_detector=None, data=None, nodes=None)[source]¶ Return the average firing rate for the neurons.
Parameters:  network (
nngt.Network
, optional (default: None)) – Network for which the activity was simulated.  spike_detector (tuple of ints, optional (default: spike detectors)) – GID of the “spike_detector” objects recording the network activity.
 data (
numpy.array
of shape (N, 2), optionale (default: None)) – Array containing the spikes data (first line must contain the NEST GID of the neuron that fired, second line must contain the associated spike time).  nodes (arraylike, optional (default: all nodes)) – NNGT ids of the nodes for which the B2 should be computed.
Returns: fr (arraylike) – Firing rate for each neuron in nodes.
 network (

nngt.analysis.
get_spikes
(recorder=None, spike_times=None, senders=None)[source]¶ Return a 2D sparse matrix, where:
 each row i contains the spikes of neuron i
 each column j contains the times of the jth spike for all neurons
Parameters:  recorder (tuple, optional (default: None)) – Tuple of NEST gids, where the first one should point to the spike_detector which recorded the spikes.
 spike_times (arraylike, optional (default: None)) – If recorder is not provided, the spikes’ data can be passed directly through their spike_times and the associated senders.
 senders (arraylike, optional (default: None)) – senders[i] corresponds to the neuron which fired at spike_times[i].
Example
>>> get_spikes()
>>> get_spikes(recorder)
>>> times = [1.5, 2.68, 125.6] >>> neuron_ids = [12, 0, 65] >>> get_spikes(spike_times=times, senders=neuron_ids)
Note
This function supposes that neuron GIDs for a continuous set of integers. If no arguments are passed to the function, the first spike_recorder available in NEST will be used.
Returns:  CSR matrix containing the spikes sorted by neuron (rows) and time
 (columns).

nngt.analysis.
total_firing_rate
(network=None, spike_detector=None, data=None, kernel_center=0.0, kernel_std=30.0, resolution=None, cut_gaussian=5.0)[source]¶ Computes the total firing rate of the network from the spike times. Firing rate is obtained as the convolution of the spikes with a Gaussian kernel characterized by a standard deviation and a temporal shift.
New in version 0.7.
Parameters:  network (
nngt.Network
, optional (default: None)) – Network for which the activity was simulated.  spike_detector (tuple of ints, optional (default: spike detectors)) – GID of the “spike_detector” objects recording the network activity.
 data (
numpy.array
of shape (N, 2), optionale (default: None)) – Array containing the spikes data (first line must contain the NEST GID of the neuron that fired, second line must contain the associated spike time).  kernel_center (float, optional (default: 0.)) – Temporal shift of the Gaussian kernel, in ms.
 kernel_std (float, optional (default: 30.)) – Characteristic width of the Gaussian kernel (standard deviation) in ms.
 resolution (float or array, optional (default: 0.1*kernel_std)) – The resolution at which the firing rate values will be computed. Choosing a value smaller than kernel_std is strongly advised. If resolution is an array, it will be considered as the times were the firing rate should be computed.
 cut_gaussian (float, optional (default: 5.)) – Range over which the Gaussian will be computed. By default, we consider the 5sigma range. Decreasing this value will increase speed at the cost of lower fidelity; increasing it with increase the fidelity at the cost of speed.
Returns:  fr (arraylike) – The firing rate in Hz.
 times (arraylike) – The times associated to the firing rate values.
 network (