UNPKG

@graphty/algorithms

Version:

Graph algorithms library for browser environments implemented in TypeScript

56 lines 2.3 kB
import type { Graph } from "../core/graph.js"; import type { NodeId } from "../types/index.js"; import type { LinkPredictionOptions, LinkPredictionScore } from "./common-neighbors.js"; /** * Adamic-Adar Index link prediction implementation * * Predicts the likelihood of a link between two nodes based on their common * neighbors, weighted by the inverse logarithm of the neighbors' degrees. * This gives higher weight to rare common neighbors. * * Formula: AA(x,y) = Σ (1 / log(|Γ(z)|)) for all z ∈ Γ(x) ∩ Γ(y) * where Γ(z) is the set of neighbors of node z * * Time complexity: O(k²) where k is the average degree * Space complexity: O(k) */ /** * Calculate Adamic-Adar index for a pair of nodes */ export declare function adamicAdarScore(graph: Graph, source: NodeId, target: NodeId, options?: LinkPredictionOptions): number; /** * Calculate Adamic-Adar scores for all possible node pairs */ export declare function adamicAdarPrediction(graph: Graph, options?: LinkPredictionOptions): LinkPredictionScore[]; /** * Calculate Adamic-Adar scores for specific node pairs */ export declare function adamicAdarForPairs(graph: Graph, pairs: [NodeId, NodeId][], options?: LinkPredictionOptions): LinkPredictionScore[]; /** * Get top Adamic-Adar candidates for link prediction for a specific node */ export declare function getTopAdamicAdarCandidatesForNode(graph: Graph, node: NodeId, options?: LinkPredictionOptions & { candidates?: NodeId[]; }): LinkPredictionScore[]; /** * Calculate precision and recall for Adamic-Adar link prediction evaluation */ export declare function evaluateAdamicAdar(trainingGraph: Graph, testEdges: [NodeId, NodeId][], nonEdges: [NodeId, NodeId][], options?: LinkPredictionOptions): { precision: number; recall: number; f1Score: number; auc: number; }; /** * Compare Adamic-Adar with Common Neighbors for the same dataset */ export declare function compareAdamicAdarWithCommonNeighbors(graph: Graph, testEdges: [NodeId, NodeId][], nonEdges: [NodeId, NodeId][], options?: LinkPredictionOptions): { adamicAdar: ReturnType<typeof evaluateAdamicAdar>; commonNeighbors: { precision: number; recall: number; f1Score: number; auc: number; }; }; //# sourceMappingURL=adamic-adar.d.ts.map