Overview
Total neighbors refers to the total distinct neighbors of two nodes. The number of total neighbors of two nodes can be used to describe the closeness of them.
Basic Concept
Total 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 TN(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 blue node has 3 neighbors, the red node has 4 neighbors, after excluding the yellow and green nodes which appear in their neighbor sets repeatedly, total neighbors of the blue and red node is 3 + 4 - 2 = 5
.
Special Case
Lonely Node, Disconnected Graph
Lonely node does not have any neighbor node, the algorithm does not calculate the total neighbors between lonely node and any other node, either it considers the total 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 total neighbors of node 3 and other nodes, return node1
, node2
and num
node1 | node2 | num |
---|---|---|
3 | 1 | 3 |
3 | 2 | 6 |
3 | 4 | 5 |
3 | 5 | 3 |
3 | 6 | 5 |
3 | 7 | 3 |
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 total neighbors of node UUID = 3 and all other nodes, write the algorithm results back to file named tn
algo(topological_link_prediction).params({
uuids: [3],
uuids2: [1,2,4,5,6,7],
type: "Total_Neighbors"
}).write({
file:{
filename: "tn"
}
})
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 total neighbors of node UUID = 3 and UUID = 4, define algorithm results as alias named tn and return the results
algo(topological_link_prediction).params({
uuids: [3],
uuids2: [4],
type: "Total_Neighbors"
}) as tn
return tn
Streaming Return
Alias Ordinal | Type | Description |
Column Name |
---|---|---|---|
0 | []perNodePair | Closeness of node pair | node1 , node2 , num |
Example: Calculate the number of total 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: "Total_Neighbors"
}).stream() as neighbors
return neighbors order by neighbors.num desc
Real-time Statistics
This algorithm has no statistics.