---
title: "Adamic Adar"
component: "graph-ml"
version: "3.10"
module: "link-prediction"
html_url: "/graph-ml/3.10/link-prediction/adamic-adar"
canonical_url: "https://www.tigergraph.com/docs/graph-ml/3.10/link-prediction/adamic-adar"
markdown_url: "https://www.tigergraph.com/docs/graph-ml/3.10/link-prediction/adamic-adar.md"
---

[View as HTML](https://www.tigergraph.com/docs/graph-ml/3.10/link-prediction/adamic-adar)

# Adamic Adar

Supported Graph Characteristics

| Unweighted edges |
| --- |
| Homogeneous vertex types |
| Heterogeneous vertex types |

Algorithm link: [Adamic Adar](https://github.com/tigergraph/gsql-graph-algorithms/tree/master/algorithms/Topological%20Link%20Prediction/adamic%5Fadar)

The Adamic/Adar index is a measure according to the number of shared links between two vertices. It is defined as the sum of the inverse logarithmic degree centrality of the neighbors shared by the two vertices.

\\\[{A(x,y)=\\sum \_{u\\in N(x)\\cap N(y)}{\\frac {1}{\\log {|N(u)|}}}}\\\]

Where \\({N(u)}\\) is the set of vertices adjacent to _u_.

This algorithm was created in 2003 by Lada Adamic and Eytan Adar.

## Notes

This algorithm ignores edge weights.

## Specifications

```gsql
CREATE QUERY tg_adamic_adar(VERTEX v_source VERTEX v_target, SET<STRING> e_type)
```

### Parameters

| Name | Description | Default value |
| --- | --- | --- |
| `VERTEX v_source` | The first vertex to compare. Provide the vertex ID and type as a tuple: `("id","type")` | N/A |
| `VERTEX v_target` | The second vertex to compare with the first. Provide the vertex ID and type as a tuple: `("id","type")` | N/A |
| `SET<STRING> e_type_set` | Edge types to traverse. | (A blank set of strings) |

### Output

Returns Adamic Adar index between the two given vertices. If the two vertices do not have common neighbors, the algorithm will return a division by 0 error.

### Time complexity

The algorithm has a time complexity of \\(O(D1 + D2)\\), where \\(D1\\) and \\(D2\\) are the degrees of the two vertices.

## Example

Suppose we have the graph below:

![adamic adar ex](https://www.tigergraph.com/docs/graph-ml/3.10/link-prediction/_images/adamic-adar-ex.png) 

Running the algorithm between Jenny and Dan will give us a result of \\(1/\\log(2) = 3.32193\\).

* Query
* Result

```gsql
RUN QUERY adamic_adar (("Jenny", "person"), ("Dan", "person"), ["friendship"])
```

```json
{
    "error": false,
    "message": "",
    "version": {
    "schema": 1,
    "edition": "enterprise",
    "api": "v2"
    },
    "results": [{"@@closeness": 3.32193}]
}
```
