graphwise 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +152 -2
- package/dist/index/index.cjs +65 -117
- package/dist/index/index.cjs.map +1 -1
- package/dist/index/index.js +61 -118
- package/dist/index/index.js.map +1 -1
- package/dist/ranking/mi/adamic-adar.d.ts.map +1 -1
- package/dist/ranking/mi/adaptive.d.ts +1 -1
- package/dist/ranking/mi/adaptive.d.ts.map +1 -1
- package/dist/ranking/mi/etch.d.ts.map +1 -1
- package/dist/ranking/mi/jaccard.d.ts.map +1 -1
- package/dist/ranking/mi/notch.d.ts.map +1 -1
- package/dist/ranking/mi/scale.d.ts.map +1 -1
- package/dist/ranking/mi/skew.d.ts.map +1 -1
- package/dist/ranking/mi/span.d.ts.map +1 -1
- package/dist/utils/index.cjs +82 -0
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +78 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/neighbours.d.ts +54 -0
- package/dist/utils/neighbours.d.ts.map +1 -0
- package/dist/utils/neighbours.unit.test.d.ts +5 -0
- package/dist/utils/neighbours.unit.test.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adamic-adar.d.ts","sourceRoot":"","sources":["../../../src/ranking/mi/adamic-adar.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"adamic-adar.d.ts","sourceRoot":"","sources":["../../../src/ranking/mi/adamic-adar.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,QAAQ,EAChE,KAAK,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,QAAQ,GACf,MAAM,CA8BR"}
|
|
@@ -4,7 +4,7 @@ import { AdaptiveMIConfig } from './types';
|
|
|
4
4
|
* Compute unified adaptive MI between two connected nodes.
|
|
5
5
|
*
|
|
6
6
|
* Combines structural, degree, and overlap signals with
|
|
7
|
-
*
|
|
7
|
+
* configurable weighting.
|
|
8
8
|
*
|
|
9
9
|
* @param graph - Source graph
|
|
10
10
|
* @param source - Source node ID
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adaptive.d.ts","sourceRoot":"","sources":["../../../src/ranking/mi/adaptive.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"adaptive.d.ts","sourceRoot":"","sources":["../../../src/ranking/mi/adaptive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAIhD;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,QAAQ,EAC9D,KAAK,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,gBAAgB,GACvB,MAAM,CA4CR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"etch.d.ts","sourceRoot":"","sources":["../../../src/ranking/mi/etch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"etch.d.ts","sourceRoot":"","sources":["../../../src/ranking/mi/etch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;GAEG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,QAAQ,EAC1D,KAAK,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,QAAQ,GACf,MAAM,CAmCR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jaccard.d.ts","sourceRoot":"","sources":["../../../src/ranking/mi/jaccard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"jaccard.d.ts","sourceRoot":"","sources":["../../../src/ranking/mi/jaccard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,QAAQ,EAC7D,KAAK,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,QAAQ,GACf,MAAM,CAsBR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notch.d.ts","sourceRoot":"","sources":["../../../src/ranking/mi/notch.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"notch.d.ts","sourceRoot":"","sources":["../../../src/ranking/mi/notch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,QAAQ,EAC3D,KAAK,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,QAAQ,GACf,MAAM,CAuCR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scale.d.ts","sourceRoot":"","sources":["../../../src/ranking/mi/scale.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"scale.d.ts","sourceRoot":"","sources":["../../../src/ranking/mi/scale.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,QAAQ,EAC3D,KAAK,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,QAAQ,GACf,MAAM,CA+BR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skew.d.ts","sourceRoot":"","sources":["../../../src/ranking/mi/skew.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"skew.d.ts","sourceRoot":"","sources":["../../../src/ranking/mi/skew.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;GAEG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,QAAQ,EAC1D,KAAK,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,QAAQ,GACf,MAAM,CA0BR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"span.d.ts","sourceRoot":"","sources":["../../../src/ranking/mi/span.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"span.d.ts","sourceRoot":"","sources":["../../../src/ranking/mi/span.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;GAEG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,QAAQ,EAC1D,KAAK,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,QAAQ,GACf,MAAM,CAyBR"}
|
package/dist/utils/index.cjs
CHANGED
|
@@ -161,13 +161,95 @@ function localTypeEntropy(neighbourTypes) {
|
|
|
161
161
|
return normalisedEntropy(probabilities);
|
|
162
162
|
}
|
|
163
163
|
//#endregion
|
|
164
|
+
//#region src/utils/neighbours.ts
|
|
165
|
+
/**
|
|
166
|
+
* Collect neighbours into a Set, optionally excluding a specific node.
|
|
167
|
+
*
|
|
168
|
+
* @param graph - The graph to traverse
|
|
169
|
+
* @param nodeId - The source node
|
|
170
|
+
* @param exclude - Optional node ID to exclude from result
|
|
171
|
+
* @returns A ReadonlySet of neighbouring node IDs
|
|
172
|
+
*/
|
|
173
|
+
function neighbourSet(graph, nodeId, exclude) {
|
|
174
|
+
const neighbours = new Set(graph.neighbours(nodeId));
|
|
175
|
+
if (exclude !== void 0) neighbours.delete(exclude);
|
|
176
|
+
return neighbours;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Compute intersection and union sizes of two neighbour sets without allocating the union set.
|
|
180
|
+
*
|
|
181
|
+
* This is more efficient than computing both separately, as it avoids creating a full union Set.
|
|
182
|
+
*
|
|
183
|
+
* @param a - First neighbourhood set
|
|
184
|
+
* @param b - Second neighbourhood set
|
|
185
|
+
* @returns Object with intersection and union sizes
|
|
186
|
+
*/
|
|
187
|
+
function neighbourOverlap(a, b) {
|
|
188
|
+
let intersection = 0;
|
|
189
|
+
const [smaller, larger] = a.size < b.size ? [a, b] : [b, a];
|
|
190
|
+
for (const node of smaller) if (larger.has(node)) intersection++;
|
|
191
|
+
const union = a.size + b.size - intersection;
|
|
192
|
+
return {
|
|
193
|
+
intersection,
|
|
194
|
+
union
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Return the actual intersection set of two neighbourhood sets.
|
|
199
|
+
*
|
|
200
|
+
* Needed by Adamic-Adar (iterates common neighbours) and ETCH (requires edge types of intersection edges).
|
|
201
|
+
*
|
|
202
|
+
* @param a - First neighbourhood set
|
|
203
|
+
* @param b - Second neighbourhood set
|
|
204
|
+
* @returns A ReadonlySet containing nodes in both a and b
|
|
205
|
+
*/
|
|
206
|
+
function neighbourIntersection(a, b) {
|
|
207
|
+
const intersection = /* @__PURE__ */ new Set();
|
|
208
|
+
const [smaller, larger] = a.size < b.size ? [a, b] : [b, a];
|
|
209
|
+
for (const node of smaller) if (larger.has(node)) intersection.add(node);
|
|
210
|
+
return intersection;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Count the number of edges with a specific type in the graph.
|
|
214
|
+
*
|
|
215
|
+
* Used by ETCH MI variant to compute edge rarity weighting.
|
|
216
|
+
*
|
|
217
|
+
* @param graph - The graph to count edges in
|
|
218
|
+
* @param type - The edge type to count
|
|
219
|
+
* @returns The number of edges with the specified type
|
|
220
|
+
*/
|
|
221
|
+
function countEdgesOfType(graph, type) {
|
|
222
|
+
let count = 0;
|
|
223
|
+
for (const edge of graph.edges()) if (edge.type === type) count++;
|
|
224
|
+
return count;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Count the number of nodes with a specific type in the graph.
|
|
228
|
+
*
|
|
229
|
+
* Used by NOTCH MI variant to compute node rarity weighting.
|
|
230
|
+
*
|
|
231
|
+
* @param graph - The graph to count nodes in
|
|
232
|
+
* @param type - The node type to count
|
|
233
|
+
* @returns The number of nodes with the specified type
|
|
234
|
+
*/
|
|
235
|
+
function countNodesOfType(graph, type) {
|
|
236
|
+
let count = 0;
|
|
237
|
+
for (const nodeId of graph.nodeIds()) if (graph.getNode(nodeId)?.type === type) count++;
|
|
238
|
+
return count;
|
|
239
|
+
}
|
|
240
|
+
//#endregion
|
|
164
241
|
exports._computeMean = require_kmeans._computeMean;
|
|
165
242
|
exports.approximateClusteringCoefficient = approximateClusteringCoefficient;
|
|
166
243
|
exports.batchClusteringCoefficients = batchClusteringCoefficients;
|
|
244
|
+
exports.countEdgesOfType = countEdgesOfType;
|
|
245
|
+
exports.countNodesOfType = countNodesOfType;
|
|
167
246
|
exports.entropyFromCounts = entropyFromCounts;
|
|
168
247
|
exports.localClusteringCoefficient = localClusteringCoefficient;
|
|
169
248
|
exports.localTypeEntropy = localTypeEntropy;
|
|
170
249
|
exports.miniBatchKMeans = require_kmeans.miniBatchKMeans;
|
|
250
|
+
exports.neighbourIntersection = neighbourIntersection;
|
|
251
|
+
exports.neighbourOverlap = neighbourOverlap;
|
|
252
|
+
exports.neighbourSet = neighbourSet;
|
|
171
253
|
exports.normaliseFeatures = require_kmeans.normaliseFeatures;
|
|
172
254
|
exports.zScoreNormalise = require_kmeans.normaliseFeatures;
|
|
173
255
|
exports.normalisedEntropy = normalisedEntropy;
|
package/dist/utils/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/utils/clustering-coefficient.ts","../../src/utils/entropy.ts"],"sourcesContent":["/**\n * Clustering coefficient computation for graph nodes.\n *\n * The local clustering coefficient measures how close a node's neighbours\n * are to being a complete graph (clique). It is used in SPAN MI variant\n * and GRASP seed selection.\n *\n * @packageDocumentation\n */\n\nimport type { ReadableGraph, NodeId } from \"../graph\";\n\n/**\n * Compute the local clustering coefficient for a single node.\n *\n * The clustering coefficient is defined as:\n * CC(v) = (triangles through v) / (possible triangles)\n * CC(v) = 2 * |{(u,w) : u,w in N(v), (u,w) in E}| / (deg(v) * (deg(v) - 1))\n *\n * For nodes with degree < 2, the clustering coefficient is 0.\n *\n * @param graph - The graph to compute on\n * @param nodeId - The node to compute clustering coefficient for\n * @returns The clustering coefficient in [0, 1], or 0 if undefined\n */\nexport function localClusteringCoefficient(\n\tgraph: ReadableGraph,\n\tnodeId: NodeId,\n): number {\n\tconst neighbours = [...graph.neighbours(nodeId, \"both\")];\n\tconst degree = neighbours.length;\n\n\t// Nodes with degree < 2 have no possible triangles\n\tif (degree < 2) {\n\t\treturn 0;\n\t}\n\n\t// Count actual triangles: pairs of neighbours that are connected\n\tlet triangleCount = 0;\n\n\tfor (let i = 0; i < neighbours.length; i++) {\n\t\tconst u = neighbours[i];\n\t\tif (u === undefined) continue;\n\n\t\tfor (let j = i + 1; j < neighbours.length; j++) {\n\t\t\tconst w = neighbours[j];\n\t\t\tif (w === undefined) continue;\n\n\t\t\t// Check if u and w are connected\n\t\t\tif (\n\t\t\t\tgraph.getEdge(u, w) !== undefined ||\n\t\t\t\tgraph.getEdge(w, u) !== undefined\n\t\t\t) {\n\t\t\t\ttriangleCount++;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Possible triangles: deg * (deg - 1) / 2 pairs\n\t// We multiply by 2 because each triangle is counted once\n\tconst possibleTriangles = (degree * (degree - 1)) / 2;\n\n\treturn triangleCount / possibleTriangles;\n}\n\n/**\n * Compute approximate local clustering coefficient using sampling.\n *\n * For nodes with many neighbours, this samples neighbour pairs rather than\n * checking all pairs. Useful for large graphs where exact computation is expensive.\n *\n * @param graph - The graph to compute on\n * @param nodeId - The node to compute clustering coefficient for\n * @param sampleSize - Maximum number of neighbour pairs to check (default: 100)\n * @returns The approximate clustering coefficient in [0, 1]\n */\nexport function approximateClusteringCoefficient(\n\tgraph: ReadableGraph,\n\tnodeId: NodeId,\n\tsampleSize = 100,\n): number {\n\tconst neighbours = [...graph.neighbours(nodeId, \"both\")];\n\tconst degree = neighbours.length;\n\n\tif (degree < 2) {\n\t\treturn 0;\n\t}\n\n\tconst possibleTriangles = (degree * (degree - 1)) / 2;\n\n\t// If all pairs can be checked within sample limit, use exact computation\n\tif (possibleTriangles <= sampleSize) {\n\t\treturn localClusteringCoefficient(graph, nodeId);\n\t}\n\n\t// Sample pairs uniformly\n\tlet triangleCount = 0;\n\tlet sampled = 0;\n\n\t// Use reservoir sampling style approach for pair selection\n\tfor (let i = 0; i < neighbours.length && sampled < sampleSize; i++) {\n\t\tconst u = neighbours[i];\n\t\tif (u === undefined) continue;\n\n\t\tfor (let j = i + 1; j < neighbours.length && sampled < sampleSize; j++) {\n\t\t\tconst w = neighbours[j];\n\t\t\tif (w === undefined) continue;\n\n\t\t\t// Decide whether to include this pair based on remaining budget\n\t\t\tsampled++;\n\n\t\t\t// Check if u and w are connected\n\t\t\tif (\n\t\t\t\tgraph.getEdge(u, w) !== undefined ||\n\t\t\t\tgraph.getEdge(w, u) !== undefined\n\t\t\t) {\n\t\t\t\ttriangleCount++;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Extrapolate from sample\n\treturn (triangleCount / sampled) * (possibleTriangles / possibleTriangles);\n}\n\n/**\n * Compute clustering coefficients for multiple nodes efficiently.\n *\n * Reuses neighbour sets to avoid repeated iteration.\n *\n * @param graph - The graph to compute on\n * @param nodeIds - The nodes to compute clustering coefficients for\n * @returns Map from nodeId to clustering coefficient\n */\nexport function batchClusteringCoefficients(\n\tgraph: ReadableGraph,\n\tnodeIds: readonly NodeId[],\n): Map<NodeId, number> {\n\tconst results = new Map<NodeId, number>();\n\n\tfor (const nodeId of nodeIds) {\n\t\tresults.set(nodeId, localClusteringCoefficient(graph, nodeId));\n\t}\n\n\treturn results;\n}\n","/**\n * Entropy computation utilities for graph analysis.\n *\n * Shannon entropy measures uncertainty or randomness in a distribution.\n * Used in EDGE and HAE algorithms for heterogeneity-aware expansion.\n *\n * @packageDocumentation\n */\n\n/**\n * Compute Shannon entropy of a probability distribution.\n *\n * Shannon entropy is defined as:\n * H(X) = -Σ p(x) × log₂(p(x))\n *\n * A uniform distribution has maximum entropy.\n * A deterministic distribution (all probability on one value) has zero entropy.\n *\n * @param probabilities - Array of probabilities (should sum to 1)\n * @returns Entropy in bits (log base 2), or 0 if probabilities are invalid\n */\nexport function shannonEntropy(probabilities: readonly number[]): number {\n\tif (probabilities.length === 0) {\n\t\treturn 0;\n\t}\n\n\tlet entropy = 0;\n\tfor (const p of probabilities) {\n\t\t// Skip zero probabilities (log(0) is undefined, but 0 * log(0) = 0)\n\t\tif (p > 0) {\n\t\t\tentropy -= p * Math.log2(p);\n\t\t}\n\t}\n\n\treturn entropy;\n}\n\n/**\n * Compute normalised entropy (entropy divided by maximum possible entropy).\n *\n * Normalised entropy is in [0, 1], where:\n * - 0 means the distribution is deterministic (all mass on one value)\n * - 1 means the distribution is uniform (maximum uncertainty)\n *\n * This is useful for comparing entropy across distributions with different\n * numbers of possible values.\n *\n * @param probabilities - Array of probabilities (should sum to 1)\n * @returns Normalised entropy in [0, 1], or 0 if only one category\n */\nexport function normalisedEntropy(probabilities: readonly number[]): number {\n\tif (probabilities.length <= 1) {\n\t\treturn 0;\n\t}\n\n\tconst H = shannonEntropy(probabilities);\n\tconst Hmax = Math.log2(probabilities.length);\n\n\tif (Hmax === 0) {\n\t\treturn 0;\n\t}\n\n\treturn H / Hmax;\n}\n\n/**\n * Compute entropy from a frequency count.\n *\n * Converts counts to probabilities and then computes entropy.\n * This is a convenience function when you have raw counts rather than\n * normalised probabilities.\n *\n * @param counts - Array of frequency counts\n * @returns Entropy in bits\n */\nexport function entropyFromCounts(counts: readonly number[]): number {\n\tif (counts.length === 0) {\n\t\treturn 0;\n\t}\n\n\tconst total = counts.reduce((sum, c) => sum + c, 0);\n\tif (total === 0) {\n\t\treturn 0;\n\t}\n\n\tconst probabilities = counts.map((c) => c / total);\n\treturn shannonEntropy(probabilities);\n}\n\n/**\n * Compute local type entropy for a node's neighbours.\n *\n * This measures the diversity of types among a node's neighbours.\n * High entropy = heterogeneous neighbourhood (diverse types).\n * Low entropy = homogeneous neighbourhood (similar types).\n *\n * @param neighbourTypes - Array of type labels for neighbours\n * @returns Normalised entropy in [0, 1]\n */\nexport function localTypeEntropy(neighbourTypes: readonly string[]): number {\n\tif (neighbourTypes.length <= 1) {\n\t\treturn 0;\n\t}\n\n\t// Count occurrences of each type\n\tconst typeCounts = new Map<string, number>();\n\tfor (const t of neighbourTypes) {\n\t\ttypeCounts.set(t, (typeCounts.get(t) ?? 0) + 1);\n\t}\n\n\t// If all neighbours are the same type, entropy is 0\n\tif (typeCounts.size === 1) {\n\t\treturn 0;\n\t}\n\n\t// Convert to probability array\n\tconst probabilities: number[] = [];\n\tconst total = neighbourTypes.length;\n\tfor (const count of typeCounts.values()) {\n\t\tprobabilities.push(count / total);\n\t}\n\n\treturn normalisedEntropy(probabilities);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAyBA,SAAgB,2BACf,OACA,QACS;CACT,MAAM,aAAa,CAAC,GAAG,MAAM,WAAW,QAAQ,OAAO,CAAC;CACxD,MAAM,SAAS,WAAW;AAG1B,KAAI,SAAS,EACZ,QAAO;CAIR,IAAI,gBAAgB;AAEpB,MAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;EAC3C,MAAM,IAAI,WAAW;AACrB,MAAI,MAAM,KAAA,EAAW;AAErB,OAAK,IAAI,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;GAC/C,MAAM,IAAI,WAAW;AACrB,OAAI,MAAM,KAAA,EAAW;AAGrB,OACC,MAAM,QAAQ,GAAG,EAAE,KAAK,KAAA,KACxB,MAAM,QAAQ,GAAG,EAAE,KAAK,KAAA,EAExB;;;CAOH,MAAM,oBAAqB,UAAU,SAAS,KAAM;AAEpD,QAAO,gBAAgB;;;;;;;;;;;;;AAcxB,SAAgB,iCACf,OACA,QACA,aAAa,KACJ;CACT,MAAM,aAAa,CAAC,GAAG,MAAM,WAAW,QAAQ,OAAO,CAAC;CACxD,MAAM,SAAS,WAAW;AAE1B,KAAI,SAAS,EACZ,QAAO;CAGR,MAAM,oBAAqB,UAAU,SAAS,KAAM;AAGpD,KAAI,qBAAqB,WACxB,QAAO,2BAA2B,OAAO,OAAO;CAIjD,IAAI,gBAAgB;CACpB,IAAI,UAAU;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C3E,KAAI,eAAe,UAAU,EAC5B,QAAO;CAIR,MAAM,6BAAa,IAAI,KAAqB;AAC5C,MAAK,MAAM,KAAK,eACf,YAAW,IAAI,IAAI,WAAW,IAAI,EAAE,IAAI,KAAK,EAAE;AAIhD,KAAI,WAAW,SAAS,EACvB,QAAO;CAIR,MAAM,gBAA0B,EAAE;CAClC,MAAM,QAAQ,eAAe;AAC7B,MAAK,MAAM,SAAS,WAAW,QAAQ,CACtC,eAAc,KAAK,QAAQ,MAAM;AAGlC,QAAO,kBAAkB,cAAc"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/utils/clustering-coefficient.ts","../../src/utils/entropy.ts","../../src/utils/neighbours.ts"],"sourcesContent":["/**\n * Clustering coefficient computation for graph nodes.\n *\n * The local clustering coefficient measures how close a node's neighbours\n * are to being a complete graph (clique). It is used in SPAN MI variant\n * and GRASP seed selection.\n *\n * @packageDocumentation\n */\n\nimport type { ReadableGraph, NodeId } from \"../graph\";\n\n/**\n * Compute the local clustering coefficient for a single node.\n *\n * The clustering coefficient is defined as:\n * CC(v) = (triangles through v) / (possible triangles)\n * CC(v) = 2 * |{(u,w) : u,w in N(v), (u,w) in E}| / (deg(v) * (deg(v) - 1))\n *\n * For nodes with degree < 2, the clustering coefficient is 0.\n *\n * @param graph - The graph to compute on\n * @param nodeId - The node to compute clustering coefficient for\n * @returns The clustering coefficient in [0, 1], or 0 if undefined\n */\nexport function localClusteringCoefficient(\n\tgraph: ReadableGraph,\n\tnodeId: NodeId,\n): number {\n\tconst neighbours = [...graph.neighbours(nodeId, \"both\")];\n\tconst degree = neighbours.length;\n\n\t// Nodes with degree < 2 have no possible triangles\n\tif (degree < 2) {\n\t\treturn 0;\n\t}\n\n\t// Count actual triangles: pairs of neighbours that are connected\n\tlet triangleCount = 0;\n\n\tfor (let i = 0; i < neighbours.length; i++) {\n\t\tconst u = neighbours[i];\n\t\tif (u === undefined) continue;\n\n\t\tfor (let j = i + 1; j < neighbours.length; j++) {\n\t\t\tconst w = neighbours[j];\n\t\t\tif (w === undefined) continue;\n\n\t\t\t// Check if u and w are connected\n\t\t\tif (\n\t\t\t\tgraph.getEdge(u, w) !== undefined ||\n\t\t\t\tgraph.getEdge(w, u) !== undefined\n\t\t\t) {\n\t\t\t\ttriangleCount++;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Possible triangles: deg * (deg - 1) / 2 pairs\n\t// We multiply by 2 because each triangle is counted once\n\tconst possibleTriangles = (degree * (degree - 1)) / 2;\n\n\treturn triangleCount / possibleTriangles;\n}\n\n/**\n * Compute approximate local clustering coefficient using sampling.\n *\n * For nodes with many neighbours, this samples neighbour pairs rather than\n * checking all pairs. Useful for large graphs where exact computation is expensive.\n *\n * @param graph - The graph to compute on\n * @param nodeId - The node to compute clustering coefficient for\n * @param sampleSize - Maximum number of neighbour pairs to check (default: 100)\n * @returns The approximate clustering coefficient in [0, 1]\n */\nexport function approximateClusteringCoefficient(\n\tgraph: ReadableGraph,\n\tnodeId: NodeId,\n\tsampleSize = 100,\n): number {\n\tconst neighbours = [...graph.neighbours(nodeId, \"both\")];\n\tconst degree = neighbours.length;\n\n\tif (degree < 2) {\n\t\treturn 0;\n\t}\n\n\tconst possibleTriangles = (degree * (degree - 1)) / 2;\n\n\t// If all pairs can be checked within sample limit, use exact computation\n\tif (possibleTriangles <= sampleSize) {\n\t\treturn localClusteringCoefficient(graph, nodeId);\n\t}\n\n\t// Sample pairs uniformly\n\tlet triangleCount = 0;\n\tlet sampled = 0;\n\n\t// Use reservoir sampling style approach for pair selection\n\tfor (let i = 0; i < neighbours.length && sampled < sampleSize; i++) {\n\t\tconst u = neighbours[i];\n\t\tif (u === undefined) continue;\n\n\t\tfor (let j = i + 1; j < neighbours.length && sampled < sampleSize; j++) {\n\t\t\tconst w = neighbours[j];\n\t\t\tif (w === undefined) continue;\n\n\t\t\t// Decide whether to include this pair based on remaining budget\n\t\t\tsampled++;\n\n\t\t\t// Check if u and w are connected\n\t\t\tif (\n\t\t\t\tgraph.getEdge(u, w) !== undefined ||\n\t\t\t\tgraph.getEdge(w, u) !== undefined\n\t\t\t) {\n\t\t\t\ttriangleCount++;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Extrapolate from sample\n\treturn (triangleCount / sampled) * (possibleTriangles / possibleTriangles);\n}\n\n/**\n * Compute clustering coefficients for multiple nodes efficiently.\n *\n * Reuses neighbour sets to avoid repeated iteration.\n *\n * @param graph - The graph to compute on\n * @param nodeIds - The nodes to compute clustering coefficients for\n * @returns Map from nodeId to clustering coefficient\n */\nexport function batchClusteringCoefficients(\n\tgraph: ReadableGraph,\n\tnodeIds: readonly NodeId[],\n): Map<NodeId, number> {\n\tconst results = new Map<NodeId, number>();\n\n\tfor (const nodeId of nodeIds) {\n\t\tresults.set(nodeId, localClusteringCoefficient(graph, nodeId));\n\t}\n\n\treturn results;\n}\n","/**\n * Entropy computation utilities for graph analysis.\n *\n * Shannon entropy measures uncertainty or randomness in a distribution.\n * Used in EDGE and HAE algorithms for heterogeneity-aware expansion.\n *\n * @packageDocumentation\n */\n\n/**\n * Compute Shannon entropy of a probability distribution.\n *\n * Shannon entropy is defined as:\n * H(X) = -Σ p(x) × log₂(p(x))\n *\n * A uniform distribution has maximum entropy.\n * A deterministic distribution (all probability on one value) has zero entropy.\n *\n * @param probabilities - Array of probabilities (should sum to 1)\n * @returns Entropy in bits (log base 2), or 0 if probabilities are invalid\n */\nexport function shannonEntropy(probabilities: readonly number[]): number {\n\tif (probabilities.length === 0) {\n\t\treturn 0;\n\t}\n\n\tlet entropy = 0;\n\tfor (const p of probabilities) {\n\t\t// Skip zero probabilities (log(0) is undefined, but 0 * log(0) = 0)\n\t\tif (p > 0) {\n\t\t\tentropy -= p * Math.log2(p);\n\t\t}\n\t}\n\n\treturn entropy;\n}\n\n/**\n * Compute normalised entropy (entropy divided by maximum possible entropy).\n *\n * Normalised entropy is in [0, 1], where:\n * - 0 means the distribution is deterministic (all mass on one value)\n * - 1 means the distribution is uniform (maximum uncertainty)\n *\n * This is useful for comparing entropy across distributions with different\n * numbers of possible values.\n *\n * @param probabilities - Array of probabilities (should sum to 1)\n * @returns Normalised entropy in [0, 1], or 0 if only one category\n */\nexport function normalisedEntropy(probabilities: readonly number[]): number {\n\tif (probabilities.length <= 1) {\n\t\treturn 0;\n\t}\n\n\tconst H = shannonEntropy(probabilities);\n\tconst Hmax = Math.log2(probabilities.length);\n\n\tif (Hmax === 0) {\n\t\treturn 0;\n\t}\n\n\treturn H / Hmax;\n}\n\n/**\n * Compute entropy from a frequency count.\n *\n * Converts counts to probabilities and then computes entropy.\n * This is a convenience function when you have raw counts rather than\n * normalised probabilities.\n *\n * @param counts - Array of frequency counts\n * @returns Entropy in bits\n */\nexport function entropyFromCounts(counts: readonly number[]): number {\n\tif (counts.length === 0) {\n\t\treturn 0;\n\t}\n\n\tconst total = counts.reduce((sum, c) => sum + c, 0);\n\tif (total === 0) {\n\t\treturn 0;\n\t}\n\n\tconst probabilities = counts.map((c) => c / total);\n\treturn shannonEntropy(probabilities);\n}\n\n/**\n * Compute local type entropy for a node's neighbours.\n *\n * This measures the diversity of types among a node's neighbours.\n * High entropy = heterogeneous neighbourhood (diverse types).\n * Low entropy = homogeneous neighbourhood (similar types).\n *\n * @param neighbourTypes - Array of type labels for neighbours\n * @returns Normalised entropy in [0, 1]\n */\nexport function localTypeEntropy(neighbourTypes: readonly string[]): number {\n\tif (neighbourTypes.length <= 1) {\n\t\treturn 0;\n\t}\n\n\t// Count occurrences of each type\n\tconst typeCounts = new Map<string, number>();\n\tfor (const t of neighbourTypes) {\n\t\ttypeCounts.set(t, (typeCounts.get(t) ?? 0) + 1);\n\t}\n\n\t// If all neighbours are the same type, entropy is 0\n\tif (typeCounts.size === 1) {\n\t\treturn 0;\n\t}\n\n\t// Convert to probability array\n\tconst probabilities: number[] = [];\n\tconst total = neighbourTypes.length;\n\tfor (const count of typeCounts.values()) {\n\t\tprobabilities.push(count / total);\n\t}\n\n\treturn normalisedEntropy(probabilities);\n}\n","/**\n * Neighbourhood computation utilities.\n *\n * Shared utilities for neighbourhood operations used by MI variants and other graph algorithms.\n * These functions eliminate duplication of neighbourhood set operations across multiple\n * implementations.\n *\n * @packageDocumentation\n */\n\nimport type { NodeId, NodeData, EdgeData, ReadableGraph } from \"../graph\";\n\n/**\n * Collect neighbours into a Set, optionally excluding a specific node.\n *\n * @param graph - The graph to traverse\n * @param nodeId - The source node\n * @param exclude - Optional node ID to exclude from result\n * @returns A ReadonlySet of neighbouring node IDs\n */\nexport function neighbourSet<N extends NodeData, E extends EdgeData>(\n\tgraph: ReadableGraph<N, E>,\n\tnodeId: NodeId,\n\texclude?: NodeId,\n): ReadonlySet<NodeId> {\n\tconst neighbours = new Set(graph.neighbours(nodeId));\n\tif (exclude !== undefined) {\n\t\tneighbours.delete(exclude);\n\t}\n\treturn neighbours;\n}\n\n/**\n * Compute intersection and union sizes of two neighbour sets without allocating the union set.\n *\n * This is more efficient than computing both separately, as it avoids creating a full union Set.\n *\n * @param a - First neighbourhood set\n * @param b - Second neighbourhood set\n * @returns Object with intersection and union sizes\n */\nexport function neighbourOverlap(\n\ta: ReadonlySet<NodeId>,\n\tb: ReadonlySet<NodeId>,\n): { intersection: number; union: number } {\n\tlet intersection = 0;\n\n\t// Count intersection by iterating through the smaller set\n\tconst [smaller, larger] = a.size < b.size ? [a, b] : [b, a];\n\n\tfor (const node of smaller) {\n\t\tif (larger.has(node)) {\n\t\t\tintersection++;\n\t\t}\n\t}\n\n\t// Union size = size(a) + size(b) - intersection\n\tconst union = a.size + b.size - intersection;\n\n\treturn { intersection, union };\n}\n\n/**\n * Return the actual intersection set of two neighbourhood sets.\n *\n * Needed by Adamic-Adar (iterates common neighbours) and ETCH (requires edge types of intersection edges).\n *\n * @param a - First neighbourhood set\n * @param b - Second neighbourhood set\n * @returns A ReadonlySet containing nodes in both a and b\n */\nexport function neighbourIntersection(\n\ta: ReadonlySet<NodeId>,\n\tb: ReadonlySet<NodeId>,\n): ReadonlySet<NodeId> {\n\tconst intersection = new Set<NodeId>();\n\n\t// Iterate through the smaller set for efficiency\n\tconst [smaller, larger] = a.size < b.size ? [a, b] : [b, a];\n\n\tfor (const node of smaller) {\n\t\tif (larger.has(node)) {\n\t\t\tintersection.add(node);\n\t\t}\n\t}\n\n\treturn intersection;\n}\n\n/**\n * Count the number of edges with a specific type in the graph.\n *\n * Used by ETCH MI variant to compute edge rarity weighting.\n *\n * @param graph - The graph to count edges in\n * @param type - The edge type to count\n * @returns The number of edges with the specified type\n */\nexport function countEdgesOfType<N extends NodeData, E extends EdgeData>(\n\tgraph: ReadableGraph<N, E>,\n\ttype: string,\n): number {\n\tlet count = 0;\n\tfor (const edge of graph.edges()) {\n\t\tif (edge.type === type) {\n\t\t\tcount++;\n\t\t}\n\t}\n\treturn count;\n}\n\n/**\n * Count the number of nodes with a specific type in the graph.\n *\n * Used by NOTCH MI variant to compute node rarity weighting.\n *\n * @param graph - The graph to count nodes in\n * @param type - The node type to count\n * @returns The number of nodes with the specified type\n */\nexport function countNodesOfType<N extends NodeData, E extends EdgeData>(\n\tgraph: ReadableGraph<N, E>,\n\ttype: string,\n): number {\n\tlet count = 0;\n\tfor (const nodeId of graph.nodeIds()) {\n\t\tconst node = graph.getNode(nodeId);\n\t\tif (node?.type === type) {\n\t\t\tcount++;\n\t\t}\n\t}\n\treturn count;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAyBA,SAAgB,2BACf,OACA,QACS;CACT,MAAM,aAAa,CAAC,GAAG,MAAM,WAAW,QAAQ,OAAO,CAAC;CACxD,MAAM,SAAS,WAAW;AAG1B,KAAI,SAAS,EACZ,QAAO;CAIR,IAAI,gBAAgB;AAEpB,MAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;EAC3C,MAAM,IAAI,WAAW;AACrB,MAAI,MAAM,KAAA,EAAW;AAErB,OAAK,IAAI,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;GAC/C,MAAM,IAAI,WAAW;AACrB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AQ,EAAE,OAAO,EAAE,OAAO;AAEhC,QAAO;EAAE;EAAc;EAAO;;;;;;;;;;;AAY/B,SAAgB,sBACf,GACA,GACsB;CACtB,MAAM,+BAAe,IAAI,KAAa;CAGtC,MAAM,CAAC,SAAS,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE;AAE3D,MAAK,MAAM,QAAQ,QAClB,KAAI,OAAO,IAAI,KAAK,CACnB,cAAa,IAAI,KAAK;AAIxB,QAAO;;;;;;;;;;;AAYR,SAAgB,iBACf,OACA,MACS;CACT,IAAI,QAAQ;AACZ,MAAK,MAAM,QAAQ,MAAM,OAAO,CAC/B,KAAI,KAAK,SAAS,KACjB;AAGF,QAAO;;;;;;;;;;;AAYR,SAAgB,iBACf,OACA,MACS;CACT,IAAI,QAAQ;AACZ,MAAK,MAAM,UAAU,MAAM,SAAS,CAEnC,KADa,MAAM,QAAQ,OAAO,EACxB,SAAS,KAClB;AAGF,QAAO"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,0BAA0B,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,0BAA0B,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -160,6 +160,83 @@ function localTypeEntropy(neighbourTypes) {
|
|
|
160
160
|
return normalisedEntropy(probabilities);
|
|
161
161
|
}
|
|
162
162
|
//#endregion
|
|
163
|
-
|
|
163
|
+
//#region src/utils/neighbours.ts
|
|
164
|
+
/**
|
|
165
|
+
* Collect neighbours into a Set, optionally excluding a specific node.
|
|
166
|
+
*
|
|
167
|
+
* @param graph - The graph to traverse
|
|
168
|
+
* @param nodeId - The source node
|
|
169
|
+
* @param exclude - Optional node ID to exclude from result
|
|
170
|
+
* @returns A ReadonlySet of neighbouring node IDs
|
|
171
|
+
*/
|
|
172
|
+
function neighbourSet(graph, nodeId, exclude) {
|
|
173
|
+
const neighbours = new Set(graph.neighbours(nodeId));
|
|
174
|
+
if (exclude !== void 0) neighbours.delete(exclude);
|
|
175
|
+
return neighbours;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Compute intersection and union sizes of two neighbour sets without allocating the union set.
|
|
179
|
+
*
|
|
180
|
+
* This is more efficient than computing both separately, as it avoids creating a full union Set.
|
|
181
|
+
*
|
|
182
|
+
* @param a - First neighbourhood set
|
|
183
|
+
* @param b - Second neighbourhood set
|
|
184
|
+
* @returns Object with intersection and union sizes
|
|
185
|
+
*/
|
|
186
|
+
function neighbourOverlap(a, b) {
|
|
187
|
+
let intersection = 0;
|
|
188
|
+
const [smaller, larger] = a.size < b.size ? [a, b] : [b, a];
|
|
189
|
+
for (const node of smaller) if (larger.has(node)) intersection++;
|
|
190
|
+
const union = a.size + b.size - intersection;
|
|
191
|
+
return {
|
|
192
|
+
intersection,
|
|
193
|
+
union
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Return the actual intersection set of two neighbourhood sets.
|
|
198
|
+
*
|
|
199
|
+
* Needed by Adamic-Adar (iterates common neighbours) and ETCH (requires edge types of intersection edges).
|
|
200
|
+
*
|
|
201
|
+
* @param a - First neighbourhood set
|
|
202
|
+
* @param b - Second neighbourhood set
|
|
203
|
+
* @returns A ReadonlySet containing nodes in both a and b
|
|
204
|
+
*/
|
|
205
|
+
function neighbourIntersection(a, b) {
|
|
206
|
+
const intersection = /* @__PURE__ */ new Set();
|
|
207
|
+
const [smaller, larger] = a.size < b.size ? [a, b] : [b, a];
|
|
208
|
+
for (const node of smaller) if (larger.has(node)) intersection.add(node);
|
|
209
|
+
return intersection;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Count the number of edges with a specific type in the graph.
|
|
213
|
+
*
|
|
214
|
+
* Used by ETCH MI variant to compute edge rarity weighting.
|
|
215
|
+
*
|
|
216
|
+
* @param graph - The graph to count edges in
|
|
217
|
+
* @param type - The edge type to count
|
|
218
|
+
* @returns The number of edges with the specified type
|
|
219
|
+
*/
|
|
220
|
+
function countEdgesOfType(graph, type) {
|
|
221
|
+
let count = 0;
|
|
222
|
+
for (const edge of graph.edges()) if (edge.type === type) count++;
|
|
223
|
+
return count;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Count the number of nodes with a specific type in the graph.
|
|
227
|
+
*
|
|
228
|
+
* Used by NOTCH MI variant to compute node rarity weighting.
|
|
229
|
+
*
|
|
230
|
+
* @param graph - The graph to count nodes in
|
|
231
|
+
* @param type - The node type to count
|
|
232
|
+
* @returns The number of nodes with the specified type
|
|
233
|
+
*/
|
|
234
|
+
function countNodesOfType(graph, type) {
|
|
235
|
+
let count = 0;
|
|
236
|
+
for (const nodeId of graph.nodeIds()) if (graph.getNode(nodeId)?.type === type) count++;
|
|
237
|
+
return count;
|
|
238
|
+
}
|
|
239
|
+
//#endregion
|
|
240
|
+
export { _computeMean, approximateClusteringCoefficient, batchClusteringCoefficients, countEdgesOfType, countNodesOfType, entropyFromCounts, localClusteringCoefficient, localTypeEntropy, miniBatchKMeans, neighbourIntersection, neighbourOverlap, neighbourSet, normaliseFeatures, normaliseFeatures as zScoreNormalise, normalisedEntropy, shannonEntropy };
|
|
164
241
|
|
|
165
242
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/utils/clustering-coefficient.ts","../../src/utils/entropy.ts"],"sourcesContent":["/**\n * Clustering coefficient computation for graph nodes.\n *\n * The local clustering coefficient measures how close a node's neighbours\n * are to being a complete graph (clique). It is used in SPAN MI variant\n * and GRASP seed selection.\n *\n * @packageDocumentation\n */\n\nimport type { ReadableGraph, NodeId } from \"../graph\";\n\n/**\n * Compute the local clustering coefficient for a single node.\n *\n * The clustering coefficient is defined as:\n * CC(v) = (triangles through v) / (possible triangles)\n * CC(v) = 2 * |{(u,w) : u,w in N(v), (u,w) in E}| / (deg(v) * (deg(v) - 1))\n *\n * For nodes with degree < 2, the clustering coefficient is 0.\n *\n * @param graph - The graph to compute on\n * @param nodeId - The node to compute clustering coefficient for\n * @returns The clustering coefficient in [0, 1], or 0 if undefined\n */\nexport function localClusteringCoefficient(\n\tgraph: ReadableGraph,\n\tnodeId: NodeId,\n): number {\n\tconst neighbours = [...graph.neighbours(nodeId, \"both\")];\n\tconst degree = neighbours.length;\n\n\t// Nodes with degree < 2 have no possible triangles\n\tif (degree < 2) {\n\t\treturn 0;\n\t}\n\n\t// Count actual triangles: pairs of neighbours that are connected\n\tlet triangleCount = 0;\n\n\tfor (let i = 0; i < neighbours.length; i++) {\n\t\tconst u = neighbours[i];\n\t\tif (u === undefined) continue;\n\n\t\tfor (let j = i + 1; j < neighbours.length; j++) {\n\t\t\tconst w = neighbours[j];\n\t\t\tif (w === undefined) continue;\n\n\t\t\t// Check if u and w are connected\n\t\t\tif (\n\t\t\t\tgraph.getEdge(u, w) !== undefined ||\n\t\t\t\tgraph.getEdge(w, u) !== undefined\n\t\t\t) {\n\t\t\t\ttriangleCount++;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Possible triangles: deg * (deg - 1) / 2 pairs\n\t// We multiply by 2 because each triangle is counted once\n\tconst possibleTriangles = (degree * (degree - 1)) / 2;\n\n\treturn triangleCount / possibleTriangles;\n}\n\n/**\n * Compute approximate local clustering coefficient using sampling.\n *\n * For nodes with many neighbours, this samples neighbour pairs rather than\n * checking all pairs. Useful for large graphs where exact computation is expensive.\n *\n * @param graph - The graph to compute on\n * @param nodeId - The node to compute clustering coefficient for\n * @param sampleSize - Maximum number of neighbour pairs to check (default: 100)\n * @returns The approximate clustering coefficient in [0, 1]\n */\nexport function approximateClusteringCoefficient(\n\tgraph: ReadableGraph,\n\tnodeId: NodeId,\n\tsampleSize = 100,\n): number {\n\tconst neighbours = [...graph.neighbours(nodeId, \"both\")];\n\tconst degree = neighbours.length;\n\n\tif (degree < 2) {\n\t\treturn 0;\n\t}\n\n\tconst possibleTriangles = (degree * (degree - 1)) / 2;\n\n\t// If all pairs can be checked within sample limit, use exact computation\n\tif (possibleTriangles <= sampleSize) {\n\t\treturn localClusteringCoefficient(graph, nodeId);\n\t}\n\n\t// Sample pairs uniformly\n\tlet triangleCount = 0;\n\tlet sampled = 0;\n\n\t// Use reservoir sampling style approach for pair selection\n\tfor (let i = 0; i < neighbours.length && sampled < sampleSize; i++) {\n\t\tconst u = neighbours[i];\n\t\tif (u === undefined) continue;\n\n\t\tfor (let j = i + 1; j < neighbours.length && sampled < sampleSize; j++) {\n\t\t\tconst w = neighbours[j];\n\t\t\tif (w === undefined) continue;\n\n\t\t\t// Decide whether to include this pair based on remaining budget\n\t\t\tsampled++;\n\n\t\t\t// Check if u and w are connected\n\t\t\tif (\n\t\t\t\tgraph.getEdge(u, w) !== undefined ||\n\t\t\t\tgraph.getEdge(w, u) !== undefined\n\t\t\t) {\n\t\t\t\ttriangleCount++;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Extrapolate from sample\n\treturn (triangleCount / sampled) * (possibleTriangles / possibleTriangles);\n}\n\n/**\n * Compute clustering coefficients for multiple nodes efficiently.\n *\n * Reuses neighbour sets to avoid repeated iteration.\n *\n * @param graph - The graph to compute on\n * @param nodeIds - The nodes to compute clustering coefficients for\n * @returns Map from nodeId to clustering coefficient\n */\nexport function batchClusteringCoefficients(\n\tgraph: ReadableGraph,\n\tnodeIds: readonly NodeId[],\n): Map<NodeId, number> {\n\tconst results = new Map<NodeId, number>();\n\n\tfor (const nodeId of nodeIds) {\n\t\tresults.set(nodeId, localClusteringCoefficient(graph, nodeId));\n\t}\n\n\treturn results;\n}\n","/**\n * Entropy computation utilities for graph analysis.\n *\n * Shannon entropy measures uncertainty or randomness in a distribution.\n * Used in EDGE and HAE algorithms for heterogeneity-aware expansion.\n *\n * @packageDocumentation\n */\n\n/**\n * Compute Shannon entropy of a probability distribution.\n *\n * Shannon entropy is defined as:\n * H(X) = -Σ p(x) × log₂(p(x))\n *\n * A uniform distribution has maximum entropy.\n * A deterministic distribution (all probability on one value) has zero entropy.\n *\n * @param probabilities - Array of probabilities (should sum to 1)\n * @returns Entropy in bits (log base 2), or 0 if probabilities are invalid\n */\nexport function shannonEntropy(probabilities: readonly number[]): number {\n\tif (probabilities.length === 0) {\n\t\treturn 0;\n\t}\n\n\tlet entropy = 0;\n\tfor (const p of probabilities) {\n\t\t// Skip zero probabilities (log(0) is undefined, but 0 * log(0) = 0)\n\t\tif (p > 0) {\n\t\t\tentropy -= p * Math.log2(p);\n\t\t}\n\t}\n\n\treturn entropy;\n}\n\n/**\n * Compute normalised entropy (entropy divided by maximum possible entropy).\n *\n * Normalised entropy is in [0, 1], where:\n * - 0 means the distribution is deterministic (all mass on one value)\n * - 1 means the distribution is uniform (maximum uncertainty)\n *\n * This is useful for comparing entropy across distributions with different\n * numbers of possible values.\n *\n * @param probabilities - Array of probabilities (should sum to 1)\n * @returns Normalised entropy in [0, 1], or 0 if only one category\n */\nexport function normalisedEntropy(probabilities: readonly number[]): number {\n\tif (probabilities.length <= 1) {\n\t\treturn 0;\n\t}\n\n\tconst H = shannonEntropy(probabilities);\n\tconst Hmax = Math.log2(probabilities.length);\n\n\tif (Hmax === 0) {\n\t\treturn 0;\n\t}\n\n\treturn H / Hmax;\n}\n\n/**\n * Compute entropy from a frequency count.\n *\n * Converts counts to probabilities and then computes entropy.\n * This is a convenience function when you have raw counts rather than\n * normalised probabilities.\n *\n * @param counts - Array of frequency counts\n * @returns Entropy in bits\n */\nexport function entropyFromCounts(counts: readonly number[]): number {\n\tif (counts.length === 0) {\n\t\treturn 0;\n\t}\n\n\tconst total = counts.reduce((sum, c) => sum + c, 0);\n\tif (total === 0) {\n\t\treturn 0;\n\t}\n\n\tconst probabilities = counts.map((c) => c / total);\n\treturn shannonEntropy(probabilities);\n}\n\n/**\n * Compute local type entropy for a node's neighbours.\n *\n * This measures the diversity of types among a node's neighbours.\n * High entropy = heterogeneous neighbourhood (diverse types).\n * Low entropy = homogeneous neighbourhood (similar types).\n *\n * @param neighbourTypes - Array of type labels for neighbours\n * @returns Normalised entropy in [0, 1]\n */\nexport function localTypeEntropy(neighbourTypes: readonly string[]): number {\n\tif (neighbourTypes.length <= 1) {\n\t\treturn 0;\n\t}\n\n\t// Count occurrences of each type\n\tconst typeCounts = new Map<string, number>();\n\tfor (const t of neighbourTypes) {\n\t\ttypeCounts.set(t, (typeCounts.get(t) ?? 0) + 1);\n\t}\n\n\t// If all neighbours are the same type, entropy is 0\n\tif (typeCounts.size === 1) {\n\t\treturn 0;\n\t}\n\n\t// Convert to probability array\n\tconst probabilities: number[] = [];\n\tconst total = neighbourTypes.length;\n\tfor (const count of typeCounts.values()) {\n\t\tprobabilities.push(count / total);\n\t}\n\n\treturn normalisedEntropy(probabilities);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyBA,SAAgB,2BACf,OACA,QACS;CACT,MAAM,aAAa,CAAC,GAAG,MAAM,WAAW,QAAQ,OAAO,CAAC;CACxD,MAAM,SAAS,WAAW;AAG1B,KAAI,SAAS,EACZ,QAAO;CAIR,IAAI,gBAAgB;AAEpB,MAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;EAC3C,MAAM,IAAI,WAAW;AACrB,MAAI,MAAM,KAAA,EAAW;AAErB,OAAK,IAAI,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;GAC/C,MAAM,IAAI,WAAW;AACrB,OAAI,MAAM,KAAA,EAAW;AAGrB,OACC,MAAM,QAAQ,GAAG,EAAE,KAAK,KAAA,KAC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AAc,UAAU,EAC3B,QAAO;CAGR,MAAM,IAAI,eAAe,cAAc;CACvC,MAAM,OAAO,KAAK,KAAK,cAAc,OAAO;AAE5C,KAAI,SAAS,EACZ,QAAO;AAGR,QAAO,IAAI;;;;;;;;;;;;AAaZ,SAAgB,kBAAkB,QAAmC;AACpE,KAAI,OAAO,WAAW,EACrB,QAAO;CAGR,MAAM,QAAQ,OAAO,QAAQ,KAAK,MAAM,MAAM,GAAG,EAAE;AACnD,KAAI,UAAU,EACb,QAAO;AAIR,QAAO,eADe,OAAO,KAAK,MAAM,IAAI,MAAM,CACd;;;;;;;;;;;;AAarC,SAAgB,iBAAiB,gBAA2C;AAC3E,KAAI,eAAe,UAAU,EAC5B,QAAO;CAIR,MAAM,6BAAa,IAAI,KAAqB;AAC5C,MAAK,MAAM,KAAK,eACf,YAAW,IAAI,IAAI,WAAW,IAAI,EAAE,IAAI,KAAK,EAAE;AAIhD,KAAI,WAAW,SAAS,EACvB,QAAO;CAIR,MAAM,gBAA0B,EAAE;CAClC,MAAM,QAAQ,eAAe;AAC7B,MAAK,MAAM,SAAS,WAAW,QAAQ,CACtC,eAAc,KAAK,QAAQ,MAAM;AAGlC,QAAO,kBAAkB,cAAc"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/utils/clustering-coefficient.ts","../../src/utils/entropy.ts","../../src/utils/neighbours.ts"],"sourcesContent":["/**\n * Clustering coefficient computation for graph nodes.\n *\n * The local clustering coefficient measures how close a node's neighbours\n * are to being a complete graph (clique). It is used in SPAN MI variant\n * and GRASP seed selection.\n *\n * @packageDocumentation\n */\n\nimport type { ReadableGraph, NodeId } from \"../graph\";\n\n/**\n * Compute the local clustering coefficient for a single node.\n *\n * The clustering coefficient is defined as:\n * CC(v) = (triangles through v) / (possible triangles)\n * CC(v) = 2 * |{(u,w) : u,w in N(v), (u,w) in E}| / (deg(v) * (deg(v) - 1))\n *\n * For nodes with degree < 2, the clustering coefficient is 0.\n *\n * @param graph - The graph to compute on\n * @param nodeId - The node to compute clustering coefficient for\n * @returns The clustering coefficient in [0, 1], or 0 if undefined\n */\nexport function localClusteringCoefficient(\n\tgraph: ReadableGraph,\n\tnodeId: NodeId,\n): number {\n\tconst neighbours = [...graph.neighbours(nodeId, \"both\")];\n\tconst degree = neighbours.length;\n\n\t// Nodes with degree < 2 have no possible triangles\n\tif (degree < 2) {\n\t\treturn 0;\n\t}\n\n\t// Count actual triangles: pairs of neighbours that are connected\n\tlet triangleCount = 0;\n\n\tfor (let i = 0; i < neighbours.length; i++) {\n\t\tconst u = neighbours[i];\n\t\tif (u === undefined) continue;\n\n\t\tfor (let j = i + 1; j < neighbours.length; j++) {\n\t\t\tconst w = neighbours[j];\n\t\t\tif (w === undefined) continue;\n\n\t\t\t// Check if u and w are connected\n\t\t\tif (\n\t\t\t\tgraph.getEdge(u, w) !== undefined ||\n\t\t\t\tgraph.getEdge(w, u) !== undefined\n\t\t\t) {\n\t\t\t\ttriangleCount++;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Possible triangles: deg * (deg - 1) / 2 pairs\n\t// We multiply by 2 because each triangle is counted once\n\tconst possibleTriangles = (degree * (degree - 1)) / 2;\n\n\treturn triangleCount / possibleTriangles;\n}\n\n/**\n * Compute approximate local clustering coefficient using sampling.\n *\n * For nodes with many neighbours, this samples neighbour pairs rather than\n * checking all pairs. Useful for large graphs where exact computation is expensive.\n *\n * @param graph - The graph to compute on\n * @param nodeId - The node to compute clustering coefficient for\n * @param sampleSize - Maximum number of neighbour pairs to check (default: 100)\n * @returns The approximate clustering coefficient in [0, 1]\n */\nexport function approximateClusteringCoefficient(\n\tgraph: ReadableGraph,\n\tnodeId: NodeId,\n\tsampleSize = 100,\n): number {\n\tconst neighbours = [...graph.neighbours(nodeId, \"both\")];\n\tconst degree = neighbours.length;\n\n\tif (degree < 2) {\n\t\treturn 0;\n\t}\n\n\tconst possibleTriangles = (degree * (degree - 1)) / 2;\n\n\t// If all pairs can be checked within sample limit, use exact computation\n\tif (possibleTriangles <= sampleSize) {\n\t\treturn localClusteringCoefficient(graph, nodeId);\n\t}\n\n\t// Sample pairs uniformly\n\tlet triangleCount = 0;\n\tlet sampled = 0;\n\n\t// Use reservoir sampling style approach for pair selection\n\tfor (let i = 0; i < neighbours.length && sampled < sampleSize; i++) {\n\t\tconst u = neighbours[i];\n\t\tif (u === undefined) continue;\n\n\t\tfor (let j = i + 1; j < neighbours.length && sampled < sampleSize; j++) {\n\t\t\tconst w = neighbours[j];\n\t\t\tif (w === undefined) continue;\n\n\t\t\t// Decide whether to include this pair based on remaining budget\n\t\t\tsampled++;\n\n\t\t\t// Check if u and w are connected\n\t\t\tif (\n\t\t\t\tgraph.getEdge(u, w) !== undefined ||\n\t\t\t\tgraph.getEdge(w, u) !== undefined\n\t\t\t) {\n\t\t\t\ttriangleCount++;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Extrapolate from sample\n\treturn (triangleCount / sampled) * (possibleTriangles / possibleTriangles);\n}\n\n/**\n * Compute clustering coefficients for multiple nodes efficiently.\n *\n * Reuses neighbour sets to avoid repeated iteration.\n *\n * @param graph - The graph to compute on\n * @param nodeIds - The nodes to compute clustering coefficients for\n * @returns Map from nodeId to clustering coefficient\n */\nexport function batchClusteringCoefficients(\n\tgraph: ReadableGraph,\n\tnodeIds: readonly NodeId[],\n): Map<NodeId, number> {\n\tconst results = new Map<NodeId, number>();\n\n\tfor (const nodeId of nodeIds) {\n\t\tresults.set(nodeId, localClusteringCoefficient(graph, nodeId));\n\t}\n\n\treturn results;\n}\n","/**\n * Entropy computation utilities for graph analysis.\n *\n * Shannon entropy measures uncertainty or randomness in a distribution.\n * Used in EDGE and HAE algorithms for heterogeneity-aware expansion.\n *\n * @packageDocumentation\n */\n\n/**\n * Compute Shannon entropy of a probability distribution.\n *\n * Shannon entropy is defined as:\n * H(X) = -Σ p(x) × log₂(p(x))\n *\n * A uniform distribution has maximum entropy.\n * A deterministic distribution (all probability on one value) has zero entropy.\n *\n * @param probabilities - Array of probabilities (should sum to 1)\n * @returns Entropy in bits (log base 2), or 0 if probabilities are invalid\n */\nexport function shannonEntropy(probabilities: readonly number[]): number {\n\tif (probabilities.length === 0) {\n\t\treturn 0;\n\t}\n\n\tlet entropy = 0;\n\tfor (const p of probabilities) {\n\t\t// Skip zero probabilities (log(0) is undefined, but 0 * log(0) = 0)\n\t\tif (p > 0) {\n\t\t\tentropy -= p * Math.log2(p);\n\t\t}\n\t}\n\n\treturn entropy;\n}\n\n/**\n * Compute normalised entropy (entropy divided by maximum possible entropy).\n *\n * Normalised entropy is in [0, 1], where:\n * - 0 means the distribution is deterministic (all mass on one value)\n * - 1 means the distribution is uniform (maximum uncertainty)\n *\n * This is useful for comparing entropy across distributions with different\n * numbers of possible values.\n *\n * @param probabilities - Array of probabilities (should sum to 1)\n * @returns Normalised entropy in [0, 1], or 0 if only one category\n */\nexport function normalisedEntropy(probabilities: readonly number[]): number {\n\tif (probabilities.length <= 1) {\n\t\treturn 0;\n\t}\n\n\tconst H = shannonEntropy(probabilities);\n\tconst Hmax = Math.log2(probabilities.length);\n\n\tif (Hmax === 0) {\n\t\treturn 0;\n\t}\n\n\treturn H / Hmax;\n}\n\n/**\n * Compute entropy from a frequency count.\n *\n * Converts counts to probabilities and then computes entropy.\n * This is a convenience function when you have raw counts rather than\n * normalised probabilities.\n *\n * @param counts - Array of frequency counts\n * @returns Entropy in bits\n */\nexport function entropyFromCounts(counts: readonly number[]): number {\n\tif (counts.length === 0) {\n\t\treturn 0;\n\t}\n\n\tconst total = counts.reduce((sum, c) => sum + c, 0);\n\tif (total === 0) {\n\t\treturn 0;\n\t}\n\n\tconst probabilities = counts.map((c) => c / total);\n\treturn shannonEntropy(probabilities);\n}\n\n/**\n * Compute local type entropy for a node's neighbours.\n *\n * This measures the diversity of types among a node's neighbours.\n * High entropy = heterogeneous neighbourhood (diverse types).\n * Low entropy = homogeneous neighbourhood (similar types).\n *\n * @param neighbourTypes - Array of type labels for neighbours\n * @returns Normalised entropy in [0, 1]\n */\nexport function localTypeEntropy(neighbourTypes: readonly string[]): number {\n\tif (neighbourTypes.length <= 1) {\n\t\treturn 0;\n\t}\n\n\t// Count occurrences of each type\n\tconst typeCounts = new Map<string, number>();\n\tfor (const t of neighbourTypes) {\n\t\ttypeCounts.set(t, (typeCounts.get(t) ?? 0) + 1);\n\t}\n\n\t// If all neighbours are the same type, entropy is 0\n\tif (typeCounts.size === 1) {\n\t\treturn 0;\n\t}\n\n\t// Convert to probability array\n\tconst probabilities: number[] = [];\n\tconst total = neighbourTypes.length;\n\tfor (const count of typeCounts.values()) {\n\t\tprobabilities.push(count / total);\n\t}\n\n\treturn normalisedEntropy(probabilities);\n}\n","/**\n * Neighbourhood computation utilities.\n *\n * Shared utilities for neighbourhood operations used by MI variants and other graph algorithms.\n * These functions eliminate duplication of neighbourhood set operations across multiple\n * implementations.\n *\n * @packageDocumentation\n */\n\nimport type { NodeId, NodeData, EdgeData, ReadableGraph } from \"../graph\";\n\n/**\n * Collect neighbours into a Set, optionally excluding a specific node.\n *\n * @param graph - The graph to traverse\n * @param nodeId - The source node\n * @param exclude - Optional node ID to exclude from result\n * @returns A ReadonlySet of neighbouring node IDs\n */\nexport function neighbourSet<N extends NodeData, E extends EdgeData>(\n\tgraph: ReadableGraph<N, E>,\n\tnodeId: NodeId,\n\texclude?: NodeId,\n): ReadonlySet<NodeId> {\n\tconst neighbours = new Set(graph.neighbours(nodeId));\n\tif (exclude !== undefined) {\n\t\tneighbours.delete(exclude);\n\t}\n\treturn neighbours;\n}\n\n/**\n * Compute intersection and union sizes of two neighbour sets without allocating the union set.\n *\n * This is more efficient than computing both separately, as it avoids creating a full union Set.\n *\n * @param a - First neighbourhood set\n * @param b - Second neighbourhood set\n * @returns Object with intersection and union sizes\n */\nexport function neighbourOverlap(\n\ta: ReadonlySet<NodeId>,\n\tb: ReadonlySet<NodeId>,\n): { intersection: number; union: number } {\n\tlet intersection = 0;\n\n\t// Count intersection by iterating through the smaller set\n\tconst [smaller, larger] = a.size < b.size ? [a, b] : [b, a];\n\n\tfor (const node of smaller) {\n\t\tif (larger.has(node)) {\n\t\t\tintersection++;\n\t\t}\n\t}\n\n\t// Union size = size(a) + size(b) - intersection\n\tconst union = a.size + b.size - intersection;\n\n\treturn { intersection, union };\n}\n\n/**\n * Return the actual intersection set of two neighbourhood sets.\n *\n * Needed by Adamic-Adar (iterates common neighbours) and ETCH (requires edge types of intersection edges).\n *\n * @param a - First neighbourhood set\n * @param b - Second neighbourhood set\n * @returns A ReadonlySet containing nodes in both a and b\n */\nexport function neighbourIntersection(\n\ta: ReadonlySet<NodeId>,\n\tb: ReadonlySet<NodeId>,\n): ReadonlySet<NodeId> {\n\tconst intersection = new Set<NodeId>();\n\n\t// Iterate through the smaller set for efficiency\n\tconst [smaller, larger] = a.size < b.size ? [a, b] : [b, a];\n\n\tfor (const node of smaller) {\n\t\tif (larger.has(node)) {\n\t\t\tintersection.add(node);\n\t\t}\n\t}\n\n\treturn intersection;\n}\n\n/**\n * Count the number of edges with a specific type in the graph.\n *\n * Used by ETCH MI variant to compute edge rarity weighting.\n *\n * @param graph - The graph to count edges in\n * @param type - The edge type to count\n * @returns The number of edges with the specified type\n */\nexport function countEdgesOfType<N extends NodeData, E extends EdgeData>(\n\tgraph: ReadableGraph<N, E>,\n\ttype: string,\n): number {\n\tlet count = 0;\n\tfor (const edge of graph.edges()) {\n\t\tif (edge.type === type) {\n\t\t\tcount++;\n\t\t}\n\t}\n\treturn count;\n}\n\n/**\n * Count the number of nodes with a specific type in the graph.\n *\n * Used by NOTCH MI variant to compute node rarity weighting.\n *\n * @param graph - The graph to count nodes in\n * @param type - The node type to count\n * @returns The number of nodes with the specified type\n */\nexport function countNodesOfType<N extends NodeData, E extends EdgeData>(\n\tgraph: ReadableGraph<N, E>,\n\ttype: string,\n): number {\n\tlet count = 0;\n\tfor (const nodeId of graph.nodeIds()) {\n\t\tconst node = graph.getNode(nodeId);\n\t\tif (node?.type === type) {\n\t\t\tcount++;\n\t\t}\n\t}\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B,cAAc;;;;;;;;;;;;ACtGxC,SAAgB,aACf,OACA,QACA,SACsB;CACtB,MAAM,aAAa,IAAI,IAAI,MAAM,WAAW,OAAO,CAAC;AACpD,KAAI,YAAY,KAAA,EACf,YAAW,OAAO,QAAQ;AAE3B,QAAO;;;;;;;;;;;AAYR,SAAgB,iBACf,GACA,GAC0C;CAC1C,IAAI,eAAe;CAGnB,MAAM,CAAC,SAAS,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE;AAE3D,MAAK,MAAM,QAAQ,QAClB,KAAI,OAAO,IAAI,KAAK,CACnB;CAKF,MAAM,QAAQ,EAAE,OAAO,EAAE,OAAO;AAEhC,QAAO;EAAE;EAAc;EAAO;;;;;;;;;;;AAY/B,SAAgB,sBACf,GACA,GACsB;CACtB,MAAM,+BAAe,IAAI,KAAa;CAGtC,MAAM,CAAC,SAAS,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE;AAE3D,MAAK,MAAM,QAAQ,QAClB,KAAI,OAAO,IAAI,KAAK,CACnB,cAAa,IAAI,KAAK;AAIxB,QAAO;;;;;;;;;;;AAYR,SAAgB,iBACf,OACA,MACS;CACT,IAAI,QAAQ;AACZ,MAAK,MAAM,QAAQ,MAAM,OAAO,CAC/B,KAAI,KAAK,SAAS,KACjB;AAGF,QAAO;;;;;;;;;;;AAYR,SAAgB,iBACf,OACA,MACS;CACT,IAAI,QAAQ;AACZ,MAAK,MAAM,UAAU,MAAM,SAAS,CAEnC,KADa,MAAM,QAAQ,OAAO,EACxB,SAAS,KAClB;AAGF,QAAO"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { NodeId, NodeData, EdgeData, ReadableGraph } from '../graph';
|
|
2
|
+
/**
|
|
3
|
+
* Collect neighbours into a Set, optionally excluding a specific node.
|
|
4
|
+
*
|
|
5
|
+
* @param graph - The graph to traverse
|
|
6
|
+
* @param nodeId - The source node
|
|
7
|
+
* @param exclude - Optional node ID to exclude from result
|
|
8
|
+
* @returns A ReadonlySet of neighbouring node IDs
|
|
9
|
+
*/
|
|
10
|
+
export declare function neighbourSet<N extends NodeData, E extends EdgeData>(graph: ReadableGraph<N, E>, nodeId: NodeId, exclude?: NodeId): ReadonlySet<NodeId>;
|
|
11
|
+
/**
|
|
12
|
+
* Compute intersection and union sizes of two neighbour sets without allocating the union set.
|
|
13
|
+
*
|
|
14
|
+
* This is more efficient than computing both separately, as it avoids creating a full union Set.
|
|
15
|
+
*
|
|
16
|
+
* @param a - First neighbourhood set
|
|
17
|
+
* @param b - Second neighbourhood set
|
|
18
|
+
* @returns Object with intersection and union sizes
|
|
19
|
+
*/
|
|
20
|
+
export declare function neighbourOverlap(a: ReadonlySet<NodeId>, b: ReadonlySet<NodeId>): {
|
|
21
|
+
intersection: number;
|
|
22
|
+
union: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Return the actual intersection set of two neighbourhood sets.
|
|
26
|
+
*
|
|
27
|
+
* Needed by Adamic-Adar (iterates common neighbours) and ETCH (requires edge types of intersection edges).
|
|
28
|
+
*
|
|
29
|
+
* @param a - First neighbourhood set
|
|
30
|
+
* @param b - Second neighbourhood set
|
|
31
|
+
* @returns A ReadonlySet containing nodes in both a and b
|
|
32
|
+
*/
|
|
33
|
+
export declare function neighbourIntersection(a: ReadonlySet<NodeId>, b: ReadonlySet<NodeId>): ReadonlySet<NodeId>;
|
|
34
|
+
/**
|
|
35
|
+
* Count the number of edges with a specific type in the graph.
|
|
36
|
+
*
|
|
37
|
+
* Used by ETCH MI variant to compute edge rarity weighting.
|
|
38
|
+
*
|
|
39
|
+
* @param graph - The graph to count edges in
|
|
40
|
+
* @param type - The edge type to count
|
|
41
|
+
* @returns The number of edges with the specified type
|
|
42
|
+
*/
|
|
43
|
+
export declare function countEdgesOfType<N extends NodeData, E extends EdgeData>(graph: ReadableGraph<N, E>, type: string): number;
|
|
44
|
+
/**
|
|
45
|
+
* Count the number of nodes with a specific type in the graph.
|
|
46
|
+
*
|
|
47
|
+
* Used by NOTCH MI variant to compute node rarity weighting.
|
|
48
|
+
*
|
|
49
|
+
* @param graph - The graph to count nodes in
|
|
50
|
+
* @param type - The node type to count
|
|
51
|
+
* @returns The number of nodes with the specified type
|
|
52
|
+
*/
|
|
53
|
+
export declare function countNodesOfType<N extends NodeData, E extends EdgeData>(graph: ReadableGraph<N, E>, type: string): number;
|
|
54
|
+
//# sourceMappingURL=neighbours.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"neighbours.d.ts","sourceRoot":"","sources":["../../src/utils/neighbours.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE1E;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,QAAQ,EAClE,KAAK,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,MAAM,GACd,WAAW,CAAC,MAAM,CAAC,CAMrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC/B,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,EACtB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GACpB;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAgBzC;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACpC,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,EACtB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GACpB,WAAW,CAAC,MAAM,CAAC,CAarB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SA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