Implementation of the DEMON Algorithm

The ego network in which the ego node has been removed, together with all its attached edges.

// Function to extract ego network minus ego node function egoMinusEgo(node, graph) { const egoNetwork = graph.neighbors(node); egoNetwork.delete(node); // Remove ego node return egoNetwork; }

This implementation defines functions to extract the ego network minus the ego node, apply the Label Propagation algorithm for community detection, and then implements the DEMON algorithm according to the provided pseudo code. We may need to adjust the implementation based on our specific graph data structure and the community detection algorithm we want to use.

// Function to apply Label Propagation algorithm for community detection function labelPropagation(graph) { // Implementation of Label Propagation algorithm // This function returns a mapping of nodes to their community labels // You can replace this with your own implementation of Label Propagation // Placeholder implementation const communityLabels = new Map(); graph.nodes.forEach(node => { communityLabels.set(node, Math.floor(Math.random() * 10)); // Assign random community label }); return communityLabels; }

// Function to discover communities using DEMON algorithm function DEMON(graph) { const communities = new Set(); // External loop: cycle over each individual node graph.nodes.forEach(node => { // Step 1: Compute ego network minus ego node const egoNetwork = egoMinusEgo(node, graph); // Step 2: Compute communities in ego network using Label Propagation const communityLabels = labelPropagation(egoNetwork); // Add discovered communities to the set communityLabels.forEach(label => communities.add(label)); }); return communities; }

// Example usage: // Assuming you have a graph object called 'graph' with nodes and edges const discoveredCommunities = DEMON(graph); console.log("Discovered Communities:", discoveredCommunities);

~

COSCIA, Michele, ROSSETTI, Giulio, GIANNOTTI, Fosca and PEDRESCHI, Dino, 2012. DEMON: a local-first discovery method for overlapping communities. In: Proceedings of the 18th ACM SIGKDD international conference on Knowledge discovery and data mining. Beijing China: ACM. 12 August 2012. p. 615–623. ISBN 978-1-4503-1462-6. DOI 10.1145/2339530.2339630. pdf