UltipaDocs
Products
Solutions
Resources
Company
Start Free Trial
UltipaDocs
Start Free Trial
  • Introduction
  • Running Algorithms
    • Degree Centrality
    • Closeness Centrality
    • Harmonic Centrality
    • Eccentricity Centrality
    • Betweenness Centrality
    • Bridges
    • Articulation Points
    • Eigenvector Centrality
    • Katz Centrality
    • CELF
    • PageRank
    • ArticleRank
    • TextRank
    • HITS
    • SybilRank
    • Jaccard Similarity
    • Overlap Similarity
    • Cosine Similarity
    • Pearson Correlation Coefficient
    • Euclidean Distance
    • KNN
    • Vector Similarity
    • Bipartite Graph
    • HyperANF
    • Weakly Connected Components (WCC)
    • Strongly Connected Components (SCC)
    • k-Edge Connected Components
    • Local Clustering Coefficient
    • Triangle Count
    • Clique Count
    • k-Core
    • k-Truss
    • p-Cohesion
    • Induced Subgraph
    • Topological Sort
    • Breadth-First Search (BFS)
    • Depth-First Search (DFS)
    • Dijkstra's Shortest Path
    • A* Shortest Path
    • Yen's K-Shortest Paths
    • Shortest Path (BFS)
    • Delta-Stepping SSSP
    • Shortest Path Faster Algorithm (SPFA)
    • All-Pairs Shortest Path (APSP)
    • Minimum Spanning Tree (MST)
    • K-Spanning Tree
    • Steiner Tree
    • Prize-Collecting Steiner Tree (PCST)
    • Minimum Cost Flow
    • Maximum Flow
    • K-Hop Fast
    • Longest Path (DAG)
    • Random Walk
    • Adamic-Adar Index
    • Common Neighbors
    • Preferential Attachment
    • Resource Allocation
    • Total Neighbors
    • Same Community
    • Louvain
    • Leiden
    • Modularity Optimization
    • Label Propagation
    • HANP
    • SLPA
    • k-Means
    • HDBSCAN
    • K-1 Coloring
    • Modularity
    • Conductance
    • Max k-Cut
      • Node2Vec
      • Struc2Vec
      • LINE
      • Fast Random Projection
      • Summary of Graph Embedding
      • Gradient Descent
      • Backpropagation
      • Skip-gram
      • Skip-gram Optimization
  1. Docs
  2. /
  3. Graph Algorithms
  4. /
  5. Similarity

Overlap Similarity

Overview

Overlap similarity is derived from Jaccard similarity, which is also called the Szymkiewicz–Simpson coefficient. It divides the size of the intersection of two sets by the size of the smaller set with the purpose to indicate how similar the two sets are.

Overlap similarity ranges from 0 to 1, where 1 indicates that one set is the subset of the other or that the two sets are identical, and 0 indicates that the sets have no elements in common.

Concepts

Overlap Similarity

Given two sets A and B, the overlap similarity between them is computed as:

In the following example, set A = {b,c,e,f,g}, set B = {a,d,b,g}, their intersection A⋂B = {b,g}, hence the overlap similarity between A and B is 2 / 4 = 0.5.

When applying Overlap Similarity to compare two nodes in a graph, each node is represented by its 1-hop neighborhood set. The 1-hop neighborhood set:

  • contains no repeated nodes;
  • excludes the two target nodes.

In this graph, the 1-hop neighborhood set of nodes u and v is:

  • Nu = {a,b,c,d,e}
  • Nv = {d,e,f}

Therefore, the overlap similarity between nodes u and v is 2 / 3 = 0.666667.

Weighted Overlap Similarity

The Weighted Overlap Similarity is an extension of the classic Overlap Similarity that takes into account the weights associated with elements in the sets being compared.

The formula for Weighted Overlap Similarity is given by:

In this weighted graph, the union of the 1-hop neighborhood sets Nu and Nv is {a,b,c,d,e,f}. For each element in the union set, assign a value equal to the sum of the edge weights between the target node and the corresponding node; assign 0 if no edge exists between them:

abcdefsum
N'u11110.504.5
N'v0000.51.5 + 0.1 =1.613.1

Therefore, the Weighted Overlap Similarity between nodes u and v is (0+0+0+0.5+0.5+0) / 3.1 = 0.322581.

Considerations

  • The algorithm treats all edges as undirected.
  • Self-loops are ignored when computing neighborhoods.

Example Graph

