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

Total Neighbors

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

Overview

The Total Neighbors algorithm computes the total number of distinct neighbors of two nodes as a measure of their similarity.

This algorithm takes into account the entire neighborhood of both nodes, giving a more comprehensive view of their similarity compared to algorithms that only focus on common neighbors. 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 total neighbors indicate greater similarity between nodes, while a number of 0 indicates no similarity between two nodes.

In this example, TN(D,E) = |N(D) ∪ N(E)| = |{B, C, E, F} ∪ {B, D, F}| = |{B, C, D, E, F}| = 5.

Considerations

  • The Total 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
typestringTotal_NeighborsAdamic_AdarNoType of similarity; for Total Neighbors, keep it as Total_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: 'Total_Neighbors'
}).write({
  file:{ 
    filename: 'tn'
  }
})

Results: File tn

File
C,A,3.000000
C,E,3.000000
C,G,3.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: 'Total_Neighbors'
}) as tn 
return tn 

Results: tn

node1node2num
313
353
373

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: 'Total_Neighbors'
}).stream() as tn
where tn.num >= 4
return tn

Results: tn

node1node2num
326
345
365