  # Change Nickname

Current Nickname:

Certifications

Certificate Issued at Valid until Serial No. File
Serial No. Valid until

Not having one? Apply now! >>>

Invoice

ProductName CreateTime ID Price File
ProductName CreateTime ID Price File

# Total Neighbors

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

The Topological Link Prediction algorithm employs various metrics to assess the similarity between pairs of nodes, leveraging the topological attributes of nodes. A higher similarity score implies a greater likelihood of future connectivity between two nodes (which are not connected yet).

## 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` / / No ID/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` / / No ID/UUID of the second set of nodes to calculate; each node in `ids`/`uuids` will be paired with each node in `ids2`/`uuids2`
type string `Total_Neighbors` `Adamic_Adar` No Type of similarity; for Total Neighbors, keep it as `Total_Neighbors`
limit int >=-1 `-1` Yes Number of results to return, `-1` to return all results

## Example

The example graph is as follows: ### File Writeback

Spec Content
filename `node1`,`node2`,`num`
``````algo(topological_link_prediction).params({
uuids: ,
uuids2: [1,5,7],
type: 'Total_Neighbors'
}).write({
file:{
filename: 'tn'
}
})
``````

Results: File tn

``````C,A,3.000000
C,E,3.000000
C,G,3.000000
``````

### Direct Return

Alias Ordinal Type
Description
Columns
0 []perNodePair Node pair and its similarity `node1`, `node2`, `num`
``````algo(topological_link_prediction).params({
ids: 'C',
ids2: ['A','C','E','G'],
type: 'Total_Neighbors'
}) as tn
return tn
``````

Results: tn

node1 node2 num
3 1 3
3 5 3
3 7 3

### Stream Return

Alias Ordinal Type
Description
Columns
0 []perNodePair Node pair and its similarity `node1`, `node2`, `num`
``````find().nodes() as n
with collect(n._id) as nID
ids: 'C',
ids2: nID,
type: 'Total_Neighbors'
}).stream() as tn
where tn.num >= 4
return tn
``````

Results: tn

node1 node2 num
3 2 6
3 4 5
3 6 5