The Adamic-Adar index predicts future links by giving more weight to common neighbors with lower degree. A common friend with two connections is treated as a stronger signal than one connected to 1,000 people. section 10.3.4
Calculate the score in three steps:
- Find every common neighbor shared by nodes x and y. section 10.3.4
- Calculate the degree of each common neighbor. section 10.3.4
- Sum the inverse logarithm of those degrees; lower-degree neighbors contribute more. section 10.3.4
Social-network intuition
If A and B share C and D, and both common friends have 1,000 friends, their Adamic-Adar score is weaker than when C and D have only two friends each. The same reasoning can describe overlap in a Twitch network. section 10.3.4
Listing 10.6 Calculating the Adamic-Adar index between pairs of nodes in the train and test sets
run_query("""
MATCH (s1:Stream)-[r:TEST_TRAIN|NEGATIVE_TEST_TRAIN]->(s2:Stream)
OPTIONAL MATCH (s1)-[:FEATURE_REL]-(neighbor)-[:FEATURE_REL]-(s2)
WITH r, collect(distinct neighbor) AS commonNeighbors #1
UNWIND commonNeighbors AS cn
WITH r, count{ (cn)-[:FEATURE_REL]-() } AS neighborDegree #2
WITH r, sum(1 / log(neighborDegree)) AS adamicAdar #3
SET r.adamicAdar = adamicAdar; #4
""")
The Cypher implementation finds common neighbors for train and test pairs, counts each neighbor’s degree, sums inverse logarithmic degrees, and stores the result as adamicAdar. section 10.3.4
Pairs with no common neighbors can produce missing adamicAdar values. A dataset may replace those values with the mean Adamic-Adar value, approximately 8.097444 in the demonstrated data. section 10.4.1
