@graphty/algorithms
Version:
Graph algorithms library for browser environments implemented in TypeScript
50 lines • 1.87 kB
TypeScript
import type { Graph } from "../core/graph.js";
import type { NodeId } from "../types/index.js";
/**
* Common Neighbors link prediction implementation
*
* Predicts the likelihood of a link between two nodes based on the number
* of common neighbors they share. The intuition is that nodes with many
* common neighbors are more likely to be connected.
*
* Time complexity: O(k²) where k is the average degree
* Space complexity: O(k)
*/
export interface LinkPredictionScore {
source: NodeId;
target: NodeId;
score: number;
}
export interface LinkPredictionOptions {
directed?: boolean;
includeExisting?: boolean;
topK?: number;
}
/**
* Calculate common neighbors score for a pair of nodes
*/
export declare function commonNeighborsScore(graph: Graph, source: NodeId, target: NodeId, options?: LinkPredictionOptions): number;
/**
* Calculate common neighbors scores for all possible node pairs
*/
export declare function commonNeighborsPrediction(graph: Graph, options?: LinkPredictionOptions): LinkPredictionScore[];
/**
* Calculate common neighbors scores for specific node pairs
*/
export declare function commonNeighborsForPairs(graph: Graph, pairs: [NodeId, NodeId][], options?: LinkPredictionOptions): LinkPredictionScore[];
/**
* Get top candidates for link prediction for a specific node
*/
export declare function getTopCandidatesForNode(graph: Graph, node: NodeId, options?: LinkPredictionOptions & {
candidates?: NodeId[];
}): LinkPredictionScore[];
/**
* Calculate precision and recall for link prediction evaluation
*/
export declare function evaluateCommonNeighbors(trainingGraph: Graph, testEdges: [NodeId, NodeId][], nonEdges: [NodeId, NodeId][], options?: LinkPredictionOptions): {
precision: number;
recall: number;
f1Score: number;
auc: number;
};
//# sourceMappingURL=common-neighbors.d.ts.map