The tethne.analyze sub-package provides additional analysis methods not provided by NetworkX, as well as methods for using NetworkX algorithms on an entire GraphCollection.
collection | Methods for analyzing GraphCollection objects. |
graph | Methods for network analysis. |
Methods for analyzing GraphCollection objects.
For the most part, these methods simply provide systematic access to algorithms in NetworkX.
Apply NetworkX method to each Graph in GraphCollection.
Passes kwargs to specified NetworkX method for each Graph, and returns a dictionary of results indexed by element (node or edge) and graph index (e.g. date).
Parameters : | C : GraphCollection
method : string
**kwargs :
|
---|---|
Returns : | results : dict
|
Raises : | ValueError :
|
Examples
Betweenness centrality:
>>> import tethne.analyze as az
>>> BC = az.collection.algorithm(C, 'betweenness_centrality')
>>> print BC[0]
{1999: 0.010101651117889644,
2000: 0.0008689093723107329,
2001: 0.010504898852426189,
2002: 0.009338654511194512,
2003: 0.007519105636349891}
Calculates the observed attachment probability for each node at each time-step.
Attachment probability is calculated based on the observed new edges in the next time-step. So if a node acquires new edges at time t, this will accrue to the node’s attachment probability at time t-1. Thus at a given time, one can ask whether degree and attachment probability are related.
Parameters : | C : GraphCollection
|
---|---|
Returns : | probs : dict
|
Performs analysis methods from networkx.connected on each graph in the collection.
Parameters : | C : GraphCollection
method : string
**kwargs : kwargs
|
---|---|
Returns : | results : dictionary
|
Raises : | ValueError :
|
Examples
>>> import tethne.data as ds
>>> import tethne.analyze as az
>>> import networkx as nx
>>> C = ds.GraphCollection()
>>> # Generate some random graphs
>>> for graph_index in xrange(1999, 2004):
>>> g = nx.random_regular_graph(4, 100)
>>> C[graph_index] = g
>>> results = az.collection.connected(C, 'connected', k=None)
>>> print results
{1999: False,
2000: False,
2001: False,
2002: False,
2003: False }
Returns a dictionary of attribute vales for each Graph in C for a single edge.
Parameters : | C : GraphCollection source : str
target : str
attribute : str
verbose : bool
|
---|---|
Returns : | history : dict
|
Calculates global closeness centrality for node in each graph in GraphCollection C.
Returns a dictionary of attribute values for each Graph in C for a single node.
Parameters : | C : GraphCollection node : str
attribute : str
verbose : bool
|
---|---|
Returns : | history : dict
|
Methods for network analysis.
Calculates global closeness centrality for all nodes in the network.
See node_global_closeness_centrality() for more information.
Parameters : | g : networkx.Graph normalize : boolean
|
---|---|
Returns : | C : dict
|
Calculates the global closeness centrality of a single node in the network.
Closeness centrality is based on the average shortest path length between a focal node and all other nodes in the network. For multi-component graphs, conventional closeness centrality metrics fail because it is not possible to traverse between a given node and all other nodes in the graph. Global closeness centrality is calculated in a way that yields values even for multi-component graphs. For an example of how global closeness centrality can be used to analyze co-authorship networks, see the blog post here.
To calculate the global closeness centrality of a single node, try:
>>> import tethne.analyze as az
>>> ngbc = az.node_global_closeness_centrality(BC, 'LEE 1975 EVOLUTION')
>>> ngbc
0.154245
You can calculate the global closeness centrality of all nodes in the network using global_closeness_centrality() .
>>> GBC = az.global_closeness_centrality(BC)
>>> GBC
{'a': 0.0, 'c': 0.0, 'b': 0.6666666666666666, 'd': 0.0}
For connected graphs, this is equivalent to conventional betweenness centrality. For disconnected graphs, works around infinite path lengths between nodes in different components.
Parameters : | g : networkx.Graph node : any
normalize : boolean
|
---|---|
Returns : | c : float
|