Community Plus

class rdigraphs.community_plus.community_plus.CommunityPlus

Bases: object

Generic class for the detection and analysis of communities from graphs

__init__()

Defines variables of the community plus object

__weakref__

list of weak references to the object (if defined)

community_metric(edges, weights, clabels, parameter)

Computes a community metric with respect to a given graph

Parameters:
  • edges (list of tuples of int) – List of edges, as pairs of indices (i, j)

  • weights (list of float) – Weight of each edge

  • clabels (list) – List of community labels

  • cd_alg (str) – Name of the community detection algorithm

  • parameter (str) – Name of the global parameter to compute. Available options are: ‘coverage’, ‘performance’ and ‘modularity’

Returns:

q – Value of the selecte metric

Return type:

float

compare_communities(comm1, comm2, method='vi', remove_none=False)

This is a wrapper to methods compare_communities and split_joing_distance from igraph.

Compares two community structures using various distance measures.

Parameters:
  • comm1 (1st community structure as a membership list)

  • comm2 (2nd community structure as a membership list)

  • method (str) – Measure to use. Options are:

    ‘vi’ | ‘meila’ : variation of information metric [Meila]

    ‘nmi’ | ‘danon’ : normalized mutual information [Danon]

    ‘rand’ : Rand index [Rand],

    ‘adjusted_rand’ : means the adjusted Rand index [Hubert]

    ‘split-join’ : split-join distance [van Dongen]

    ‘split-join-proj’ : assymetric split-join distance [van Dongen]

  • remove_none (boolean) – Whether to remove None entries from the membership lists.

Return type:

The calculated measure.

References

Meila M: Comparing clusterings by the variation of information. In:

Scholkopf B, Warmuth MK (eds). Learning Theory and Kernel Machines: 16th Annual Conference on Computational Learning Theory and 7th Kernel Workship, COLT/Kernel 2003, Washington, DC, USA. LCNS, vol. 2777, Springer, 2003. ISBN: 978-3-540-40720-1.

Danon L, Diaz-Guilera A, Duch J, Arenas A: Comparing community

structure identification. J Stat Mech P09008, 2005.

van Dongen D: Performance criteria for graph clustering and Markov

cluster experiments. Technical Report INS-R0012, National Research Institute for Mathematics and Computer Science in the Netherlands, Amsterdam, May 2000.

Rand WM: Objective criteria for the evaluation of clustering methods.

J Am Stat Assoc 66(336):846-850, 1971.

Hubert L and Arabie P: Comparing partitions. Journal of Classification

2:193-218, 1985.

Notes

‘vi’ and ‘split-join’ are divergence measures (minimum at 0). ‘nmi’, ‘rand’ and ‘adjusted_rand’ are similarity measures (max at 1).

detect_communities(edges, weights, n_nodes=None, alg='louvain', ncmax=None, resolution=1e+100)

Applies a Community Detection algorithm to the graph given by a list of edges and a list of weights.

Parameters:
  • edges (list of tuples of int) – List of edges, as pairs of indices (i, j)

  • weights (list of float) – Weight of each edge

  • n_nodes (int) – Total number of nodes. In general, it must be specified because isolated nodes do not appear in the list of edges. If none, it is taken as the largest index in list or edges

  • ncmax (int) – Number of clusters.

  • alg (string, default=’louvain) – Community detection algorithm. It must be one of ‘louvain’, ‘spectral’, ‘fastgreedy’, ‘walktrap’, ‘infomap’ or ‘labelprop’

  • resolution (float) – Resolution parameter of the Louvain algorithm

Returns:

  • cluster_labels (numpy array) – Index of the cluster assigned to each node

  • cluster_sizes (numpy array) – Size of each cluster