pynets.statistics.individual package¶
Submodules¶
pynets.statistics.individual.algorithms module¶
Created on Tue Nov 7 10:40:07 2017 Copyright (C) 2017 @author: Derek Pisner
- pynets.statistics.individual.algorithms.average_local_efficiency(G, weight='weight', engine='nx')[source]¶
Return the average local efficiency of all of the nodes in the G
- Parameters
- GObj
NetworkX graph.
- Returns
- average_local_efficiencyfloat
Average local efficiency of G.
Notes
Adapted from NetworkX to incorporate weight parameter.
References
- 1
Latora, V., and Marchiori, M. (2001). Efficient behavior of small-world networks. Physical Review Letters 87.
- 2
Latora, V., and Marchiori, M. (2003). Economic small-world behavior in weighted networks. Eur Phys J B 32, 249-263.
- pynets.statistics.individual.algorithms.average_shortest_path_length_fast(G, weight='weight')[source]¶
- pynets.statistics.individual.algorithms.average_shortest_path_length_for_all(G)[source]¶
Helper function, in the case of graph disconnectedness, that returns the average shortest path length, calculated iteratively for each distinct subgraph of the G.
- Parameters
- GObj
NetworkX graph.
- Returns
- average_shortest_path_lengthfloat
The length of the average shortest path for G.
- pynets.statistics.individual.algorithms.collect_pandas_df_make(net_mets_csv_list, ID, subnet, plot_switch, embed=False, create_summary=False)[source]¶
Summarize list of pickled pandas dataframes of graph metrics unique to each unique combination of metaparameters.
- Parameters
- net_mets_csv_listlist
List of file paths to pickled pandas dataframes as themselves.
- IDstr
A subject id or other unique identifier.
- subnetstr
Resting-state subnet based on Yeo-7 and Yeo-17 naming (e.g. ‘Default’) used to filter nodes in the study of brain subgraphs.
- plot_switchbool
Activate summary plotting (histograms, central tendency, AUC, etc.)
- Returns
- combination_completebool
If True, then data integration completed successfully.
References
- 1
Drakesmith, M., Caeyenberghs, K., Dutt, A., Lewis, G., David, A. S., & Jones, D. K. (2015). Overcoming the effects of false positives and threshold bias in graph theoretical analyses of neuroimaging data. NeuroImage. https://doi.org/10.1016/j.neuroimage.2015.05.011
- pynets.statistics.individual.algorithms.countmotifs(A, N=4)[source]¶
Counts number of motifs with size N from A.
- Parameters
- Andarray
M x M Connectivity matrix
- Nint
Size of motif type. Default is N=4, only 3 or 4 supported.
- Returns
- umotifsint
Total count of size N motifs for graph A.
References
- 1
Sporns, O., & Kötter, R. (2004). Motifs in Brain Networks. PLoS Biology. https://doi.org/10.1371/journal.pbio.0020369
- pynets.statistics.individual.algorithms.create_communities(node_comm_aff_mat, node_num)[source]¶
Create a 1D vector of community assignments from a community affiliation matrix.
- Parameters
- node_comm_aff_matarray
Community affiliation matrix produced from modularity estimation (e.g. Louvain).
- node_numint
Number of total connected nodes in the graph used to estimate node_comm_aff_mat.
- Returns
- com_assignarray
1D numpy vector of community assignments.
References
- 1
Newman, M.E.J. & Girvan, M. Finding and evaluating community structure in networks. Physical Review E 69, 26113(2004).
- 2
Blondel, V.D. et al. Fast unfolding of communities in large networks. J. Stat. Mech 10008, 1-12(2008).
- pynets.statistics.individual.algorithms.diversity_coef_sign(W, ci)[source]¶
The Shannon-entropy based diversity coefficient measures the diversity of intermodular connections of individual nodes and ranges from 0 to 1.
- Parameters
- WNxN np.ndarray
undirected connection matrix with positive and negative weights
- ciNx1 np.ndarray
community affiliation vector
- Returns
- HposNx1 np.ndarray
diversity coefficient based on positive connections
- HnegNx1 np.ndarray
diversity coefficient based on negative connections
References
- 1
Rubinov, M., & Sporns, O. (2010). Complex subnet measures of brain connectivity: Uses and interpretations. NeuroImage, 52, 1059-1069.
- pynets.statistics.individual.algorithms.get_betweenness_centrality(G_len, metric_list_names, net_met_val_list_final, engine='nx')[source]¶
- pynets.statistics.individual.algorithms.get_clustering(G, metric_list_names, net_met_val_list_final, engine='nx')[source]¶
- pynets.statistics.individual.algorithms.get_comm_centrality(G, metric_list_names, net_met_val_list_final)[source]¶
- pynets.statistics.individual.algorithms.get_community(G, net_met_val_list_final, metric_list_names)[source]¶
- pynets.statistics.individual.algorithms.get_degree_centrality(G, metric_list_names, net_met_val_list_final)[source]¶
- pynets.statistics.individual.algorithms.get_diversity(in_mat, ci, metric_list_names, net_met_val_list_final)[source]¶
- pynets.statistics.individual.algorithms.get_eigen_centrality(G, metric_list_names, net_met_val_list_final, engine='nx')[source]¶
- pynets.statistics.individual.algorithms.get_local_efficiency(G, metric_list_names, net_met_val_list_final)[source]¶
- pynets.statistics.individual.algorithms.get_participation(in_mat, ci, metric_list_names, net_met_val_list_final)[source]¶
- pynets.statistics.individual.algorithms.get_prop_type(value, key=None)[source]¶
Performs typing and value conversion for the graph_tool PropertyMap class. If a key is provided, it also ensures the key is in a format that can be used with the PropertyMap. Returns a tuple, (type name, value, key)
- pynets.statistics.individual.algorithms.get_rich_club_coeff(G, metric_list_names, net_met_val_list_final, engine='nx')[source]¶
- pynets.statistics.individual.algorithms.global_efficiency(G, weight='weight', engine='nx')[source]¶
Return the global efficiency of the G
- Parameters
- GNetworkX graph
- Returns
- global_efficiencyfloat
Notes
The published definition includes a scale factor based on a completely connected graph. In the case of an unweighted subnet, the scaling factor is 1 and can be ignored. In the case of a weighted graph, calculating the scaling factor requires somehow knowing the weights of the edges required to make a completely connected graph. Since that knowlege may not exist, the scaling factor is not included. If that knowlege exists, construct the corresponding weighted graph and calculate its global_efficiency to scale the weighted graph. Distance between nodes is calculated as the sum of weights. If the graph is defined such that a higher weight represents a stronger connection, distance should be represented by 1/weight. In this case, use the invert weights function to generate a graph where the weights are set to 1/weight and then calculate efficiency
References
- 1
Latora, V., and Marchiori, M. (2001). Efficient behavior of small-world networks. Physical Review Letters 87.
- 2
Latora, V., and Marchiori, M. (2003). Economic small-world behavior in weighted networks. Eur Phys J B 32, 249-263.
- pynets.statistics.individual.algorithms.link_communities(W, type_clustering='single')[source]¶
The optimal community structure is a subdivision of the subnet into nonoverlapping groups of nodes which maximizes the number of within-group edges and minimizes the number of between-group edges. This algorithm uncovers overlapping community structure via hierarchical clustering of subnet links. This algorithm is generalized for weighted/directed/fully-connected networks
- Parameters
- WNxN np.array
directed weighted/binary adjacency matrix
- type_clusteringstr
type of hierarchical clustering. ‘single’ for single-linkage, ‘complete’ for complete-linkage. Default value=’single’
- Returns
- MCxN np.ndarray
nodal community affiliation matrix.
References
- 1
de Reus, M. A., Saenger, V. M., Kahn, R. S., & van den Heuvel, M. P. (2014). An edge-centric perspective on the human connectome: Link communities in the brain. Philosophical Transactions of the Royal Society B: Biological Sciences. https://doi.org/10.1098/rstb.2013.0527
- pynets.statistics.individual.algorithms.local_efficiency(G, weight='weight', engine='nx')[source]¶
Return the local efficiency of each node in the G
- Parameters
- GObj
NetworkX graph.
- Returns
- local_efficiencydict
The keys of the dict are the nodes in the G and the corresponding values are local efficiencies of each node
Notes
The published definition includes a scale factor based on a completely connected graph. In the case of an unweighted subnet, the scaling factor is 1 and can be ignored. In the case of a weighted graph, calculating the scaling factor requires somehow knowing the weights of the edges required to make a completely connected graph. Since that knowlege may not exist, the scaling factor is not included. If that knowlege exists, construct the corresponding weighted graph and calculate its local_efficiency to scale the weighted graph.
References
- 1
Latora, V., and Marchiori, M. (2001). Efficient behavior of small-world networks. Physical Review Letters 87.
- 2
Latora, V., and Marchiori, M. (2003). Economic small-world behavior in weighted networks. Eur Phys J B 32, 249-263.
- pynets.statistics.individual.algorithms.most_important(G, method='betweenness', sd=1, engine='nx')[source]¶
Returns a copy of G with hubs as defined by centrality, core topology, or rich-club topology.
- Parameters
- GObj
NetworkX graph.
- methodstr
Determines method for defining hubs. Valid inputs are coreness, richclub, and eigenvector centrality. Default is coreness.
- sdint
Number of standard errors as cutoff for low-importance pruning.
- Returns
- GObj
NetworkX graph with isolated and low-importance nodes pruned.
- pruned_nodeslist
List of indices of nodes that were pruned from G.
References
- 1
Power, J. D., Schlaggar, B. L., Lessov-Schlaggar, C. N., & Petersen, S. E. (2013). Evidence for hubs in human functional brain networks. Neuron. https://doi.org/10.1016/j.neuron.2013.07.035
- pynets.statistics.individual.algorithms.nx2gt(nxG)[source]¶
Converts a networkx graph to a graph-tool graph.
- pynets.statistics.individual.algorithms.participation_coef(W, ci, degree='undirected')[source]¶
Participation coefficient is a measure of diversity of intermodular connections of individual nodes.
- Parameters
- WNxN np.ndarray
binary/weighted directed/undirected connection matrix
- ciNx1 np.ndarray
community affiliation vector
- degreestr
- Flag to describe nature of graph ‘undirected’: For undirected graphs
‘in’: Uses the in-degree ‘out’: Uses the out-degree
- Returns
- ——-
- PNx1 np.ndarray
Participation coefficient
References
- 1
Guimera, R., & Amaral, L. A. N. (2005). Functional cartography of complex metabolic networks. Nature, 433, 895-900.
- 2
Rubinov, M., & Sporns, O. (2010). Complex subnet measures of brain connectivity: Uses and interpretations. NeuroImage, 52, 1059-1069.
- pynets.statistics.individual.algorithms.participation_coef_sign(W, ci)[source]¶
Participation coefficient is a measure of diversity of intermodular connections of individual nodes.
- Parameters
- WNxN np.ndarray
undirected connection matrix with positive and negative weights
- ciNx1 np.ndarray
community affiliation vector
- Returns
- PposNx1 np.ndarray
participation coefficient from positive weights
- PnegNx1 np.ndarray
participation coefficient from negative weights
References
- 1
Guimera, R., & Amaral, L. A. N. (2005). Functional cartography of complex metabolic networks. Nature, 433, 895-900.
- 2
Rubinov, M., & Sporns, O. (2010). Complex subnet measures of brain connectivity: Uses and interpretations. NeuroImage, 52, 1059-1069.
- pynets.statistics.individual.algorithms.prune_small_components(G, min_nodes)[source]¶
Returns a recomposed graph of all connected components of a minimum size
- Parameters
- GObj
NetworkX graph with isolated nodes present.
- min_nodes: int
Minimum number of nodes permitted in a connected subgraph
- Returns
- GObj
NetworkX graph with isolated nodes pruned.
- pruned_nodeslist
List of indices of nodes that were pruned from G.
References
- 1
Hayasaka, S. (2017). Anti-Fragmentation of Resting-State Functional Magnetic Resonance Imaging Connectivity Networks with Node-Wise Thresholding. Brain Connectivity. https://doi.org/10.1089/brain.2017.0523
- 2
Fornito, A., Zalesky, A., & Bullmore, E. T. (2016). Fundamentals of Brain subnet Analysis. In Fundamentals of Brain subnet Analysis. https://doi.org/10.1016/C2012-0-06036-X
- pynets.statistics.individual.algorithms.raw_mets(G, i, engine='nx')[source]¶
API that iterates across NetworkX algorithms for a G.
- Parameters
- GObj
NetworkX graph.
- istr
Name of the NetworkX algorithm.
- Returns
- net_met_valfloat
Value of the graph metric i that was calculated from G.
- pynets.statistics.individual.algorithms.smallworldness(G, niter=5, nrand=10, approach='clustering', reference='lattice', engine='nx')[source]¶
Returns the small-world coefficient of a graph
The small-world coefficient of a G is:
omega/sigma = Lr/L - C/Cl
where C and L are respectively the average clustering coefficient/ transitivity and average shortest path length of G. Lr is the average shortest path length of an equivalent random graph and Cl is the average clustering coefficient/transitivity of an equivalent lattice/random graph.
- Parameters
- GNetworkX graph
An undirected graph.
- niter: integer (optional, default=5)
Approximate number of rewiring per edge to compute the equivalent random graph.
- nrand: integer (optional, default=10)
Number of random graphs generated to compute the average clustering coefficient (Cr) and average shortest path length (Lr).
- approachstr
Specifies whether to use clustering coefficient directly clustering or transitivity method of counting weighted triangles. Default is clustering.
- referencestr
Specifies whether to use a random random or lattice lattice reference. Default is lattice.
- Returns
- omega/sigmafloat
The smallworld coefficient
References
- 1
Telesford, Joyce, Hayasaka, Burdette, and Laurienti (2011). “The Ubiquity of Small-World Networks”. Brain Connectivity. 1 (0038): 367-75. PMC 3604768. PMID 22432451. doi:10.1089/brain.2011.0038.
- pynets.statistics.individual.algorithms.subgraph_number_of_cliques_for_all(G)[source]¶
Helper function, in the case of graph disconnectedness, that returns the number of cliques, calculated iteratively for each distinct subgraph of the G.
- Parameters
- GObj
NetworkX graph.
- Returns
- number of cliquesint
The average number of cliques for G.
References
- 1
Bron, C. and Kerbosch, J. “Algorithm 457: finding all cliques of an undirected graph”. Communications of the ACM 16, 9 (Sep. 1973), 575–577. <http://portal.acm.org/citation.cfm?doid=362342.362367>
- 2
Etsuji Tomita, Akira Tanaka, Haruhisa Takahashi, “The worst-case time complexity for generating all maximal cliques and computational experiments”, Theoretical Computer Science, Volume 363, Issue 1, Computing and Combinatorics, 10th Annual International Conference on Computing and Combinatorics (COCOON 2004), 25 October 2006, Pages 28-42 <https://doi.org/10.1016/j.tcs.2006.06.015>
- 3
F. Cazals, C. Karande, “A note on the problem of reporting maximal cliques”, Theoretical Computer Science, Volume 407, Issues 1–3, 6 November 2008, Pages 564–568, <https://doi.org/10.1016/j.tcs.2008.05.010>
- pynets.statistics.individual.algorithms.weighted_transitivity(G)[source]¶
Compute weighted graph transitivity, the fraction of all possible weighted triangles present in G.
Possible triangles are identified by the number of “triads” (two edges with a shared vertex).
The transitivity is
\[T = 3\frac{\#triangles}{\#triads}.\]- Parameters
- Ggraph
- Returns
- outfloat
Transitivity
References
- 1
Wasserman, S., and Faust, K. (1994). Social subnet Analysis: Methods and Applications. Cambridge: Cambridge University Press.
- 2
Alain Barrat, Marc Barthelemy, Romualdo Pastor-Satorras, Alessandro Vespignani: The architecture of complex weighted networks, Proc. Natl. Acad. Sci. USA 101, 3747 (2004)
pynets.statistics.individual.spectral module¶
Created on Tue Nov 7 10:40:07 2017 Copyright (C) 2017 @author: Derek Pisner
- pynets.statistics.individual.spectral.build_asetomes(est_path_iterlist)[source]¶
Embeds single graphs using the ASE algorithm.
- Parameters
- est_path_iterlistlist
List of file paths to .npy files, each containing a graph.
- pynets.statistics.individual.spectral.build_masetome(est_path_iterlist)[source]¶
Embeds structural-functional graph pairs into a common invariant subspace.
- Parameters
- est_path_iterlistlist
List of list of pairs of file paths (.npy) corresponding to structural and functional connectomes matched at a given node resolution.
References
- 1
Rosenthal, G., Váša, F., Griffa, A., Hagmann, P., Amico, E., Goñi, J., Sporns, O. (2018). Mapping higher-order relations between brain structure and function with embedded vector representations of connectomes. Nature Communications. https://doi.org/10.1038/s41467-018-04614-w
- pynets.statistics.individual.spectral.build_omnetome(est_path_iterlist)[source]¶
Embeds ensemble population of graphs into an embedded ensemble feature vector.
- Parameters
- est_path_iterlistlist
List of file paths to .npy file containing graph.
References
- 1
Liu, Y., He, L., Cao, B., Yu, P. S., Ragin, A. B., & Leow, A. D. (2018). Multi-view multi-graph embedding for brain network clustering analysis. 32nd AAAI Conference on Artificial Intelligence, AAAI 2018.
- 2
Levin, K., Athreya, A., Tang, M., Lyzinski, V., & Priebe, C. E. (2017, November). A central limit theorem for an omnibus embedding of multiple random dot product graphs. In Data Mining Workshops (ICDMW), 2017 IEEE International Conference on (pp. 964-967). IEEE.
pynets.statistics.individual.multiplex module¶
Created on Tue Nov 7 10:40:07 2017 Copyright (C) 2018 @author: Derek Pisner & James Kunert-Graf
- pynets.statistics.individual.multiplex.build_multigraphs(est_path_iterlist)[source]¶
Constructs a multimodal multigraph for each available resolution of vertices.
- Parameters
- est_path_iterlistlist
List of file paths to .npy file containing graph.
- Returns
- multigraph_list_alllist
List of multiplex graph dictionaries corresponding to each unique node resolution.
- graph_path_list_toplist
List of lists consisting of pairs of most similar structural and functional connectomes for each unique node resolution.
References
- 1
Bullmore, E., & Sporns, O. (2009). Complex brain networks: Graph theoretical analysis of structural and functional systems. Nature Reviews Neuroscience. https://doi.org/10.1038/nrn2575
- 2
Vaiana, M., & Muldoon, S. F. (2018). Multilayer Brain Networks. Journal of Nonlinear Science. https://doi.org/10.1007/s00332-017-9436-8
- pynets.statistics.individual.multiplex.build_mx_multigraph(func_mat, dwi_mat, name, namer_dir)[source]¶
It creates a symmetric (undirected) MultilayerGraph object from vertex-aligned structural and functional connectivity matrices.
References
- 1
R. Amato, N. E Kouvaris, M. San Miguel and A. Diaz-Guilera, Opinion competition dynamics on multiplex networks, New J. Phys. DOI: https://doi.org/10.1088/1367-2630/aa936a
- 2
N. E. Kouvaris, S. Hata and A. Diaz-Guilera, Pattern formation in multiplex networks, Scientific Reports 5, 10840 (2015). http://www.nature.com/srep/2015/150604/srep10840/full/srep10840.html
- 3
A. Sole-Ribata, M. De Domenico, N. E. Kouvaris, A. Diaz-Guilera, S. Gomez and A. Arenas, Spectral properties of the Laplacian of a multiplex network, Phys. Rev. E 88, 032807 (2013). http://journals.aps.org/pre/abstract/10.1103/PhysRevE.88.032807
- pynets.statistics.individual.multiplex.mutual_information_2d(x, y, sigma=1, normalized=True)[source]¶
Computes (normalized) mutual information between two 2D variate from a joint histogram.
- Parameters
- x1D array
first variable
- y1D array
second variable
- sigma: float
sigma for Gaussian smoothing of the joint histogram
- Returns
- nmi: float
the computed similariy measure