community_detection#

community_detection(domain, network_name='default_network', edge_weight_name=None, community_method='louvain', community_method_parameters={'resolution': 1, 'seed': 42, 'threshold': 1e-07}, add_as_label_to_objects=True, community_label_name='community label', community_cmap=None)#

Community detection on a provided network.

Community detection partitions nodes based on their connectivity, providing a way of clustering nodes.

This function will return a list of sets for each community which contain the node indices associated with that community. Egde weights can be used modify the community detection algorithm. The function will also add the community labels to the objects in the domain.

Parameters:
domainobject

The domain object containing the network.

network_namestr, optional

The name of the network, by default ‘default_network’.

edge_weight_namestr or None, optional

The name of the edge weight attribute, by default None.

community_methodstr, optional

The community detection method to use, by default ‘louvain’.

community_method_parametersdict, optional

Parameters for the community detection method, by default {‘resolution’:1,’threshold’:1e-07,’seed’:42}.

add_as_label_to_objectsbool, optional

Whether to add the community labels to the objects, by default True.

community_label_namestr, optional

The name of the community label, by default ‘community label’.

community_cmapcolormap or None, optional

The colormap for the community labels, by default None.

Returns:
dict

A dictionary where keys are community indices and values are lists of node indices in each community.

Raises:
RuntimeError

If the network name is not in the list of generated networks.

RuntimeError

If the edge weight name is not in the list of edge weights for the network.

Notes

The function currently implements the Louvain method for community detection. The Louvain method is a popular algorithm for detecting communities in large networks. It optimises modularity, a measure of the density of links inside communities compared to links between communities.

The main parameters for the Louvain method include:

  • resolution: Controls the size of the detected communities. Higher values lead to smaller communities.

  • threshold: A threshold for the modularity gain to stop the algorithm.

  • seed: A random seed for reproducibility.

For more information, see louvain community detection.