@graphty/algorithms 1.3.1 → 1.4.2
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 +358 -413
- package/dist/algorithms.js +564 -261
- package/dist/algorithms.js.map +1 -1
- package/dist/src/algorithms/centrality/betweenness.d.ts +10 -0
- package/dist/src/algorithms/centrality/betweenness.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/betweenness.js +27 -6
- package/dist/src/algorithms/centrality/betweenness.js.map +1 -1
- package/dist/src/algorithms/centrality/closeness.d.ts +11 -2
- package/dist/src/algorithms/centrality/closeness.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/closeness.js +17 -3
- package/dist/src/algorithms/centrality/closeness.js.map +1 -1
- package/dist/src/algorithms/centrality/degree.d.ts +7 -0
- package/dist/src/algorithms/centrality/degree.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/degree.js +9 -6
- package/dist/src/algorithms/centrality/degree.js.map +1 -1
- package/dist/src/algorithms/centrality/delta-pagerank-simple.d.ts +21 -3
- package/dist/src/algorithms/centrality/delta-pagerank-simple.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/delta-pagerank-simple.js +25 -7
- package/dist/src/algorithms/centrality/delta-pagerank-simple.js.map +1 -1
- package/dist/src/algorithms/centrality/delta-pagerank.d.ts +28 -2
- package/dist/src/algorithms/centrality/delta-pagerank.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/delta-pagerank.js +30 -4
- package/dist/src/algorithms/centrality/delta-pagerank.js.map +1 -1
- package/dist/src/algorithms/centrality/eigenvector.d.ts +10 -3
- package/dist/src/algorithms/centrality/eigenvector.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/eigenvector.js +11 -4
- package/dist/src/algorithms/centrality/eigenvector.js.map +1 -1
- package/dist/src/algorithms/centrality/hits.d.ts +10 -3
- package/dist/src/algorithms/centrality/hits.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/hits.js +11 -4
- package/dist/src/algorithms/centrality/hits.js.map +1 -1
- package/dist/src/algorithms/centrality/index.d.ts +1 -1
- package/dist/src/algorithms/centrality/index.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/index.js +1 -1
- package/dist/src/algorithms/centrality/index.js.map +1 -1
- package/dist/src/algorithms/centrality/katz.d.ts +10 -3
- package/dist/src/algorithms/centrality/katz.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/katz.js +13 -8
- package/dist/src/algorithms/centrality/katz.js.map +1 -1
- package/dist/src/algorithms/centrality/pagerank.d.ts +14 -0
- package/dist/src/algorithms/centrality/pagerank.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/pagerank.js +16 -1
- package/dist/src/algorithms/centrality/pagerank.js.map +1 -1
- package/dist/src/algorithms/community/girvan-newman.d.ts +2 -3
- package/dist/src/algorithms/community/girvan-newman.d.ts.map +1 -1
- package/dist/src/algorithms/community/girvan-newman.js +21 -4
- package/dist/src/algorithms/community/girvan-newman.js.map +1 -1
- package/dist/src/algorithms/community/index.d.ts.map +1 -1
- package/dist/src/algorithms/community/index.js.map +1 -1
- package/dist/src/algorithms/community/label-propagation.d.ts +0 -3
- package/dist/src/algorithms/community/label-propagation.d.ts.map +1 -1
- package/dist/src/algorithms/community/label-propagation.js +13 -6
- package/dist/src/algorithms/community/label-propagation.js.map +1 -1
- package/dist/src/algorithms/community/leiden.d.ts +0 -1
- package/dist/src/algorithms/community/leiden.d.ts.map +1 -1
- package/dist/src/algorithms/community/leiden.js +37 -6
- package/dist/src/algorithms/community/leiden.js.map +1 -1
- package/dist/src/algorithms/community/louvain-optimized.d.ts +37 -0
- package/dist/src/algorithms/community/louvain-optimized.d.ts.map +1 -1
- package/dist/src/algorithms/community/louvain-optimized.js +42 -7
- package/dist/src/algorithms/community/louvain-optimized.js.map +1 -1
- package/dist/src/algorithms/community/louvain.d.ts +2 -3
- package/dist/src/algorithms/community/louvain.d.ts.map +1 -1
- package/dist/src/algorithms/community/louvain.js +19 -6
- package/dist/src/algorithms/community/louvain.js.map +1 -1
- package/dist/src/algorithms/community/modularity-utils.d.ts +0 -4
- package/dist/src/algorithms/community/modularity-utils.d.ts.map +1 -1
- package/dist/src/algorithms/community/modularity-utils.js +1 -5
- package/dist/src/algorithms/community/modularity-utils.js.map +1 -1
- package/dist/src/algorithms/components/connected.d.ts +23 -0
- package/dist/src/algorithms/components/connected.d.ts.map +1 -1
- package/dist/src/algorithms/components/connected.js +29 -3
- package/dist/src/algorithms/components/connected.js.map +1 -1
- package/dist/src/algorithms/matching/bipartite.d.ts +10 -0
- package/dist/src/algorithms/matching/bipartite.d.ts.map +1 -1
- package/dist/src/algorithms/matching/bipartite.js +10 -0
- package/dist/src/algorithms/matching/bipartite.js.map +1 -1
- package/dist/src/algorithms/matching/index.d.ts.map +1 -1
- package/dist/src/algorithms/matching/index.js.map +1 -1
- package/dist/src/algorithms/matching/isomorphism.d.ts +8 -0
- package/dist/src/algorithms/matching/isomorphism.d.ts.map +1 -1
- package/dist/src/algorithms/matching/isomorphism.js +36 -2
- package/dist/src/algorithms/matching/isomorphism.js.map +1 -1
- package/dist/src/algorithms/mst/index.d.ts.map +1 -1
- package/dist/src/algorithms/mst/index.js.map +1 -1
- package/dist/src/algorithms/mst/kruskal.d.ts +14 -0
- package/dist/src/algorithms/mst/kruskal.d.ts.map +1 -1
- package/dist/src/algorithms/mst/kruskal.js +17 -3
- package/dist/src/algorithms/mst/kruskal.js.map +1 -1
- package/dist/src/algorithms/mst/prim.d.ts +9 -0
- package/dist/src/algorithms/mst/prim.d.ts.map +1 -1
- package/dist/src/algorithms/mst/prim.js +9 -0
- package/dist/src/algorithms/mst/prim.js.map +1 -1
- package/dist/src/algorithms/shortest-path/bellman-ford.d.ts +10 -0
- package/dist/src/algorithms/shortest-path/bellman-ford.d.ts.map +1 -1
- package/dist/src/algorithms/shortest-path/bellman-ford.js +10 -0
- package/dist/src/algorithms/shortest-path/bellman-ford.js.map +1 -1
- package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.d.ts +11 -4
- package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.d.ts.map +1 -1
- package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.js +18 -16
- package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.js.map +1 -1
- package/dist/src/algorithms/shortest-path/dijkstra.d.ts +15 -0
- package/dist/src/algorithms/shortest-path/dijkstra.d.ts.map +1 -1
- package/dist/src/algorithms/shortest-path/dijkstra.js +15 -0
- package/dist/src/algorithms/shortest-path/dijkstra.js.map +1 -1
- package/dist/src/algorithms/shortest-path/floyd-warshall.d.ts +17 -0
- package/dist/src/algorithms/shortest-path/floyd-warshall.d.ts.map +1 -1
- package/dist/src/algorithms/shortest-path/floyd-warshall.js +17 -0
- package/dist/src/algorithms/shortest-path/floyd-warshall.js.map +1 -1
- package/dist/src/algorithms/shortest-path/index.d.ts.map +1 -1
- package/dist/src/algorithms/shortest-path/index.js.map +1 -1
- package/dist/src/algorithms/traversal/bfs-unified.d.ts +13 -0
- package/dist/src/algorithms/traversal/bfs-unified.d.ts.map +1 -1
- package/dist/src/algorithms/traversal/bfs-unified.js +37 -0
- package/dist/src/algorithms/traversal/bfs-unified.js.map +1 -1
- package/dist/src/algorithms/traversal/bfs-variants.d.ts +23 -0
- package/dist/src/algorithms/traversal/bfs-variants.d.ts.map +1 -1
- package/dist/src/algorithms/traversal/bfs-variants.js +34 -0
- package/dist/src/algorithms/traversal/bfs-variants.js.map +1 -1
- package/dist/src/algorithms/traversal/bfs.d.ts +1 -1
- package/dist/src/algorithms/traversal/bfs.d.ts.map +1 -1
- package/dist/src/algorithms/traversal/bfs.js +1 -1
- package/dist/src/algorithms/traversal/bfs.js.map +1 -1
- package/dist/src/algorithms/traversal/dfs.d.ts +10 -0
- package/dist/src/algorithms/traversal/dfs.d.ts.map +1 -1
- package/dist/src/algorithms/traversal/dfs.js +48 -0
- package/dist/src/algorithms/traversal/dfs.js.map +1 -1
- package/dist/src/algorithms/traversal/index.d.ts.map +1 -1
- package/dist/src/algorithms/traversal/index.js.map +1 -1
- package/dist/src/benchmark-all-algorithms.d.ts +2 -0
- package/dist/src/benchmark-all-algorithms.d.ts.map +1 -1
- package/dist/src/benchmark-all-algorithms.js +32 -3
- package/dist/src/benchmark-all-algorithms.js.map +1 -1
- package/dist/src/clustering/hierarchical.d.ts +8 -1
- package/dist/src/clustering/hierarchical.d.ts.map +1 -1
- package/dist/src/clustering/hierarchical.js +22 -6
- package/dist/src/clustering/hierarchical.js.map +1 -1
- package/dist/src/clustering/index.d.ts.map +1 -1
- package/dist/src/clustering/index.js.map +1 -1
- package/dist/src/clustering/k-core.d.ts +2 -5
- package/dist/src/clustering/k-core.d.ts.map +1 -1
- package/dist/src/clustering/k-core.js +14 -12
- package/dist/src/clustering/k-core.js.map +1 -1
- package/dist/src/clustering/mcl.d.ts +6 -0
- package/dist/src/clustering/mcl.d.ts.map +1 -1
- package/dist/src/clustering/mcl.js +34 -3
- package/dist/src/clustering/mcl.js.map +1 -1
- package/dist/src/clustering/spectral.d.ts +4 -1
- package/dist/src/clustering/spectral.d.ts.map +1 -1
- package/dist/src/clustering/spectral.js +61 -28
- package/dist/src/clustering/spectral.js.map +1 -1
- package/dist/src/core/graph.d.ts +45 -0
- package/dist/src/core/graph.d.ts.map +1 -1
- package/dist/src/core/graph.js +45 -1
- package/dist/src/core/graph.js.map +1 -1
- package/dist/src/data-structures/index.d.ts.map +1 -1
- package/dist/src/data-structures/index.js.map +1 -1
- package/dist/src/data-structures/priority-queue.d.ts +18 -1
- package/dist/src/data-structures/priority-queue.d.ts.map +1 -1
- package/dist/src/data-structures/priority-queue.js +26 -5
- package/dist/src/data-structures/priority-queue.js.map +1 -1
- package/dist/src/data-structures/union-find.d.ts +21 -0
- package/dist/src/data-structures/union-find.d.ts.map +1 -1
- package/dist/src/data-structures/union-find.js +21 -0
- package/dist/src/data-structures/union-find.js.map +1 -1
- package/dist/src/flow/ford-fulkerson.d.ts +4 -2
- package/dist/src/flow/ford-fulkerson.d.ts.map +1 -1
- package/dist/src/flow/ford-fulkerson.js +31 -2
- package/dist/src/flow/ford-fulkerson.js.map +1 -1
- package/dist/src/flow/min-cut.d.ts +0 -3
- package/dist/src/flow/min-cut.d.ts.map +1 -1
- package/dist/src/flow/min-cut.js +17 -4
- package/dist/src/flow/min-cut.js.map +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/link-prediction/adamic-adar.d.ts +26 -0
- package/dist/src/link-prediction/adamic-adar.d.ts.map +1 -1
- package/dist/src/link-prediction/adamic-adar.js +36 -10
- package/dist/src/link-prediction/adamic-adar.js.map +1 -1
- package/dist/src/link-prediction/common-neighbors.d.ts +21 -0
- package/dist/src/link-prediction/common-neighbors.d.ts.map +1 -1
- package/dist/src/link-prediction/common-neighbors.js +27 -6
- package/dist/src/link-prediction/common-neighbors.js.map +1 -1
- package/dist/src/link-prediction/index.d.ts.map +1 -1
- package/dist/src/optimized/bit-packed.d.ts +103 -53
- package/dist/src/optimized/bit-packed.d.ts.map +1 -1
- package/dist/src/optimized/bit-packed.js +104 -54
- package/dist/src/optimized/bit-packed.js.map +1 -1
- package/dist/src/optimized/csr-graph.d.ts +87 -24
- package/dist/src/optimized/csr-graph.d.ts.map +1 -1
- package/dist/src/optimized/csr-graph.js +87 -24
- package/dist/src/optimized/csr-graph.js.map +1 -1
- package/dist/src/optimized/direction-optimized-bfs.d.ts +37 -16
- package/dist/src/optimized/direction-optimized-bfs.d.ts.map +1 -1
- package/dist/src/optimized/direction-optimized-bfs.js +39 -20
- package/dist/src/optimized/direction-optimized-bfs.js.map +1 -1
- package/dist/src/optimized/graph-adapter.d.ts +58 -9
- package/dist/src/optimized/graph-adapter.d.ts.map +1 -1
- package/dist/src/optimized/graph-adapter.js +58 -10
- package/dist/src/optimized/graph-adapter.js.map +1 -1
- package/dist/src/optimized/index.d.ts +1 -1
- package/dist/src/optimized/index.d.ts.map +1 -1
- package/dist/src/optimized/index.js +3 -1
- package/dist/src/optimized/index.js.map +1 -1
- package/dist/src/pathfinding/astar.d.ts +25 -9
- package/dist/src/pathfinding/astar.d.ts.map +1 -1
- package/dist/src/pathfinding/astar.js +25 -10
- package/dist/src/pathfinding/astar.js.map +1 -1
- package/dist/src/pathfinding/utils.d.ts +15 -6
- package/dist/src/pathfinding/utils.d.ts.map +1 -1
- package/dist/src/pathfinding/utils.js +19 -7
- package/dist/src/pathfinding/utils.js.map +1 -1
- package/dist/src/research/grsbm.d.ts +0 -1
- package/dist/src/research/grsbm.d.ts.map +1 -1
- package/dist/src/research/grsbm.js +22 -9
- package/dist/src/research/grsbm.js.map +1 -1
- package/dist/src/research/index.d.ts.map +1 -1
- package/dist/src/research/index.js.map +1 -1
- package/dist/src/research/sync.d.ts +0 -1
- package/dist/src/research/sync.d.ts.map +1 -1
- package/dist/src/research/sync.js +28 -7
- package/dist/src/research/sync.js.map +1 -1
- package/dist/src/research/terahac.d.ts +0 -1
- package/dist/src/research/terahac.d.ts.map +1 -1
- package/dist/src/research/terahac.js +32 -4
- package/dist/src/research/terahac.js.map +1 -1
- package/dist/src/utils/graph-converters.d.ts +31 -0
- package/dist/src/utils/graph-converters.d.ts.map +1 -1
- package/dist/src/utils/graph-converters.js +31 -0
- package/dist/src/utils/graph-converters.js.map +1 -1
- package/dist/src/utils/graph-utilities.d.ts.map +1 -1
- package/dist/src/utils/graph-utilities.js.map +1 -1
- package/dist/src/utils/math-utilities.d.ts +11 -0
- package/dist/src/utils/math-utilities.d.ts.map +1 -1
- package/dist/src/utils/math-utilities.js +14 -5
- package/dist/src/utils/math-utilities.js.map +1 -1
- package/dist/src/utils/optimization-helpers.d.ts +9 -0
- package/dist/src/utils/optimization-helpers.d.ts.map +1 -1
- package/dist/src/utils/optimization-helpers.js +12 -0
- package/dist/src/utils/optimization-helpers.js.map +1 -1
- package/dist/src/utils/priorityQueue.d.ts +24 -0
- package/dist/src/utils/priorityQueue.d.ts.map +1 -1
- package/dist/src/utils/priorityQueue.js +34 -4
- package/dist/src/utils/priorityQueue.js.map +1 -1
- package/package.json +49 -45
- package/src/algorithms/centrality/betweenness.ts +34 -17
- package/src/algorithms/centrality/closeness.ts +34 -17
- package/src/algorithms/centrality/degree.ts +15 -19
- package/src/algorithms/centrality/delta-pagerank-simple.ts +36 -28
- package/src/algorithms/centrality/delta-pagerank.ts +34 -11
- package/src/algorithms/centrality/eigenvector.ts +14 -15
- package/src/algorithms/centrality/hits.ts +17 -17
- package/src/algorithms/centrality/index.ts +20 -15
- package/src/algorithms/centrality/katz.ts +17 -25
- package/src/algorithms/centrality/pagerank.ts +26 -17
- package/src/algorithms/community/girvan-newman.ts +39 -28
- package/src/algorithms/community/index.ts +6 -7
- package/src/algorithms/community/label-propagation.ts +20 -28
- package/src/algorithms/community/leiden.ts +61 -37
- package/src/algorithms/community/louvain-optimized.ts +49 -20
- package/src/algorithms/community/louvain.ts +35 -25
- package/src/algorithms/community/modularity-utils.ts +5 -17
- package/src/algorithms/components/connected.ts +40 -17
- package/src/algorithms/matching/bipartite.ts +17 -10
- package/src/algorithms/matching/index.ts +4 -4
- package/src/algorithms/matching/isomorphism.ts +53 -23
- package/src/algorithms/mst/index.ts +3 -4
- package/src/algorithms/mst/kruskal.ts +21 -6
- package/src/algorithms/mst/prim.ts +13 -4
- package/src/algorithms/shortest-path/bellman-ford.ts +16 -15
- package/src/algorithms/shortest-path/bidirectional-dijkstra.ts +28 -28
- package/src/algorithms/shortest-path/dijkstra.ts +23 -17
- package/src/algorithms/shortest-path/floyd-warshall.ts +21 -4
- package/src/algorithms/shortest-path/index.ts +5 -5
- package/src/algorithms/traversal/bfs-unified.ts +64 -60
- package/src/algorithms/traversal/bfs-variants.ts +61 -37
- package/src/algorithms/traversal/bfs.ts +1 -7
- package/src/algorithms/traversal/dfs.ts +61 -42
- package/src/algorithms/traversal/index.ts +3 -3
- package/src/benchmark-all-algorithms.ts +57 -25
- package/src/clustering/hierarchical.ts +40 -34
- package/src/clustering/index.ts +8 -8
- package/src/clustering/k-core.ts +26 -42
- package/src/clustering/mcl.ts +53 -23
- package/src/clustering/spectral.ts +91 -57
- package/src/core/graph.ts +54 -14
- package/src/data-structures/index.ts +2 -2
- package/src/data-structures/priority-queue.ts +36 -11
- package/src/data-structures/union-find.ts +22 -1
- package/src/flow/ford-fulkerson.ts +62 -35
- package/src/flow/min-cut.ts +43 -45
- package/src/index.ts +3 -2
- package/src/link-prediction/adamic-adar.ts +65 -51
- package/src/link-prediction/common-neighbors.ts +45 -36
- package/src/link-prediction/index.ts +1 -1
- package/src/optimized/bit-packed.ts +106 -56
- package/src/optimized/csr-graph.ts +93 -30
- package/src/optimized/direction-optimized-bfs.ts +44 -25
- package/src/optimized/graph-adapter.ts +64 -16
- package/src/optimized/index.ts +7 -9
- package/src/pathfinding/astar.ts +40 -25
- package/src/pathfinding/utils.ts +20 -13
- package/src/research/grsbm.ts +30 -24
- package/src/research/index.ts +4 -4
- package/src/research/sync.ts +39 -23
- package/src/research/terahac.ts +54 -20
- package/src/utils/graph-converters.ts +42 -14
- package/src/utils/graph-utilities.ts +11 -37
- package/src/utils/math-utilities.ts +17 -8
- package/src/utils/optimization-helpers.ts +27 -21
- package/src/utils/priorityQueue.ts +40 -6
|
@@ -22,24 +22,45 @@ export interface LinkPredictionOptions {
|
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* Calculate common neighbors score for a pair of nodes
|
|
25
|
+
* @param graph - The input graph
|
|
26
|
+
* @param source - The source node ID
|
|
27
|
+
* @param target - The target node ID
|
|
28
|
+
* @param options - Link prediction options
|
|
29
|
+
* @returns The number of common neighbors
|
|
25
30
|
*/
|
|
26
31
|
export declare function commonNeighborsScore(graph: Graph, source: NodeId, target: NodeId, options?: LinkPredictionOptions): number;
|
|
27
32
|
/**
|
|
28
33
|
* Calculate common neighbors scores for all possible node pairs
|
|
34
|
+
* @param graph - The input graph
|
|
35
|
+
* @param options - Link prediction options
|
|
36
|
+
* @returns Array of link prediction scores sorted by score descending
|
|
29
37
|
*/
|
|
30
38
|
export declare function commonNeighborsPrediction(graph: Graph, options?: LinkPredictionOptions): LinkPredictionScore[];
|
|
31
39
|
/**
|
|
32
40
|
* Calculate common neighbors scores for specific node pairs
|
|
41
|
+
* @param graph - The input graph
|
|
42
|
+
* @param pairs - Array of node ID pairs to calculate scores for
|
|
43
|
+
* @param options - Link prediction options
|
|
44
|
+
* @returns Array of link prediction scores for the specified pairs
|
|
33
45
|
*/
|
|
34
46
|
export declare function commonNeighborsForPairs(graph: Graph, pairs: [NodeId, NodeId][], options?: LinkPredictionOptions): LinkPredictionScore[];
|
|
35
47
|
/**
|
|
36
48
|
* Get top candidates for link prediction for a specific node
|
|
49
|
+
* @param graph - The input graph
|
|
50
|
+
* @param node - The node ID to get candidates for
|
|
51
|
+
* @param options - Link prediction options with optional candidate list
|
|
52
|
+
* @returns Array of top link prediction candidates sorted by score descending
|
|
37
53
|
*/
|
|
38
54
|
export declare function getTopCandidatesForNode(graph: Graph, node: NodeId, options?: LinkPredictionOptions & {
|
|
39
55
|
candidates?: NodeId[];
|
|
40
56
|
}): LinkPredictionScore[];
|
|
41
57
|
/**
|
|
42
58
|
* Calculate precision and recall for link prediction evaluation
|
|
59
|
+
* @param trainingGraph - The training graph without test edges
|
|
60
|
+
* @param testEdges - Array of node pairs that are actual edges
|
|
61
|
+
* @param nonEdges - Array of node pairs that are not edges
|
|
62
|
+
* @param options - Link prediction options
|
|
63
|
+
* @returns Evaluation metrics including precision, recall, F1 score, and AUC
|
|
43
64
|
*/
|
|
44
65
|
export declare function evaluateCommonNeighbors(trainingGraph: Graph, testEdges: [NodeId, NodeId][], nonEdges: [NodeId, NodeId][], options?: LinkPredictionOptions): {
|
|
45
66
|
precision: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-neighbors.d.ts","sourceRoot":"","sources":["../../../src/link-prediction/common-neighbors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"common-neighbors.d.ts","sourceRoot":"","sources":["../../../src/link-prediction/common-neighbors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGhD;;;;;;;;;GASG;AAEH,MAAM,WAAW,mBAAmB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,qBAAqB;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAChC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,qBAA0B,GACpC,MAAM,CAcR;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,GAAE,qBAA0B,GAAG,mBAAmB,EAAE,CA0ClH;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACnC,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EACzB,OAAO,GAAE,qBAA0B,GACpC,mBAAmB,EAAE,CAMvB;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACnC,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,qBAAqB,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,GAChE,mBAAmB,EAAE,CA+BvB;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACnC,aAAa,EAAE,KAAK,EACpB,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAC7B,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAC5B,OAAO,GAAE,qBAA0B,GACpC;IACC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACf,CAgEA"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { getCommonNeighbors, getIntermediateNodes } from "../utils/graph-utilities.js";
|
|
2
2
|
/**
|
|
3
3
|
* Calculate common neighbors score for a pair of nodes
|
|
4
|
+
* @param graph - The input graph
|
|
5
|
+
* @param source - The source node ID
|
|
6
|
+
* @param target - The target node ID
|
|
7
|
+
* @param options - Link prediction options
|
|
8
|
+
* @returns The number of common neighbors
|
|
4
9
|
*/
|
|
5
10
|
export function commonNeighborsScore(graph, source, target, options = {}) {
|
|
6
11
|
if (!graph.hasNode(source) || !graph.hasNode(target)) {
|
|
@@ -9,16 +14,19 @@ export function commonNeighborsScore(graph, source, target, options = {}) {
|
|
|
9
14
|
const { directed = false } = options;
|
|
10
15
|
// Use utility function to get common neighbors
|
|
11
16
|
// For directed graphs, we want intermediate nodes that form paths source->X->target
|
|
12
|
-
const commonNeighborsSet = directed
|
|
13
|
-
getIntermediateNodes(graph, source, target)
|
|
14
|
-
getCommonNeighbors(graph, source, target, false);
|
|
17
|
+
const commonNeighborsSet = directed
|
|
18
|
+
? getIntermediateNodes(graph, source, target)
|
|
19
|
+
: getCommonNeighbors(graph, source, target, false);
|
|
15
20
|
return commonNeighborsSet.size;
|
|
16
21
|
}
|
|
17
22
|
/**
|
|
18
23
|
* Calculate common neighbors scores for all possible node pairs
|
|
24
|
+
* @param graph - The input graph
|
|
25
|
+
* @param options - Link prediction options
|
|
26
|
+
* @returns Array of link prediction scores sorted by score descending
|
|
19
27
|
*/
|
|
20
28
|
export function commonNeighborsPrediction(graph, options = {}) {
|
|
21
|
-
const { directed = false, includeExisting = false, topK
|
|
29
|
+
const { directed = false, includeExisting = false, topK } = options;
|
|
22
30
|
const scores = [];
|
|
23
31
|
const nodes = Array.from(graph.nodes()).map((n) => n.id);
|
|
24
32
|
for (let i = 0; i < nodes.length; i++) {
|
|
@@ -52,6 +60,10 @@ export function commonNeighborsPrediction(graph, options = {}) {
|
|
|
52
60
|
}
|
|
53
61
|
/**
|
|
54
62
|
* Calculate common neighbors scores for specific node pairs
|
|
63
|
+
* @param graph - The input graph
|
|
64
|
+
* @param pairs - Array of node ID pairs to calculate scores for
|
|
65
|
+
* @param options - Link prediction options
|
|
66
|
+
* @returns Array of link prediction scores for the specified pairs
|
|
55
67
|
*/
|
|
56
68
|
export function commonNeighborsForPairs(graph, pairs, options = {}) {
|
|
57
69
|
return pairs.map(([source, target]) => ({
|
|
@@ -62,12 +74,16 @@ export function commonNeighborsForPairs(graph, pairs, options = {}) {
|
|
|
62
74
|
}
|
|
63
75
|
/**
|
|
64
76
|
* Get top candidates for link prediction for a specific node
|
|
77
|
+
* @param graph - The input graph
|
|
78
|
+
* @param node - The node ID to get candidates for
|
|
79
|
+
* @param options - Link prediction options with optional candidate list
|
|
80
|
+
* @returns Array of top link prediction candidates sorted by score descending
|
|
65
81
|
*/
|
|
66
82
|
export function getTopCandidatesForNode(graph, node, options = {}) {
|
|
67
83
|
if (!graph.hasNode(node)) {
|
|
68
84
|
return [];
|
|
69
85
|
}
|
|
70
|
-
const { directed = false, includeExisting = false, topK = 10, candidates
|
|
86
|
+
const { directed = false, includeExisting = false, topK = 10, candidates } = options;
|
|
71
87
|
const scores = [];
|
|
72
88
|
const targetNodes = candidates ?? Array.from(graph.nodes()).map((n) => n.id);
|
|
73
89
|
for (const target of targetNodes) {
|
|
@@ -89,6 +105,11 @@ export function getTopCandidatesForNode(graph, node, options = {}) {
|
|
|
89
105
|
}
|
|
90
106
|
/**
|
|
91
107
|
* Calculate precision and recall for link prediction evaluation
|
|
108
|
+
* @param trainingGraph - The training graph without test edges
|
|
109
|
+
* @param testEdges - Array of node pairs that are actual edges
|
|
110
|
+
* @param nonEdges - Array of node pairs that are not edges
|
|
111
|
+
* @param options - Link prediction options
|
|
112
|
+
* @returns Evaluation metrics including precision, recall, F1 score, and AUC
|
|
92
113
|
*/
|
|
93
114
|
export function evaluateCommonNeighbors(trainingGraph, testEdges, nonEdges, options = {}) {
|
|
94
115
|
// Get scores for test edges and non-edges
|
|
@@ -115,7 +136,7 @@ export function evaluateCommonNeighbors(trainingGraph, testEdges, nonEdges, opti
|
|
|
115
136
|
}
|
|
116
137
|
const precision = truePositives / (truePositives + falsePositives);
|
|
117
138
|
const recall = truePositives / totalPositives;
|
|
118
|
-
const f1 = precision + recall > 0 ? 2 * (precision * recall) / (precision + recall) : 0;
|
|
139
|
+
const f1 = precision + recall > 0 ? (2 * (precision * recall)) / (precision + recall) : 0;
|
|
119
140
|
if (f1 > bestF1) {
|
|
120
141
|
bestF1 = f1;
|
|
121
142
|
bestPrecision = precision;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-neighbors.js","sourceRoot":"","sources":["../../../src/link-prediction/common-neighbors.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"common-neighbors.js","sourceRoot":"","sources":["../../../src/link-prediction/common-neighbors.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAyBvF;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAChC,KAAY,EACZ,MAAc,EACd,MAAc,EACd,UAAiC,EAAE;IAEnC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,OAAO,CAAC,CAAC;IACb,CAAC;IAED,MAAM,EAAE,QAAQ,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAErC,+CAA+C;IAC/C,oFAAoF;IACpF,MAAM,k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1F,IAAI,EAAE,GAAG,MAAM,EAAE,CAAC;YACd,MAAM,GAAG,EAAE,CAAC;YACZ,aAAa,GAAG,SAAS,CAAC;YAC1B,UAAU,GAAG,MAAM,CAAC;QACxB,CAAC;IACL,CAAC;IAED,mCAAmC;IACnC,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,OAAO,GAAG,CAAC,CAAC;IAEhB,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACpB,OAAO,EAAE,CAAC;QACd,CAAC;aAAM,CAAC;YACJ,GAAG,IAAI,OAAO,CAAC;YACf,OAAO,EAAE,CAAC;QACd,CAAC;IACL,CAAC;IAED,IAAI,OAAO,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;QAC7B,GAAG,GAAG,GAAG,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC,CAAC;IACpC,CAAC;SAAM,CAAC;QACJ,GAAG,GAAG,GAAG,CAAC,CAAC,qBAAqB;IACpC,CAAC;IAED,OAAO;QACH,SAAS,EAAE,aAAa;QACxB,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,MAAM;QACf,GAAG;KACN,CAAC;AACN,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/link-prediction/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACH,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,oCAAoC,EACpC,kBAAkB,EAClB,iCAAiC,GACpC,MAAM,kBAAkB,CAAC;AAC1B,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/link-prediction/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACH,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,oCAAoC,EACpC,kBAAkB,EAClB,iCAAiC,GACpC,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACxF,OAAO,EACH,uBAAuB,EACvB,yBAAyB,EACzB,oBAAoB,EACpB,uBAAuB,EACvB,uBAAuB,GAC1B,MAAM,uBAAuB,CAAC"}
|
|
@@ -7,52 +7,76 @@
|
|
|
7
7
|
export declare class GraphBitSet {
|
|
8
8
|
private bitset;
|
|
9
9
|
private _cardinality;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new GraphBitSet with optional pre-allocated capacity.
|
|
12
|
+
* @param capacity - The initial capacity to pre-allocate for the bitset
|
|
13
|
+
*/
|
|
10
14
|
constructor(capacity?: number);
|
|
11
15
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
* Add a single element to the set.
|
|
17
|
+
* @param index - The element index to add
|
|
18
|
+
*/
|
|
14
19
|
add(index: number): void;
|
|
15
20
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
* Remove a single element from the set.
|
|
22
|
+
* @param index - The element index to remove
|
|
23
|
+
*/
|
|
18
24
|
remove(index: number): void;
|
|
19
25
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
* Check if an element exists in the set.
|
|
27
|
+
* @param index - The element index to check
|
|
28
|
+
* @returns True if the element exists, false otherwise
|
|
29
|
+
*/
|
|
22
30
|
has(index: number): boolean;
|
|
23
31
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
* Clear all elements
|
|
33
|
+
*/
|
|
26
34
|
clear(): void;
|
|
27
35
|
/**
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
* Check if the set is empty.
|
|
37
|
+
* @returns True if the set contains no elements, false otherwise
|
|
38
|
+
*/
|
|
30
39
|
isEmpty(): boolean;
|
|
31
40
|
/**
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
* Optimized for graph algorithms - add a range of indices.
|
|
42
|
+
* @param start - The starting index (inclusive)
|
|
43
|
+
* @param end - The ending index (exclusive)
|
|
44
|
+
*/
|
|
34
45
|
addRange(start: number, end: number): void;
|
|
35
46
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
47
|
+
* Fast cardinality tracking - get the number of elements in the set.
|
|
48
|
+
* @returns The number of elements in the set
|
|
49
|
+
*/
|
|
38
50
|
size(): number;
|
|
39
51
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
52
|
+
* Batch operations for frontier management - swap contents with another GraphBitSet.
|
|
53
|
+
* @param other - The GraphBitSet to swap contents with
|
|
54
|
+
*/
|
|
42
55
|
swap(other: GraphBitSet): void;
|
|
43
56
|
/**
|
|
44
|
-
|
|
45
|
-
|
|
57
|
+
* Efficient iteration over all elements in the set.
|
|
58
|
+
* @yields The indices of elements in the set
|
|
59
|
+
*/
|
|
46
60
|
[Symbol.iterator](): Generator<number>;
|
|
47
61
|
/**
|
|
48
|
-
|
|
49
|
-
|
|
62
|
+
* Perform union operation with another GraphBitSet, updating this set in place.
|
|
63
|
+
* @param other - The GraphBitSet to union with
|
|
64
|
+
*/
|
|
50
65
|
union(other: GraphBitSet): void;
|
|
66
|
+
/**
|
|
67
|
+
* Perform intersection operation with another GraphBitSet, updating this set in place.
|
|
68
|
+
* @param other - The GraphBitSet to intersect with
|
|
69
|
+
*/
|
|
51
70
|
intersection(other: GraphBitSet): void;
|
|
71
|
+
/**
|
|
72
|
+
* Perform difference operation with another GraphBitSet, updating this set in place.
|
|
73
|
+
* @param other - The GraphBitSet to subtract from this set
|
|
74
|
+
*/
|
|
52
75
|
difference(other: GraphBitSet): void;
|
|
53
76
|
/**
|
|
54
|
-
|
|
55
|
-
|
|
77
|
+
* Clone the bitset.
|
|
78
|
+
* @returns A new GraphBitSet with the same elements
|
|
79
|
+
*/
|
|
56
80
|
clone(): GraphBitSet;
|
|
57
81
|
}
|
|
58
82
|
/**
|
|
@@ -65,47 +89,62 @@ export declare class VisitedBitArray {
|
|
|
65
89
|
private words;
|
|
66
90
|
private wordCount;
|
|
67
91
|
private _size;
|
|
92
|
+
/**
|
|
93
|
+
* Creates a new VisitedBitArray with the specified size.
|
|
94
|
+
* @param size - The number of bits to allocate
|
|
95
|
+
*/
|
|
68
96
|
constructor(size: number);
|
|
69
97
|
/**
|
|
70
|
-
|
|
71
|
-
|
|
98
|
+
* Set bit at the specified index.
|
|
99
|
+
* @param index - The bit index to set
|
|
100
|
+
*/
|
|
72
101
|
set(index: number): void;
|
|
73
102
|
/**
|
|
74
|
-
|
|
75
|
-
|
|
103
|
+
* Get bit value at the specified index.
|
|
104
|
+
* @param index - The bit index to get
|
|
105
|
+
* @returns True if the bit is set, false otherwise
|
|
106
|
+
*/
|
|
76
107
|
get(index: number): boolean;
|
|
77
108
|
/**
|
|
78
|
-
|
|
79
|
-
|
|
109
|
+
* Clear all bits
|
|
110
|
+
*/
|
|
80
111
|
clear(): void;
|
|
81
112
|
/**
|
|
82
|
-
|
|
83
|
-
|
|
113
|
+
* Toggle bit at the specified index.
|
|
114
|
+
* @param index - The bit index to toggle
|
|
115
|
+
*/
|
|
84
116
|
toggle(index: number): void;
|
|
85
117
|
/**
|
|
86
|
-
|
|
87
|
-
|
|
118
|
+
* Population count for statistics - count the number of set bits.
|
|
119
|
+
* @returns The number of bits set to 1
|
|
120
|
+
*/
|
|
88
121
|
popcount(): number;
|
|
89
122
|
/**
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
123
|
+
* Efficient population count for a single word.
|
|
124
|
+
* Uses bit manipulation tricks for fast counting.
|
|
125
|
+
* @param n - The 32-bit word to count
|
|
126
|
+
* @returns The number of bits set to 1 in the word
|
|
127
|
+
*/
|
|
93
128
|
private popcountWord;
|
|
94
129
|
/**
|
|
95
|
-
|
|
96
|
-
|
|
130
|
+
* Get size of the bit array.
|
|
131
|
+
* @returns The total number of bits in the array
|
|
132
|
+
*/
|
|
97
133
|
size(): number;
|
|
98
134
|
/**
|
|
99
|
-
|
|
100
|
-
|
|
135
|
+
* Check if all bits are zero.
|
|
136
|
+
* @returns True if no bits are set, false otherwise
|
|
137
|
+
*/
|
|
101
138
|
isEmpty(): boolean;
|
|
102
139
|
/**
|
|
103
|
-
|
|
104
|
-
|
|
140
|
+
* Set multiple bits from an array of indices.
|
|
141
|
+
* @param indices - Array of bit indices to set
|
|
142
|
+
*/
|
|
105
143
|
setMultiple(indices: number[]): void;
|
|
106
144
|
/**
|
|
107
|
-
|
|
108
|
-
|
|
145
|
+
* Get indices of all set bits.
|
|
146
|
+
* @returns Array containing the indices of all bits that are set to 1
|
|
147
|
+
*/
|
|
109
148
|
getSetIndices(): number[];
|
|
110
149
|
}
|
|
111
150
|
/**
|
|
@@ -118,26 +157,37 @@ export declare class CompactDistanceArray {
|
|
|
118
157
|
private data;
|
|
119
158
|
private _size;
|
|
120
159
|
private static readonly INFINITY;
|
|
160
|
+
/**
|
|
161
|
+
* Creates a new CompactDistanceArray with the specified size.
|
|
162
|
+
* @param size - The number of distance values to store
|
|
163
|
+
*/
|
|
121
164
|
constructor(size: number);
|
|
122
165
|
/**
|
|
123
|
-
|
|
124
|
-
|
|
166
|
+
* Set distance at the specified index.
|
|
167
|
+
* @param index - The node index to set the distance for
|
|
168
|
+
* @param distance - The distance value to set
|
|
169
|
+
*/
|
|
125
170
|
set(index: number, distance: number): void;
|
|
126
171
|
/**
|
|
127
|
-
|
|
128
|
-
|
|
172
|
+
* Get distance at the specified index.
|
|
173
|
+
* @param index - The node index to get the distance for
|
|
174
|
+
* @returns The distance value, or INFINITY if not set
|
|
175
|
+
*/
|
|
129
176
|
get(index: number): number;
|
|
130
177
|
/**
|
|
131
|
-
|
|
132
|
-
|
|
178
|
+
* Check if a node has been visited (has a valid distance).
|
|
179
|
+
* @param index - The node index to check
|
|
180
|
+
* @returns True if the node has been visited, false otherwise
|
|
181
|
+
*/
|
|
133
182
|
isVisited(index: number): boolean;
|
|
134
183
|
/**
|
|
135
|
-
|
|
136
|
-
|
|
184
|
+
* Reset all distances to unvisited state.
|
|
185
|
+
*/
|
|
137
186
|
clear(): void;
|
|
138
187
|
/**
|
|
139
|
-
|
|
140
|
-
|
|
188
|
+
* Get the size of the distance array.
|
|
189
|
+
* @returns The number of elements in the array
|
|
190
|
+
*/
|
|
141
191
|
size(): number;
|
|
142
192
|
}
|
|
143
193
|
//# sourceMappingURL=bit-packed.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bit-packed.d.ts","sourceRoot":"","sources":["../../../src/optimized/bit-packed.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,qBAAa,WAAW;IACpB,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,YAAY,CAAK;
|
|
1
|
+
{"version":3,"file":"bit-packed.d.ts","sourceRoot":"","sources":["../../../src/optimized/bit-packed.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,qBAAa,WAAW;IACpB,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,YAAY,CAAK;IAEzB;;;OAGG;gBACS,QAAQ,CAAC,EAAE,MAAM;IAQ7B;;;OAGG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAOxB;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAO3B;;;;OAIG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAI3B;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb;;;OAGG;IACH,OAAO,IAAI,OAAO;IAIlB;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI;IAS1C;;;OAGG;IACH,IAAI,IAAI,MAAM;IAId;;;OAGG;IACH,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAK9B;;;OAGG;IACF,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,SAAS,CAAC,MAAM,CAAC;IAKvC;;;OAGG;IACH,KAAK,CAAC,KA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