Overview
Common neighbors refer to the common adjacent nodes to both nodes. The number of common neighbors of two nodes can be used to describe the closeness of them.
Basic Concept
Common Neighbors
The number of common neighbors is calculated by the following formula:
where N(x)
and N(y)
are neighbor sets of x
and y
respectively. The larger the value of CN(x,y)
is, the closer the two nodes are, value of 0 indicates that the two nodes are not close.
Taking the above graph as an example, the common neighbors of the blue and red nodes are the yellow and green 2 nodes.
Special Case
Lonely Node, Disconnected Graph
Lonely node does not have any neighbor node, the algorithm does not calculate the common neighbors between lonely node and any other node, either it considers the common neighbors of two nodes which are located in different connected components.
Self-loop Edge
The algorithm ignores all self-loop edges when calculating neighbor nodes.
Directed Edge
For directed edges, the algorithm ignores the direction of edges but calculates them as undirected edges.
Results and Statistics
Take the graph below as an example, run the algorithm in the graph:
Algorithm results: Calculate the number of common neighbors of node 3 and other nodes, return node1
, node2
and num
node1 | node2 | num |
---|---|---|
3 | 1 | 1 |
3 | 2 | 1 |
3 | 4 | 2 |
3 | 5 | 2 |
3 | 6 | 1 |
3 | 7 | 1 |
Algorithm statistics: N/A
Command and Configuration
- Command:
algo(topological_link_prediction)
- Configurations for the parameter
params()
:
Name |
Type |
Default |
Specification | Description |
---|---|---|---|---|
ids / uuids | []_id / []_uuid |
/ | Mandatory | IDs or UUIDs of the first set of nodes to be calculated, only need to configure one of them; every node in ids/uuids will be paired with every node in ids2/uuids2 for calculation |
ids2 / uuids2 | []_id / []_uuid |
/ | Mandatory | IDs or UUIDs of the second set of nodes to be calculated, only need to configure one of them; every node in ids/uuids will be paired with every node in ids2/uuids2 for calculation |
type | string | Adamic_Adar | Adamic_Adar / Common_Neighbors / Preferential_Attachment / Resource_Allocation / Total_Neighbors | Measurement of the closeness of the node pair; Adamic_Adar means to calculate AA index, Common_Neighbors means to calculate the number of common neighbors, Preferential_Attachment means to calculate the score of preferential attachment, Resource_Allocation means to calculate the score of resource allocation, Total_Neighbors means to calculate the number of total neighbors |
limit | int | -1 | >=-1 | Number of results to return; return all results if sets to -1 or not set |
Algorithm Execution
Task Writeback
1. File Writeback
Configuration | Data in Each Row |
---|---|
filename | node1 ,node2 ,num |
Example: Calculate the number of common neighbors of node UUID = 3 and all other nodes, write the algorithm results back to file named cn
algo(topological_link_prediction).params({
uuids: [3],
uuids2: [1,2,4,5,6,7],
type: "Common_Neighbors"
}).write({
file:{
filename: "cn"
}
})
2. Property Writeback
Not supported by this algorithm.
3. Statistics Writeback
This algorithm has no statistics.
Direct Return
Alias Ordinal | Type | Description |
Column Name |
---|---|---|---|
0 | []perNodePair | Closeness of node pair | node1 , node2 , num |
Example: Calculate the number of common neighbors of node UUID = 3 and UUID = 4, define algorithm results as alias named number and return the results
algo(topological_link_prediction).params({
uuids: [3],
uuids2: [4],
type: "Common_Neighbors"
}) as number
return number
Streaming Return
Alias Ordinal | Type | Description |
Column Name |
---|---|---|---|
0 | []perNodePair | Closeness of node pair | node1 , node2 , num |
Example: Calculate the number of common neighbors of node UUID = 1 and UUID = 5,6,7, return the results in the descending closeness score
algo(topological_link_prediction).params({
uuids: [1],
uuids2: [5,6,7],
type: "Common_Neighbors"
}).stream() as cn
return cn order by cn.num desc
Real-time Statistics
This algorithm has no statistics.