{"_id":"@aflsolutions/graphology-communities-leiden","_rev":"3-c8d9e70a064161238026e4a981d3780f","name":"@aflsolutions/graphology-communities-leiden","dist-tags":{"latest":"1.1.1"},"versions":{"1.0.0":{"name":"@aflsolutions/graphology-communities-leiden","version":"1.0.0","keywords":["community","detection","graph","graphology","leiden","clustering"],"author":{"name":"Guillaume Plique","email":"guillaume.plique@sciencespo.fr"},"license":"MIT","_id":"@aflsolutions/graphology-communities-leiden@1.0.0","maintainers":[{"name":"blade47","email":"alessandro.afloarei@outlook.it"}],"homepage":"https://github.com/graphology/graphology#readme","bugs":{"url":"https://github.com/graphology/graphology/issues"},"dist":{"shasum":"e89a44ad0d52371f8dbbbb0344649c32708e9abc","tarball":"https://registry.npmjs.org/@aflsolutions/graphology-communities-leiden/-/graphology-communities-leiden-1.0.0.tgz","fileCount":7,"integrity":"sha512-2o8OhH28vjSdL6udpPrA54cm6IP0GtQAdlDXPEeqU1d/aNmZErR0XZKMuuW3eXIs4iBqfl64Q91fcIIue3MIrQ==","signatures":[{"sig":"MEUCIBODyIdu4sRUbIf83cpoRFT5PO21ruE7X/7vs9x1tsJeAiEAw3VOF0wHm6mm/V8htsElZYSkmStnAS3V1LN3yLZcjTM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":37630},"main":"index.js","types":"index.d.ts","_npmUser":{"name":"blade47","email":"alessandro.afloarei@outlook.it"},"repository":{"url":"git+https://github.com/graphology/graphology.git","type":"git","directory":"src/communities-leiden"},"_npmVersion":"10.9.4","description":"Leiden community detection algorithm for graphology. Extracted from the graphology monorepo.","directories":{},"_nodeVersion":"22.21.1","dependencies":{"mnemonist":"^0.39.0","pandemonium":"^2.4.0","graphology-utils":"^2.3.0","graphology-indices":"^0.17.0"},"_hasShrinkwrap":false,"peerDependencies":{"graphology-types":">=0.19.0"},"_npmOperationalInternal":{"tmp":"tmp/graphology-communities-leiden_1.0.0_1776352575413_0.1222906198688063","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@aflsolutions/graphology-communities-leiden","version":"1.1.0","keywords":["community","detection","graph","graphology","leiden","clustering"],"author":{"name":"Guillaume Plique","email":"guillaume.plique@sciencespo.fr"},"license":"MIT","_id":"@aflsolutions/graphology-communities-leiden@1.1.0","maintainers":[{"name":"blade47","email":"alessandro.afloarei@outlook.it"}],"homepage":"https://github.com/graphology/graphology#readme","bugs":{"url":"https://github.com/graphology/graphology/issues"},"dist":{"shasum":"3b60750db6a5313c090907982eefae047aba7d06","tarball":"https://registry.npmjs.org/@aflsolutions/graphology-communities-leiden/-/graphology-communities-leiden-1.1.0.tgz","fileCount":7,"integrity":"sha512-VZbUCYVPA1J5gWnljej1r323zSq6yYqb1pTsh5h8qWXPq5XBUGS8ojYHk2k5rg0SMCyXHJvZtXREDfQY8kKEew==","signatures":[{"sig":"MEQCIGenwGyJUmmeZTqjLbN4ULVh9Sjocs//5MUszMiTv/efAiADLCAPTH3lCO5c5eb/6jaxoGaPnvIgkJZqBj9f38uUhw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":38884},"main":"index.js","types":"index.d.ts","_npmUser":{"name":"blade47","email":"alessandro.afloarei@outlook.it"},"repository":{"url":"git+https://github.com/graphology/graphology.git","type":"git","directory":"src/communities-leiden"},"_npmVersion":"10.9.4","description":"Leiden community detection algorithm for graphology. Extracted from the graphology monorepo.","directories":{},"_nodeVersion":"22.21.1","dependencies":{"mnemonist":"^0.39.0","pandemonium":"^2.4.0","graphology-utils":"^2.3.0","graphology-indices":"^0.17.0"},"_hasShrinkwrap":false,"devDependencies":{"graphology":"^0.26.0"},"peerDependencies":{"graphology-types":">=0.19.0"},"_npmOperationalInternal":{"tmp":"tmp/graphology-communities-leiden_1.1.0_1777115723442_0.47768523882104663","host":"s3://npm-registry-packages-npm-production"}},"1.1.1":{"name":"@aflsolutions/graphology-communities-leiden","version":"1.1.1","description":"Leiden community detection algorithm for graphology. Extracted from the graphology monorepo.","main":"index.js","types":"index.d.ts","keywords":["community","detection","graph","graphology","leiden","clustering"],"repository":{"type":"git","url":"git+https://github.com/aflsolutions/graphology-communities-leiden.git"},"homepage":"https://github.com/aflsolutions/graphology-communities-leiden#readme","bugs":{"url":"https://github.com/aflsolutions/graphology-communities-leiden/issues"},"author":{"name":"Guillaume Plique","email":"guillaume.plique@sciencespo.fr"},"contributors":[{"name":"Alessandro Afloarei","email":"alessandro.afloarei@aflsolutions.it"}],"license":"MIT","peerDependencies":{"graphology-types":">=0.19.0"},"dependencies":{"graphology-indices":"^0.17.0","graphology-utils":"^2.3.0","mnemonist":"^0.39.0","pandemonium":"^2.4.0"},"devDependencies":{"graphology":"^0.26.0"},"_id":"@aflsolutions/graphology-communities-leiden@1.1.1","gitHead":"ff4199df0953cc9db96d5dce35d19d1e28e0f530","_nodeVersion":"22.21.1","_npmVersion":"10.9.4","dist":{"integrity":"sha512-kqjUf7oofB2c3RKvUIP3dIqwMzZxtVdDYLtr2Z2DFOmWa9RbNfUeQRns+UeODtWtEfwh6j83UiMRxRMDIdGC5A==","shasum":"3addd01257b5950ffbe98b901b9b82ed85fdbd8b","tarball":"https://registry.npmjs.org/@aflsolutions/graphology-communities-leiden/-/graphology-communities-leiden-1.1.1.tgz","fileCount":7,"unpackedSize":38850,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIFHpRDph7Nt+9UR3djBNiJzJg0gve094FWli47wlB3IzAiARoOq5JvinLzrVpMWG541k/fyTU8zKKk37TxiwryFwsQ=="}]},"_npmUser":{"name":"blade47","email":"alessandro.afloarei@outlook.it"},"directories":{},"maintainers":[{"name":"blade47","email":"alessandro.afloarei@outlook.it"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/graphology-communities-leiden_1.1.1_1777194485603_0.36693915607411864"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-16T15:16:15.325Z","modified":"2026-04-26T09:08:05.873Z","1.0.0":"2026-04-16T15:16:15.555Z","1.1.0":"2026-04-25T11:15:23.575Z","1.1.1":"2026-04-26T09:08:05.741Z"},"bugs":{"url":"https://github.com/aflsolutions/graphology-communities-leiden/issues"},"author":{"name":"Guillaume Plique","email":"guillaume.plique@sciencespo.fr"},"license":"MIT","homepage":"https://github.com/aflsolutions/graphology-communities-leiden#readme","keywords":["community","detection","graph","graphology","leiden","clustering"],"repository":{"type":"git","url":"git+https://github.com/aflsolutions/graphology-communities-leiden.git"},"description":"Leiden community detection algorithm for graphology. Extracted from the graphology monorepo.","maintainers":[{"name":"blade47","email":"alessandro.afloarei@outlook.it"}],"readme":"# @aflsolutions/graphology-communities-leiden\n\nLeiden community detection for [`graphology`](https://graphology.github.io), with a hard cap on outer iterations for use on very large graphs.\n\n> **Origin:** This is an extracted, repackaged copy of [`graphology-communities-leiden`](https://github.com/graphology/graphology/tree/master/src/communities-leiden) from the upstream `graphology` monorepo. All credit for the algorithm and its JavaScript implementation goes to Guillaume Plique and the graphology contributors. License is unchanged (MIT).\n\n## Why this fork\n\nThe upstream package runs the outer Leiden loop until convergence. On large code-graph workloads (>100k nodes, >500k edges), this can take minutes per pass and exhibit pathological tail iterations that contribute <2% modularity for >50% of total runtime.\n\nThis fork adds an optional **`maxIterations`** cap so callers can bound runtime on adversarial inputs. The first 2–3 outer iterations capture the bulk of final modularity; after that, returns diminish quickly. Setting `maxIterations: 3` on large graphs typically trades <2% community-quality loss for 5–10× faster runtime.\n\nThe default behavior is unchanged (`maxIterations: 0` = unlimited, run until convergence).\n\n## Changes vs upstream\n\n| File | Change |\n|---|---|\n| `package.json` | Renamed to `@aflsolutions/graphology-communities-leiden`; bumped to `1.1.0`; trimmed `files` to ship only what's needed; kept upstream `repository` field pointing at the original location |\n| `index.d.ts` | Added `maxIterations?: number` to `LeidenOptions` with JSDoc explaining the trade-off |\n| `index.js` | Added `maxIterations: 0` to the `DEFAULTS` object; added a single `if (options.maxIterations > 0 && iteration >= options.maxIterations) break;` guard at the top of the outer `while` loop in `undirectedLeiden` |\n\nNo algorithmic changes. No changes to `utils.js`, `utils.d.ts`, or `LICENSE.txt`. The `directedLeiden` path is untouched (it remains commented out in upstream as well).\n\n## Installation\n\n```sh\nnpm install @aflsolutions/graphology-communities-leiden\n```\n\n## Usage\n\n```js\nimport leiden from '@aflsolutions/graphology-communities-leiden';\n\n// Default: run until convergence (matches upstream)\nconst communities = leiden(graph);\n\n// Bounded: stop after at most 3 outer iterations\nconst communities = leiden(graph, { maxIterations: 3 });\n\n// Assign communities as a node attribute\nleiden.assign(graph, { maxIterations: 3 });\n\n// Detailed output\nconst details = leiden.detailed(graph, { maxIterations: 3 });\n```\n\n### Options\n\nAll upstream options are supported:\n\n- **`attributes.weight`** *(string, default `\"weight\"`)* — name of the edge weight attribute\n- **`attributes.community`** *(string, default `\"community\"`)* — name of the community attribute used by `assign`\n- **`randomWalk`** *(boolean, default `true`)* — traverse the graph randomly\n- **`resolution`** *(number, default `1`)* — higher values produce more communities\n- **`rng`** *(function, default `Math.random`)* — RNG, useful for seeding via [`seedrandom`](https://www.npmjs.com/package/seedrandom)\n- **`weighted`** *(boolean, default `false`)* — take edge weights into account\n\nPlus the new option:\n\n- **`maxIterations`** *(number, default `0`)* — hard cap on outer iterations. `0` = unlimited (upstream default). Setting `N > 0` stops after exactly `N` iterations even if the algorithm has not converged.\n\n### Detailed output\n\n`leiden.detailed(graph, options)` returns:\n\n- `communities` — `{ [node: string]: number }` partition\n- `count` — number of communities\n- `deltaComputations` — number of delta computations run\n- `dendrogram` — array of partitions across the hierarchy\n- `modularity` — final modularity\n- `moves` — array of move counts per iteration\n- `nodesVisited` — total nodes visited across iterations\n- `resolution` — resolution parameter used\n\n## Algorithm\n\nImplements the Leiden algorithm from:\n\n> Traag, V. A., Waltman, L., & van Eck, N. J. (2019). *From Louvain to Leiden: Guaranteeing Well-Connected Communities.* Scientific Reports, 9(1), 5233. doi:10.1038/s41598-019-41695-z. <https://arxiv.org/abs/1810.08473>\n\nReferences list and theoretical background match upstream — see the doc-comment at the top of `index.js`.\n\n## License\n\nMIT, same as upstream. See `LICENSE.txt`.\n","readmeFilename":"README.md","contributors":[{"name":"Alessandro Afloarei","email":"alessandro.afloarei@aflsolutions.it"}]}