centrality#
- centrality(domain, network_name='default_network', edge_weight_name='Distance', method='betweenness', method_kwargs={}, add_as_label_to_objects=True, new_label_name=None, label_cmap='plasma')#
Calculate centrality measures for a given network within a domain and optionally add the results as labels to objects. Centrality measures quantify the importance of nodes in a graph. Implemented centrality measures are:
Betweenness Centrality: The fraction of shortest paths that pass through a node, indicating its role as a bridge.
Closeness Centrality: The inverse of the average shortest path distance to all other nodes, measuring efficiency in reaching others.
Eigenvector Centrality: A measure of influence based on connections to other highly connected nodes.
Katz Centrality: Similar to eigenvector centrality but considers distant connections with an attenuation factor.
Harmonic Centrality: A modification of closeness centrality that handles disconnected components by summing inverse distances.
- Parameters:
- domainobject
The domain object containing the network.
- network_namestr, optional
The name of the network within the domain to analyze (default is ‘default_network’).
- edge_weight_namestr, optional
The name of the edge attribute to use as weight (default is ‘Distance’).
- methodstr, optional
The centrality measure to calculate. Options are ‘katz’, ‘betweeness’, ‘closeness’, ‘laplacian’, ‘eigenvector’, ‘harmonic’ (default is ‘betweeness’).
- method_kwargsdict, optional
Additional keyword arguments to pass to the centrality calculation function (default is an empty dictionary).
- add_as_label_to_objectsbool, optional
Whether to add the centrality results as labels to the objects in the domain (default is True).
- new_label_namestr, optional
The name of the new label to add to the objects. If None, a default name is generated (default is None).
- label_cmapstr, optional
The colormap to use for the labels if they are added to the objects (default is ‘plasma’).
- Returns:
- centralitydict
A dictionary of nodes with their corresponding centrality values.
- Raises:
- ValueError
If the network name is not found in the domain.
- ValueError
If the specified method is not available.
- ValueError
If the edge weight name is not found in the network.
Notes
The method_kwargs are the arguments for the NetworkX centrality functions. For example, for katz_centrality, you might include alpha and beta as shown in the example below.
For all available centrality parameters information, see https://networkx.org/documentation/stable/reference/algorithms/centrality.html.
Examples
>>> method_kwargs = dict(alpha=0.1,beta=1.0) >>> centrality(domain, network_name='my_network', method='katz', method_kwargs=method_kwargs)