GQL
INSERT (userA:user {_id: "userA"}), (userB:user {_id: "userB"}),
       (userC:user {_id: "userC"}), (userD:user {_id: "userD"}),
       (running:sport {_id: "running"}), (tennis:sport {_id: "tennis"}),
       (baseball:sport {_id: "baseball"}), (swimming:sport {_id: "swimming"}),
       (badminton:sport {_id: "badminton"}), (iceball:sport {_id: "iceball"}),
       (userA)-[:likes {weight: 2}]->(tennis),
       (userA)-[:likes {weight: 1}]->(baseball),
       (userA)-[:likes {weight: 3}]->(swimming),
       (userA)-[:likes {weight: 2}]->(badminton),
       (userB)-[:likes {weight: 1}]->(running),
       (userB)-[:likes {weight: 3}]->(swimming),
       (userC)-[:likes {weight: 2}]->(swimming),
       (userD)-[:likes {weight: 1}]->(running),
       (userD)-[:likes {weight: 2}]->(badminton),
       (userD)-[:likes {weight: 2}]->(iceball)

Parameters

NameTypeDefaultDescription
typeSTRINGjaccardType of similarity to compute: overlap.
idsLIST/First group of node _ids. If empty, all nodes are used.
ids2LIST/Second group of node _ids for pairing mode. If empty, selection mode is used.
weightLIST/Numeric edge properties used as weights for weighted overlap.
degreeCutoffINT0Minimum degree to include a node (0 = no cutoff).
orderSTRING/Sorts results by similarity: asc or desc.
limitINT-1Maximum total results returned (-1 = all).
top_limitINT-1Maximum results per source node in selection mode (-1 = all).

Supports three computation modes:

  • All-pairs: When both ids and ids2 are empty, computes similarity between all node pairs in the graph.
  • Pairing: When both ids and ids2 are specified, computes similarity between each node in ids and each node in ids2.
  • Selection: When only ids is specified (no ids2), computes similarity between each node in ids and all other nodes. Use top_limit to limit results per source node.

Run Mode

Returns:

ColumnTypeDescription
node1STRINGFirst node identifier (_id)
node2STRINGSecond node identifier (_id)
similarityFLOATComputed overlap similarity score

Overlap similarity in pairing mode:

GQL
CALL algo.similarity({
  type: "overlap",
  ids: ["userA", "userB"],
  ids2: ["userB", "userC", "userD"]
}) YIELD node1, node2, similarity

Result:

node1node2similarity
userAuserB0.5
userAuserC1
userAuserD0.3333333333333333
userBuserC1
userBuserD0.5

Overlap similarity in selection mode:

GQL
CALL algo.similarity({
  type: "overlap",
  ids: ["userA"],
  weight: ["weight"],
  top_limit: 2
}) YIELD node1, node2, similarity

Result:

node1node2similarity
userAuserC1
userAuserB0.75

Stream Mode

Returns the same columns as run mode, streamed for memory efficiency.

GQL
CALL algo.similarity.stream({
  type: "overlap",
  degreeCutoff: 3
}) YIELD node1, node2, similarity
RETURN node1, node2, similarity

Result:

node1node2similarity
swimminguserA0
swimminguserD0
userAswimming0
userAuserD0.3333333333333333
userDswimming0
userDuserA0.3333333333333333

Stats Mode

Returns:

ColumnTypeDescription
pairCountINTNumber of node pairs computed
minSimilarityFLOATMinimum similarity score
maxSimilarityFLOATMaximum similarity score
avgSimilarityFLOATAverage similarity score
GQL
CALL algo.similarity.stats({
  type: "overlap"
}) YIELD pairCount, minSimilarity, maxSimilarity, avgSimilarity

Result:

pairCountminSimilaritymaxSimilarityavgSimilarity
90010.26296296296296295

Write Mode

Computes results and writes them back to node properties. The write configuration is passed as a second argument map.

Write parameters:

NameTypeDescription
db.propertySTRING or MAPNode property to write results to. String: writes the similarity column in results to a property. Map: explicit column-to-property mapping (e.g., {similarity: 'sim_score'}).

Writable columns:

ColumnTypeDescription
similarityFLOATComputed overlap similarity score

Returns:

ColumnTypeDescription
task_idSTRINGTask identifier for tracking via SHOW TASKS
nodesWrittenINTNumber of nodes with properties written
computeTimeMsINTTime spent computing the algorithm (milliseconds)
writeTimeMsINTTime spent writing properties to storage (milliseconds)
GQL
CALL algo.similarity.write({type: "overlap", ids: ["userA", "userB"]}, {
  db: {
    property: "sim_score"
  }
}) YIELD task_id, nodesWritten, computeTimeMs, writeTimeMs