UNPKG

entropyx

Version:

A simple data mining library, written in TypeScript

39 lines 1.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CommunityManager = void 0; class CommunityManager { constructor(nodeCount, degrees, totalEdges) { this.nodeToComm = Array.from({ length: nodeCount }, (_, i) => i); this.commDegree = new Map(); this.totalEdges = totalEdges; this.nextCommId = nodeCount; for (let i = 0; i < nodeCount; i++) { this.commDegree.set(i, degrees[i]); } } mergeCommunities(commA, commB) { const degA = this.commDegree.get(commA) ?? 0; const degB = this.commDegree.get(commB) ?? 0; const mergedId = this.nextCommId++; const newDegree = degA + degB; this.commDegree.set(mergedId, newDegree); this.commDegree.delete(commA); this.commDegree.delete(commB); for (let i = 0; i < this.nodeToComm.length; i++) { if (this.nodeToComm[i] === commA || this.nodeToComm[i] === commB) { this.nodeToComm[i] = mergedId; } } return mergedId; } deltaQ(commA, commB, edgesBetween) { const m = this.totalEdges; const degA = this.commDegree.get(commA) ?? 0; const degB = this.commDegree.get(commB) ?? 0; const eAB = edgesBetween / m; const expAB = (degA * degB) / (2 * m * m); return eAB - expAB; } } exports.CommunityManager = CommunityManager; //# sourceMappingURL=community-manager.js.map