HITS Algorithm - Pseudocode

Pseudocode

1 G := set of pages 2 for each page p in G do 3 p.auth = 1 // p.auth is the authority score of the page p 4 p.hub = 1 // p.hub is the hub score of the page p 5 function HubsAndAuthorities(G) 6 for step from 1 to k do // run the algorithm for k steps 7 norm = 0 8 for each page p in G do // update all authority values first 9 p.auth = 0 10 for each page q in p.incomingNeighbors do // p.incomingNeighbors is the set of pages that link to p 11 p.auth += q.hub 12 norm += square(p.auth) // calculate the sum of the squared auth values to normalise 13 norm = sqrt(norm) 14 for each page p in G do // update the auth scores 15 p.auth = p.auth / norm // normalise the auth values 16 norm = 0 17 for each page p in G do // then update all hub values 18 p.hub = 0 19 for each page r in p.outgoingNeighbors do // p.outgoingNeighbors is the set of pages that p links to 20 p.hub += r.auth 21 norm += square(p.hub) // calculate the sum of the squared hub values to normalise 22 norm = sqrt(norm) 23 for each page p in G do // then update all hub values 24 p.hub = p.hub / norm // normalise the hub values

The hub and authority values converge in the pseudocode above.

The code below does not converge, because it is necessary to limit the number of steps that the algorithm runs for. One way to get around this, however, would be to normalize the hub and authority values after each "step" by dividing each authority value by the square root of the sum of the squares of all authority values, and dividing each hub value by the square root of the sum of the squares of all hub values. This is what the pseudocode above does.

Read more about this topic:  HITS Algorithm