UltipaDocs
Try Playground
  • Introduction
    • Show Algorithms
    • Install and Uninstall
    • Run Algorithms
    • Algorithm Results and Statistics
    • Degree Centrality
    • Closeness Centrality
    • Harmonic Centrality
    • Graph Centrality
    • Betweenness Centrality
    • Eigenvector Centrality
    • CELF
    • PageRank
    • ArticleRank
    • HITS
    • SybilRank
    • Jaccard Similarity
    • Overlap Similarity
    • Cosine Similarity
    • Pearson Correlation Coefficient
    • Euclidean Distance
    • K-Hop All
    • Bipartite Graph
    • HyperANF
    • Connected Component
    • Triangle Counting
    • Induced Subgraph
    • k-Core
    • k-Truss
    • p-Cohesion
    • k-Edge Connected Components
    • Local Clustering Coefficient
    • Topological Sort
    • Schema Overview
    • Dijkstra's Single-Source Shortest Path
    • Delta-Stepping Single-Source Shortest Path
    • Shortest Path Faster Algorithm (SPFA)
    • Minimum Spanning Tree
    • Breadth-First Search (BFS)
    • Depth-First Search (DFS)
    • Adamic-Adar Index
    • Common Neighbors
    • Preferential Attachment
    • Resource Allocation
    • Total Neighbors
    • Louvain
    • Leiden
    • Label Propagation
    • HANP
    • k-Means
    • kNN (k-Nearest Neighbors)
    • K-1 Coloring
    • Conductance
      • Random Walk
      • Node2Vec Walk
      • Node2Vec
      • Struc2Vec Walk
      • Struc2Vec
      • GraphSAGE
      • GraphSAGE Train
      • LINE
      • Fast Random Projection
      • Summary of Graph Embedding
      • Gradient Descent
      • Backpropagation
      • Skip-gram
      • Skip-gram Optimization
  1. Docs
  2. /
  3. Graph Analytics & Algorithms
  4. /
  5. Topological Link Prediction

Common Neighbors

✓ File Writeback ✕ Property Writeback ✓ Direct Return ✓ Stream Return ✕ Stats

Overview

The Common Neighbors algorithm computes the number of common neighbors between two nodes as a measure of their similarity.

The logic behind this algorithm is that if two nodes have a high number of neighbors in common, they are likely to be similar or connected in some meaningful way. It is computed using the following formula:

where N(x) and N(y) are the sets of adjacent nodes to nodes x and y respectively.

More common neighbors indicate greater similarity between nodes, while a number of 0 indicates no similarity between two nodes.

In this example, CN(D,E) = |N(D) ∩ N(E)| = |{B, F}| = 2.

Considerations

  • The Common Neighbors algorithm ignores the direction of edges but calculates them as undirected edges.

Syntax

  • Command: algo(topological_link_prediction)
  • Parameters:
Name
Type
Spec
Default
Optional
Description
ids / uuids[]_id / []_uuid//NoID/UUID of the first set of nodes to calculate; each node in ids/uuids will be paired with each node in ids2/uuids2
ids2 / uuids2[]_id / []_uuid//NoID/UUID of the second set of nodes to calculate; each node in ids/uuids will be paired with each node in ids2/uuids2
typestringCommon_NeighborsAdamic_AdarNoType of similarity; for Common Neighbors, keep it as Common_Neighbors
limitint>=-1-1YesNumber of results to return, -1 to return all results

Example

The example graph is as follows:

File Writeback

SpecContent
filenamenode1,node2,num
UQL
algo(topological_link_prediction).params({
  uuids: [3],
  uuids2: [1,5,7],
  type: 'Common_Neighbors'
}).write({
  file:{ 
    filename: 'cn'
  }
})

Results: File cn

File
C,A,1.000000
C,E,2.000000
C,G,1.000000

Direct Return

Alias OrdinalType
Description
Columns
0[]perNodePairNode pair and its similaritynode1, node2, num
UQL
algo(topological_link_prediction).params({
  ids: 'C',
  ids2: ['A','C','E','G'],
  type: 'Common_Neighbors'
}) as cn 
return cn 

Results: cn

node1node2num
311
352
371

Stream Return

Alias OrdinalType
Description
Columns
0[]perNodePairNode pair and its similaritynode1, node2, num
UQL
find().nodes() as n
with collect(n._id) as nID
algo(topological_link_prediction).params({
  ids: 'C',
  ids2: nID,
  type: 'Common_Neighbors'
}).stream() as cn
where cn.num >= 2
return cn

Results: cn

node1node2num
342
352