# HITS.R (Mauro Brunato, april 2007) # # Computing HITS authority and hub scores. # Uncomment a line ending by "q()" to stop the program at that point # and show the corresponding quantity. ################################## # # GRAPH DEFINITION # The graph matrix # graph <- rbind ( c( 0, 1, 0, 0, 0 ), c( 0, 0, 1, 0, 0 ), c( 1, 0, 0, 1, 0 ), c( 0, 1, 0, 0, 1 ), c( 0, 0, 0, 1, 0 )); # Graph size # N <- length (graph[,1]); # Uncomment to see the graph matrix # #graph;q(); ##################################### # # HITS SCORE COMPUTATION # # Initialize scores uniformly # authority <- matrix ( rep (1, N), N ); hub <- matrix ( rep (1, N), N ); # Uncomment to show initial scores and stop # #matrix(c(hub, authority), N);q(); # Compute the two transition matrices # E <- graph; tE <- t(E); # Iterate through the HITS algorithm # for ( i in 1:101 ) { oldauthority <- authority; authority <- tE %*% hub; hub <- E %*% oldauthority; authority <- authority / sum(authority); hub <- hub / sum(hub); } # Print the final scores # print (matrix(c(hub, authority), N));