core.interacting_networks¶
Provides classes for analyzing spatially embedded complex networks, handling multivariate data and generating time series surrogates.
- class pyunicorn.core.interacting_networks.InteractingNetworks(adjacency, directed=False, node_weights=None, silence_level=0)[source]¶
Bases:
Network
Encapsulates an ensemble of interacting networks.
Provides measures to analyze the interaction topology of different pairs of subnetworks (groups of vertices).
So far, most methods only give meaningful results for undirected networks!
The idea of interacting networks and measures for their analysis are described in [Donges2011a].
Consistently node-weighted measures for interacting network topologies are derived, described and applied in [Wiedermann2011].
- static RandomlyRewireCrossLinks(network, node_list1, node_list2, swaps)[source]¶
Randomize the cross links between two subnetworks under preservation of cross degree centrality of both subnetworks.
Chooses randomly two cross links and swaps their ending points in subnetwork 2.
Implementation:
Stores the coordinates of the “1”-entries of the cross adjacency matrix in a tuple. Chooses randomly two entries of the tuple (ergo two cross links) allowing for the constraints that
the chosen links have distinct starting points in subnetwork 1 and distinct ending points in subnetwork 2
there do not exist intermediate links such that starting point of link 1 is connected to ending point of link 2 and vice versa.
[In case two links have the same starting point or / and the same ending point, condition (2) is never satisfied. Therefore only condition (2) is implemented.]
Swaps the ending points of the links in subnetwork 2 and overwrites the coordinates of the initial links in the tuple. The number of permutation procedures is determined by the “swaps” argument and the initial number of cross links. Creates a new adjacency matrix out of the altered tuple of coordinates.
Example (Degree and cross degree sequences should be the same after rewiring):
>>> net = InteractingNetworks.SmallTestNetwork() >>> print("Degree:", net.degree()) Degree: [3 3 2 2 3 1] >>> print("Cross degree:", net.cross_degree( ... node_list1=[0,3,5], node_list2=[1,2,4])) Cross degree: [1 1 0] >>> rewired_net = net.RandomlyRewireCrossLinks( ... network=net, node_list1=[0,3,5], ... node_list2=[1,2,4], swaps=10.) >>> print("Degree:", rewired_net.degree()) Degree: [3 3 2 2 3 1] >>> print("Cross degree:", rewired_net.cross_degree( ... node_list1=[0,3,5], node_list2=[1,2,4])) Cross degree: [1 1 0]
- Parameters:
network (
InteractingNetworks
instance) – The base network for rewiring cross links.node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
internal (float) – Gives the fraction number_swaps / number_cross_links.
- Return type:
- Returns:
The initial InteractingNetworks with swapped cross links
- static RandomlySetCrossLinks(network, node_list1, node_list2, cross_link_density=None, number_cross_links=None)[source]¶
Creates a set of random cross links between the considered interacting subnetworks. The number of cross links to be set can be chosen either explicitly or via a predefined cross link density. By not choosing any of either, a null model is created under preservation of the cross link density of the initial network.
Implementation:
Determines the number of cross links to be set. Creates an empty cross adjacency matrix. Randomly picks the coordinates of an entry and sets it to one. Repeats the procedure until the desired cross link density is reached.
- Parameters:
network (InteractingNetworks instance) – The base network for setting random cross links.
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return type:
- Returns:
The initial InteractingNetworks with random cross links
- static RandomlySetCrossLinks_sparse(network, node_list1, node_list2, cross_link_density=None, number_cross_links=None)[source]¶
Creates a set of random cross links between the considered interacting subnetworks. The number of cross links to be set can be chosen either explicitly or via a predefined cross link density. By not choosing any of either, a null model is created under preservation of the cross link density of the initial network.
Implementation:
Determines the number of cross links to be set. Creates an empty cross adjacency matrix. Randomly picks the coordinates of an entry and sets it to one. Repeats the procedure until the desired cross link density is reached.
- Parameters:
network (InteractingNetworks instance) – The base network for setting random cross links.
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return type:
- Returns:
The initial InteractingNetworks with random cross links
- static SmallDirectedTestNetwork()[source]¶
Return a 6-node directed test network with node and edge weights.
The node weights are [1.5, 1.7, 1.9, 2.1, 2.3, 2.5], a typical node weight for corrected n.s.i. measures would be 2.0.
- Return type:
InteractingNetworks instance
- static SmallTestNetwork()[source]¶
Return a 6-node undirected test network.
The network looks like this:
3 - 1 | | \ 5 - 0 - 4 - 2
- Return type:
InteractingNetworks instance
- Returns:
an InteractingNetworks instance for testing purposes.
- __init__(adjacency, directed=False, node_weights=None, silence_level=0)[source]¶
Initialize an instance of InteractingNetworks.
- Parameters:
adjacency (square numpy array or list [node,node] of 0s and 1s) – Adjacency matrix of the new network. Entry [i,j] indicates whether node i links to node j. Its diagonal must be zero. Must be symmetric if directed=False.
directed (bool) – Indicates whether the network shall be considered as directed. If False, adjacency must be symmetric.
node_weights (1d numpy array or list [node] of floats >= 0) – Optional array or list of node weights to be used for node splitting invariant network measures. Entry [i] is the weight of node i. (Default: list of ones)
silence_level (int) – The inverse level of verbosity of the object.
- static _calculate_general_average_path_length(path_lengths, internal=False)[source]¶
Calculate general average path length for interacting networks.
- Parameters:
path_lengths (2D array [index, index]) – The path length matrix.
internal (bool) – Indicates, whether internal or cross average path length shall be calculated.
- Return float:
the general average path length.
- _calculate_general_closeness(path_lengths, internal=True)[source]¶
Calculate general closeness sequence for interacting networks.
- Parameters:
path_lengths (2D array [node,node] of floats) – Path lengths to use
internal (bool) – Indicates, whether internal or cross closeness shall be calculated.
- Return type:
1D array [index]
- Returns:
the general closeness sequence.
- average_cross_closeness(node_list1, node_list2, link_attribute=None)[source]¶
Return the average cross closeness.
Example:
>>> r(InteractingNetworks.SmallTestNetwork(). average_cross_closeness([0,5], [1,2,3,4])) 1.7143
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
link_attribute (str) – Optional name of the link attribute to be used as the links’ length. If None, links have length 1. (Default: None)
- Return float:
the average cross closeness.
- cross_adjacency(node_list1, node_list2)[source]¶
Return cross adjacency matrix describing the interaction of two subnetworks.
The cross adjacency matrix entry \(CA_{ij} = 1\) describes that node i in the first subnetwork is linked to node j in the second subnetwork. Vice versa, \(CA_{ji} = 1\) indicates that node j in the first subnetwork is linked to node i in the second subnetwork.
Note
The Cross adjacency matrix is NEITHER square NOR symmetric in general!
Examples:
>>> r(InteractingNetworks.SmallTestNetwork(). cross_adjacency([1,2,4], [0,3,5])) array([[0, 1, 0], [0, 0, 0], [1, 0, 0]]) >>> r(InteractingNetworks.SmallTestNetwork(). cross_adjacency([1,2,3,4], [0,5])) array([[0, 0], [0, 0], [1, 0], [1, 0]])
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return type:
2D array [node index_1, node index_2]
- Returns:
the cross adjacency matrix.
- cross_adjacency_sparse(node_list1, node_list2)[source]¶
Return cross adjacency matrix describing the interaction of two subnetworks.
The cross adjacency matrix entry M{CA_ij = 1} describes that node i in the first subnetwork is linked to node j in the second subnetwork. Vice versa, M{CA_ji = 1} indicates that node j in the first subnetwork is linked to node i in the second subnetwork.
Note
The Cross adjacency matrix is NEITHER square NOR symmetric in general!
Examples:
>>> print(InteractingNetworks.SmallTestNetwork(). cross_adjacency_sparse([1,2,4], [0,3,5])) [[0 1 0] [0 0 0] [1 0 0]]
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return type:
2D array [node index_1, node index_2]
- Returns:
the cross adjacency matrix.
- cross_average_path_length(node_list1, node_list2, link_attribute=None)[source]¶
Return cross average path length.
Return the average (weighted) shortest path length between two induced subnetworks.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). cross_average_path_length([0,3,5], [1,2,4], None) 2.0 >>> InteractingNetworks.SmallTestNetwork(). cross_average_path_length([0,5], [1,2,3,4], None) 2.0
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
link_attribute (str) – Optional name of the link attribute to be used as the links’ length. If None, links have length 1. (Default: None)
- Return float:
the cross average path length between a pair of subnetworks.
- cross_betweenness(node_list1, node_list2)[source]¶
Return the cross betweenness sequence for the whole network with respect to a pair of subnetworks.
Gives the normalized number of shortest paths only between nodes from two subnetworks, in which a node \(i\) is contained. This is equivalent to the inter-regional / inter-group betweenness with respect to subnetwork 1 and subnetwork 2.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). cross_betweenness([2], [3,5]) array([ 1., 1., 0., 0., 1., 0.]) >>> InteractingNetworks.SmallTestNetwork(). cross_betweenness(range(0,6), range(0,6)) array([ 9., 3., 0., 2., 6., 0.])
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return type:
1D arrays [node index]
- Returns:
the cross betweenness sequence for the whole network with respect to two subnetworks.
- cross_closeness(node_list1, node_list2, link_attribute=None)[source]¶
Return cross closeness sequence for a pair of induced subnetworks.
Gives the inverse average geodesic distance from a node in subnetwork 1 to all nodes in subnetwork 2.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). cross_closeness([0,3,5], [1,2,4], None) array([ 0.6 , 0.6 , 0.375]) >>> InteractingNetworks.SmallTestNetwork(). cross_closeness([0,5], [1,2,3,4], None) array([ 0.66666667, 0.4 ])
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
link_attribute (str) – Optional name of the link attribute to be used as the links’ length. If None, links have length 1. (Default: None)
- Return type:
1D arrays [index]
- Returns:
the cross closeness sequence.
- cross_degree(node_list1, node_list2, link_attribute=None)[source]¶
Return the cross degree sequence for one subnetwork with respect to a second subnetwork.
Gives the number of links from a specific node in the first subnetwork projecting to the second subnetwork. If a link attribute is specified, return the associated strength
Examples:
>>> InteractingNetworks.SmallTestNetwork(). cross_degree([0,3,5], [1,2,4]) array([1, 1, 0]) >>> InteractingNetworks.SmallTestNetwork(). cross_degree([1,2,4], [0,3,5]) array([1, 0, 1]) >>> InteractingNetworks.SmallTestNetwork(). cross_degree([1,2,3,4], [0,5]) array([0, 0, 1, 1])
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
key (str) – link attribute key (optional)
- Return type:
1D array [node index]
- Returns:
the cross degree sequence.
- cross_degree_density(node_list1, node_list2)[source]¶
Return the density of degrees, i.e., the cross degree sequence of the first subnetwork normalized to the number of nodes in the second subnetwork
Example:
>>> InteractingNetworks.SmallTestNetwork(). cross_degree_density([0,3,5], [1,2,4]) array([0.33333333, 0.33333333, 0. ])
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return type:
1D array [node index]
- Returns:
the cross degree sequence.
- cross_global_clustering(node_list1, node_list2)[source]¶
Return global cross clustering for a pair of subnetworks.
The global cross clustering coefficient C_v gives the average probability, that two randomly drawn neighbors in subnetwork 2 of node v in subnetwork 1 are also neighbors and vice versa. It counts triangles having one vertex in subnetwork 1 and two vertices in subnetwork 2 and vice versa.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). cross_global_clustering([0,3,5], [1,2,4]) 0.0 >>> InteractingNetworks.SmallTestNetwork(). cross_global_clustering([2], [1,3,4]) 1.0 >>> InteractingNetworks.SmallTestNetwork(). cross_global_clustering([3,4], [1,2]) 0.5
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return float:
the cross global clustering coefficient for a pair of subnetworks.
- cross_global_clustering_sparse(node_list1, node_list2)[source]¶
Return global cross clustering for a pair of subnetworks.
The global cross clustering coefficient C_v gives the average probability, that two randomly drawn neighbors in subnetwork 2 of node v in subnetwork 1 are also neighbors and vice versa. It counts triangles having one vertex in subnetwork 1 and two vertices in subnetwork 2 and vice versa.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). cross_global_clustering_sparse([0,3,5], [1,2,4]) 0.0 >>> InteractingNetworks.SmallTestNetwork(). cross_global_clustering_sparse([2], [1,3,4]) 1.0 >>> InteractingNetworks.SmallTestNetwork(). cross_global_clustering_sparse([3,4], [1,2]) 0.5
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return float:
the cross global clustering coefficient for a pair of subnetworks.
- cross_indegree(node_list1, node_list2, link_attribute=None)[source]¶
Return the cross indegree sequence for the first given subnetwork with respect to the second given subnetwork
Gives the number of links from nodes in subnetwork two to a specific node from subnetwork one. If a link attribute is specified, return the associated in strength.
Example:
>>> net = InteractingNetworks.SmallDirectedTestNetwork() >>> net.cross_indegree([1, 2], [0, 3, 4]) array([2, 1])
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
key (str) – link attribute key (optional)
- Return type:
1D array [node index]
- Returns:
the cross in degree sequence.
- cross_link_attribute(attribute_name, node_list1, node_list2)[source]¶
Return a cross link weights matrix describing the interaction of two subnetworks.
The cross link weights matrix entry \(CW_{ij} = w\) describes that node i in the first subnetwork is linked to node j in the second subnetwork with weights \(w\).
Note
The cross link weights matrix is NEITHER square NOR symmetric in general!
Example:
>>> net = InteractingNetworks.SmallTestNetwork() >>> r(net.cross_link_attribute("link_weights", [1,2,3], [0,4])) array([[ 0. , 2.7], [ 0. , 1.5], [ 1.3, 0. ]])
- Parameters:
attribute_name (str) – _name of link attribute to be used
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return type:
2D array [node index_1, node index_2]
- Returns:
the cross adjacency matrix.
- cross_link_density(node_list1, node_list2)[source]¶
Return the density of links between two subnetworks.
Examples:
>>> r(InteractingNetworks.SmallTestNetwork(). cross_link_density([0,3,5], [1,2,4])) 0.2222 >>> InteractingNetworks.SmallTestNetwork(). cross_link_density([0,5], [1,2,3,4]) 0.25
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return float:
the density of links between two subnetworks.
- cross_local_clustering(node_list1, node_list2)[source]¶
Return local cross clustering for a pair of subnetworks.
The local cross clustering coefficient C_v gives the probability, that two randomly drawn neighbors in subnetwork 1 of node v in subnetwork 1 are also neighbors. It counts triangles having one vertex in subnetwork 1 and two vertices in subnetwork 2.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). cross_local_clustering([0,3,5], [1,2,4]) array([ 0., 0., 0.]) >>> InteractingNetworks.SmallTestNetwork(). cross_local_clustering([2], [1,3,4]) array([ 1.]) >>> InteractingNetworks.SmallTestNetwork(). cross_local_clustering([3,4], [1,2]) array([ 0., 1.])
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return type:
1D array [node index]
- Returns:
the cross local clustering coefficient.
- cross_local_clustering_sparse(node_list1, node_list2)[source]¶
Return local cross clustering for a pair of subnetworks.
The local cross clustering coefficient C_v gives the probability, that two randomly drawn neighbors in subnetwork 1 of node v in subnetwork 1 are also neighbors. It counts triangles having one vertex in subnetwork 1 and two vertices in subnetwork 2.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). cross_local_clustering_sparse([0,3,5], [1,2,4]) array([ 0., 0., 0.])
>>> InteractingNetworks.SmallTestNetwork(). cross_local_clustering_sparse([2], [1,3,4]) array([ 1.])
>>> InteractingNetworks.SmallTestNetwork(). cross_local_clustering_sparse([3,4], [1,2]) array([ 0., 1.])
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return type:
1D array [node index]
- Returns:
the cross local clustering coefficient.
- cross_outdegree(node_list1, node_list2, link_attribute=None)[source]¶
Return the cross outdegree sequence for the first given subnetwork with respect to the second given subnetwork
Gives the number of links from a specific node in subnetwork one to nodes in subnetwork two. If a link attribute is specified, return the associated out strength.
Example:
>>> net = InteractingNetworks.SmallDirectedTestNetwork() >>> net.cross_outdegree([1, 2], [0, 3, 4]) array([1, 0])
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
key (str) – link attribute key (optional)
- Return type:
1D array [node index]
- Returns:
the cross out degree sequence.
- cross_path_lengths(node_list1, node_list2, link_attribute=None)[source]¶
Return cross path length matrix for a pair of subnetworks.
Contains the path length between nodes from different subnetworks. The paths may generally contain nodes from the full network.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). cross_path_lengths([0,3,5], [1,2,4], None) array([[ 2., 2., 1.], [ 1., 2., 2.], [ 3., 3., 2.]]) >>> InteractingNetworks.SmallTestNetwork(). cross_path_lengths([0,5], [1,2,3,4], None) array([[ 2., 2., 1., 1.], [ 3., 3., 2., 2.]])
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
link_attribute (str) – Optional name of the link attribute to be used as the links’ length. If None, links have length 1. (Default: None)
- Return type:
2D array [index1, index2]
- Returns:
the cross path length matrix for a pair of subnetworks.
- cross_transitivity(node_list1, node_list2)[source]¶
Return cross transitivity for a pair of subnetworks.
The cross transitivity is the probability, that two randomly drawn neighbors in subnetwork 2 of node v in subnetwork 1 are also neighbors. It counts triangles having one vertex in subnetwork 1 and two vertices in subnetwork 2. Cross transitivity tends to weight low cross degree vertices less strongly when compared to the global cross clustering coefficient (see [Newman2003]).
Examples:
>>> InteractingNetworks.SmallTestNetwork(). cross_transitivity([0,3,5], [1,2,4]) 0.0 >>> InteractingNetworks.SmallTestNetwork(). cross_transitivity([2], [1,3,4]) 1.0 >>> InteractingNetworks.SmallTestNetwork(). cross_transitivity([3,4], [1,2]) 1.0
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return float:
the cross transitivity for a pair of subnetworks.
- cross_transitivity_sparse(node_list1, node_list2)[source]¶
Return cross transitivity for a pair of subnetworks.
The cross transitivity is the probability, that two randomly drawn neighbors in subnetwork 2 of node v in subnetwork 1 are also neighbors. It counts triangles having one vertex in subnetwork 1 and two vertices in subnetwork 2. Cross transitivity tends to weight low cross degree vertices less strongly when compared to the global cross clustering coefficient (see Newman, SIAM Review, 2003).
Examples:
>>> InteractingNetworks.SmallTestNetwork(). cross_transitivity_sparse([0,3,5], [1,2,4]) 0.0 >>> InteractingNetworks.SmallTestNetwork(). cross_transitivity_sparse([3,4], [1,2]) 1.0
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return float:
the cross transitivity for a pair of subnetworks.
- global_efficiency(node_list1, node_list2, link_attribute=None)[source]¶
Return the global efficiency.
Example:
>>> r(InteractingNetworks.SmallTestNetwork(). global_efficiency([0,5], [1,2,3,4])) 1.7143
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
link_attribute (str) – Optional name of the link attribute to be used as the links’ length. If None, links have length 1. (Default: None)
- Return float:
the global efficiency.
- internal_adjacency(node_list)[source]¶
Return the adjacency matrix of a subnetwork induced by a subset of nodes.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). internal_adjacency([0,3,5]) array([[0, 1, 1], [1, 0, 0], [1, 0, 0]], dtype=int8) >>> InteractingNetworks.SmallTestNetwork(). internal_adjacency([1,2,4]) array([[0, 1, 1], [1, 0, 1], [1, 1, 0]], dtype=int8)
- Parameters:
node_list ([int]) – list of node indices describing the subnetwork
- Return type:
2D array [node index, node index]
- Returns:
the subnetwork’s adjacency matrix.
- internal_average_path_length(node_list, link_attribute=None)[source]¶
Return internal average path length for an induced subnetwork.
Return the average (weighted) shortest path length between all pairs of nodes within a subnetwork separately for which a path exists. Paths between nodes from different subnetworks are not included in the average!
However, even if the end points lie within the same layer, the paths themselves will generally contain nodes from the whole network. To avoid this and only consider paths lying within the subnetwork, do the following:
>>> r(InteractingNetworks.SmallTestNetwork(). subnetwork([0,3,5]).average_path_length(None)) 1.3333
Examples:
>>> r(InteractingNetworks.SmallTestNetwork(). internal_average_path_length([0,3,5], None)) 1.3333 >>> r(InteractingNetworks.SmallTestNetwork(). internal_average_path_length([1,2,4], None)) 1.0
- Parameters:
node_list ([int]) – list of node indices describing the subnetwork
link_attribute (str) – Optional name of the link attribute to be used as the links’ length. If None, links have length 1. (Default: None)
- Return float:
the internal average path length.
- internal_betweenness(node_list)[source]¶
Return the internal betweenness sequence for an induced subnetwork.
Gives the normalized number of shortest paths only between nodes from subnetwork 1, in which a node \(i\) from the whole network is contained. This is equivalent to the inter-regional / inter-group betweenness with respect to subnetwork 1 and subnetwork 1.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). internal_betweenness(range(0,6)) array([ 9., 3., 0., 2., 6., 0.])
- Parameters:
node_list ([int]) – list of node indices describing the subnetwork
- Return type:
1D array [node index]
- Returns:
the internal betweenness sequence for layer 1.
- internal_closeness(node_list, link_attribute=None)[source]¶
Return internal closeness sequence for an induced subnetwork.
Gives the inverse average geodesic distance from a node to all other nodes in the same induced subnetwork.
However, the included paths will generally contain nodes from the whole network. To avoid this, do the following:
>>> r(InteractingNetworks.SmallTestNetwork(). subnetwork([0,3,5]).closeness(None)) array([ 1. , 0.6667, 0.6667])
Examples:
>>> InteractingNetworks.SmallTestNetwork(). internal_closeness([0,3,5], None) array([ 1. , 0.66666667, 0.66666667]) >>> InteractingNetworks.SmallTestNetwork(). internal_closeness([1,2,4], None) array([ 1., 1., 1.])
- Parameters:
node_list ([int]) – list of node indices describing the subnetwork
link_attribute (str) – Optional name of the link attribute to be used as the links’ length. If None, links have length 1. (Default: None)
- Return type:
1D array [index]
- Returns:
the internal closeness sequence.
- internal_degree(node_list, link_attribute=None)[source]¶
Return the internal degree sequence of one induced subnetwork.
Gives the number of links from a specific node to other nodes within the same induced subnetwork. If a link attribute is specified, return the associated strength.
Examples:
>>> InteractingNetworks.SmallTestNetwork().internal_degree([0,3,5]) array([2, 1, 1]) >>> InteractingNetworks.SmallTestNetwork().internal_degree([1,2,4]) array([2, 2, 2])
- Parameters:
node_list ([int]) – list of node indices describing the subnetwork
key (str) – link attribute key (optional)
- Return type:
1D array [node index]
- Returns:
the internal degree sequence.
- internal_global_clustering(node_list)[source]¶
Return internal global clustering coefficients for an induced subnetwork.
Internal global clustering coefficients are calculated as mean values from the local clustering sequence of the whole network. This implies that triangles spanning different subnetworks will generally contribute to the internal clustering coefficient.
To avoid this and consider only triangles lying within the subnetwork:
>>> r(InteractingNetworks.SmallTestNetwork(). subnetwork([0,3,5]).global_clustering()) 0.0
Examples:
>>> r(InteractingNetworks.SmallTestNetwork(). internal_global_clustering([0,3,5])) 0.0 >>> r(InteractingNetworks.SmallTestNetwork(). internal_global_clustering([1,2,4])) 0.5556
- Parameters:
node_list ([int]) – list of node indices describing the subnetwork
- Return float:
the internal global clustering coefficient for a subnetwork.
- internal_indegree(node_list, link_attribute=None)[source]¶
Return the internal indegree sequence of one induced subnetwork.
Gives the number of links from other nodes to a specific node within the same induced subnetwork. If a link attribute is specified, return the associated in strength.
Example:
>>> net = InteractingNetworks.SmallDirectedTestNetwork() >>> net.internal_indegree([0, 1, 3]) array([0, 2, 1])
- Parameters:
node_list ([int]) – list of node indices describing the subnetwork
key (str) – link attribute key (optional)
- Return type:
1D array [node index]
- Returns:
the internal in degree sequence.
- internal_link_attribute(attribute_name, node_list)[source]¶
Return a like attribute matrix of a subnetwork induced by a subset of nodes.
Example:
>>> net = InteractingNetworks.SmallTestNetwork() >>> r(net.internal_link_attribute("link_weights", [1,2,3])) array([[ 0. , 2.3, 2.9], [ 2.3, 0. , 0. ], [ 2.9, 0. , 0. ]])
- Parameters:
attribute_name (str) – _name of link attribute to be used
node_list ([int]) – list of node indices describing the subnetwork
- Return type:
square numpy array [node_index, node_index]
- Returns:
link weights submatrix
- internal_link_density(node_list)[source]¶
Return the density of links within an induced subnetwork.
Examples:
>>> r(InteractingNetworks.SmallTestNetwork(). internal_link_density([0,3,5])) 0.6667 >>> r(InteractingNetworks.SmallTestNetwork(). internal_link_density([1,2,3,4])) 0.6667
- Parameters:
node_list ([int]) – list of node indices describing the subnetwork
- Return float:
the density of links within a subnetwork.
- internal_outdegree(node_list, link_attribute=None)[source]¶
Return the internal outdegree sequence of one induced subnetwork.
Gives the number of links from a specific node to other nodes within the same induced subnetwork. If a link attribute is specified, return the associated out strength.
Example:
>>> net = InteractingNetworks.SmallDirectedTestNetwork() >>> net.internal_outdegree([0, 1, 3]) array([2, 0, 1])
- Parameters:
node_list ([int]) – list of node indices describing the subnetwork
key (str) – link attribute key (optional)
- Return type:
1D array [node index]
- Returns:
the internal out degree sequence.
- internal_path_lengths(node_list, link_attribute=None)[source]¶
Return internal path length matrix of an induced subnetwork.
Contains the paths length between all pairs of nodes within the subnetwork. However, the paths themselves will generally contain nodes from the full network. To avoid this and only consider paths lying within the subnetwork, do the following:
>>> InteractingNetworks.SmallTestNetwork(). subnetwork([0,3,5]).path_lengths() array([[ 0., 1., 1.], [ 1., 0., 2.], [ 1., 2., 0.]])
Examples:
>>> InteractingNetworks.SmallTestNetwork(). internal_path_lengths([0,3,5], None) array([[ 0., 1., 1.], [ 1., 0., 2.], [ 1., 2., 0.]]) >>> InteractingNetworks.SmallTestNetwork(). internal_path_lengths([1,2,4], None) array([[ 0., 1., 1.], [ 1., 0., 1.], [ 1., 1., 0.]])
- Parameters:
node_list ([int]) – list of node indices describing the subnetwork
link_attribute (str) – Optional name of the link attribute to be used as the links’ length. If None, links have length 1. (Default: None)
- Return type:
2D array [node index, node index]
- Returns:
the internal path length matrix of an induced subnetwork.
- local_efficiency(node_list1, node_list2, link_attribute=None)[source]¶
Return the local efficiency sequence for an induced subnetwork.
Example:
>>> InteractingNetworks.SmallTestNetwork(). local_efficiency([0,5], [1,2,3,4]) array([0.75 , 0.41666667])
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
link_attribute (str) – Optional name of the link attribute to be used as the links’ length. If None, links have length 1. (Default: None)
- Return type:
1D arrays [index]
- Returns:
the local efficiency sequence.
- nsi_cross_average_path_length(node_list1, node_list2)[source]¶
Return n.s.i. cross average path length between two induced subnetworks.
Examples:
>>> net = InteractingNetworks.SmallTestNetwork() >>> r(net.nsi_cross_average_path_length([0,5],[1,2,4])) 3.3306 >>> r(net.nsi_cross_average_path_length([1,3,4,5],[2])) 0.376
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return float:
the n.s.i. cross-average path length between a pair of subnetworks.
- nsi_cross_betweenness(node_list1, node_list2)[source]¶
Return the n.s.i. cross betweenness sequence for the whole network with respect to a pair of subnetworks.
Examples:
>>> r(InteractingNetworks.SmallTestNetwork(). nsi_cross_betweenness([0,4,5],[1,3])) array([ 6.5333, 1.2 , 0. , 0.6769, 0.6769, 0. ]) >>> r(InteractingNetworks.SmallTestNetwork(). nsi_cross_betweenness([0,1],[2,3,4,5])) array([ 2.1333, 0. , 0. , 0.4923, 0.9209, 0. ])
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return type:
1D arrays [node index]
- Returns:
the n.s.i. cross betweenness sequence for the whole network with respect to two subnetworks.
- nsi_cross_closeness_centrality(node_list1, node_list2)[source]¶
Return the n.s.i. cross-closeness centrality for a pair of induced subnetworks.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). nsi_cross_closeness_centrality([0,1,2],[3,4,5]) array([ 1. , 0.56756757, 0.48837209]) >>> InteractingNetworks.SmallTestNetwork(). nsi_cross_closeness_centrality([0,2,5],[1,4]) array([ 0.73333333, 1. , 0.42307692])
- Parameters:
node_list1 ([int]) – list of node indices describing the subnetwork 1
node_list2 ([int]) – list of node indices describing the subnetwork 2
- Return type:
1D array [node index]
- Returns:
the n.s.i. cross-closeness for layer 1.
- nsi_cross_degree(node_list1, node_list2)[source]¶
Return the n.s.i. cross-degree for a pair of induced subnetworks.
Gives an estimation about the quota of the whole domain of interest of the subnetwork 2 any node in the subnetwork 1 is connected to.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). nsi_cross_degree([0,1,2],[3,4,5]) array([ 4.2, 2.6, 1.4]) >>> InteractingNetworks.SmallTestNetwork(). nsi_cross_degree([0,2,5],[1,4]) array([ 1.4, 2.2, 0. ])
- Parameters:
node_list1 ([int]) – list of node indices describing the subnetwork 1
node_list2 ([int]) – list of node indices describing the subnetwork 2
- Return type:
1D array [node index]
- Returns:
the n.s.i. cross-degree for layer 1.
- nsi_cross_edge_density(node_list1, node_list2)[source]¶
Return the n.s.i. density of edges between two subnetworks.
Examples:
>>> r(InteractingNetworks.SmallTestNetwork(). nsi_cross_edge_density([1,2,3],[0,5])) 0.1091 >>> r(InteractingNetworks.SmallTestNetwork(). nsi_cross_edge_density([0],[1,4,5])) 0.7895
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return float:
the n.s.i. cross density of edges between two subnetworks 1 and 2.
- nsi_cross_global_clustering(node_list1, node_list2)[source]¶
Return the n.s.i. cross-global clustering coefficient for an induced subnetwork 1 with regard to a second induced subnetwork 2.
Examples:
>>> r(InteractingNetworks.SmallTestNetwork(). nsi_cross_global_clustering([0,1,2],[3,4,5])) 0.6688
- Parameters:
node_list1 ([int]) – list of node indices describing the subnetwork 1
node_list2 ([int]) – list of node indices describing the subnetwork 2
- Return float:
the n.s.i. cross-global clustering coefficient for the subnetwork 1 with regard to subnetwork 2.
- nsi_cross_local_clustering(node_list1, node_list2)[source]¶
Return the n.s.i. cross-local clustering coefficient for a pair of induced subnetworks.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). nsi_cross_local_clustering([0,1,2],[3,4,5]) array([ 0.33786848, 0.50295858, 1. ]) >>> InteractingNetworks.SmallTestNetwork(). nsi_cross_local_clustering([0,2,5],[1,4]) array([ 1., 1., 0.])
- Parameters:
node_list1 ([int]) – list of node indices describing the subnetwork 1
node_list2 ([int]) – list of node indices describing the subnetwork 2
- Return type:
1D array [node index]
- Returns:
the n.s.i. cross-local clustering coefficient for layer 1.
- nsi_cross_mean_degree(node_list1, node_list2)[source]¶
Return the n.s.i. cross-mean degree for a pair of induced subnetworks.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). nsi_cross_mean_degree([0,1,2],[3,4,5]) 2.5 >>> r(InteractingNetworks.SmallTestNetwork(). nsi_cross_mean_degree([0,2,5],[1,4])) 0.95
- Parameters:
node_list1 ([int]) – list of node indices describing the subnetwork 1
node_list2 ([int]) – list of node indices describing the subnetwork 2
- Return float:
the n.s.i. cross-mean degree for layer 1.
- nsi_cross_transitivity(node_list1, node_list2)[source]¶
Return n.s.i. cross-transitivity for a pair of subnetworks.
Examples:
>>> r(InteractingNetworks.SmallTestNetwork(). nsi_cross_transitivity([1,2],[0,3,4,5])) 0.6352 >>> InteractingNetworks.SmallTestNetwork(). nsi_cross_transitivity([0,2,3],[1]) 1.0
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return float:
the n.s.i. cross transitivity for a pair of subnetworks 1 and 2.
- nsi_internal_closeness_centrality(node_list)[source]¶
Return the n.s.i. internal closeness sequence of one induced subnetwork.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). nsi_internal_closeness_centrality([0,3,5]) array([ 1. , 0.68 , 0.73913043]) >>> InteractingNetworks.SmallTestNetwork(). nsi_internal_closeness_centrality([0,1,3,5]) array([ 0.84 , 0.525 , 0.72413793, 0.6 ])
- Parameters:
node_list ([int]) – list of node indices describing the subnetwork
- Return type:
1D array [node index]
- Returns:
the n.s.i. internal closeness sequence
- nsi_internal_degree(node_list)[source]¶
Return the n.s.i. internal degree sequence of one induced subnetwork.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). nsi_internal_degree([0,3,5]) array([ 3.4, 1.8, 2.2]) >>> InteractingNetworks.SmallTestNetwork(). nsi_internal_degree([0,1,3,5]) array([ 3.4, 2. , 2.6, 2.2])
- Parameters:
node_list ([int]) – list of node indices describing the subnetwork
- Return type:
1D array [node index]
- Returns:
the n.s.i. internal degree sequence
- nsi_internal_local_clustering(node_list)[source]¶
Return the n.s.i. internal cross-local clustering coefficient for an induced subnetwork.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). nsi_internal_local_clustering([1,2,3,5]) array([ 0.73333333, 1. , 1. , 1. ]) >>> InteractingNetworks.SmallTestNetwork(). nsi_internal_local_clustering([0,2,4]) array([ 1. , 1. , 0.86666667])
- Parameters:
node_list ([int]) – list of node indices describing the subnetwork
- Return type:
1D numpy array [node_index]
- Returns:
the n.s.i. internal-local clustering coefficient for all nodes within the induced subnetwork
- number_cross_links(node_list1, node_list2)[source]¶
Return the number of links connecting the two subnetworks.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). number_cross_links([0,3,5], [1,2,4]) 2 >>> InteractingNetworks.SmallTestNetwork(). number_cross_links([0,5], [1,2,3,4]) 2
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return int:
the number of links between nodes from different subnetworks.
- number_internal_links(node_list)[source]¶
Return the number of links within an induced subnetwork.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). number_internal_links([0,3,5]) 2 >>> InteractingNetworks.SmallTestNetwork(). number_internal_links([1,2,4]) 3
- Parameters:
node_list ([int]) – list of node indices describing the subnetwork
- Return int:
the number of links within a given subnetwork.
- subnetwork(node_list)[source]¶
Return the subnetwork induced by a subset of nodes as a Network object.
This can be used to conveniently analyze the subnetwork separately, e.g., for calculation network measures solely this subnetwork.
- Parameters:
node_list ([int]) – list of node indices describing the subnetwork
- Return type:
- Returns:
the subnetwork induced by the nodes in node_list.
- total_cross_degree(node_list1, node_list2)[source]¶
Return the total cross degree of the two subnetworks.
Examples:
>>> InteractingNetworks.SmallTestNetwork(). toal_cross_degree([0,3,5], [1,2,4]) 1.0 >>> InteractingNetworks.SmallTestNetwork(). total_cross_degree([0,5], [1,2,3,4]).round(4) 0.6667
- Parameters:
node_list1 ([int]) – list of node indices describing the first subnetwork
node_list2 ([int]) – list of node indices describing the second subnetwork
- Return int:
the total cross degree.