def node_ranking(filename='network.csv', alpha=0.95): ''' Rank the nodes in the network imported from a CSV file. (1) import the adjacency matrix from `filename` file. (2) compute pagerank scores of all the nodes (3) return a list of node IDs sorted by descending order of pagerank scores Input: filename: the csv filename for the adjacency matrix, a string. alpha: a float scalar value, which is the probability of choosing option 1 (randomly follow a link on the node) Output: sorted_ids: the list of node IDs (starting from 0) in descending order of their pagerank scores, a python list of integer values, such as [2,0,1,3]. Hint: you could solve this problem using 3 lines of code. ''' ######################################### ## INSERT YOUR CODE HERE # import the adjacency matrix A from csv file "filename" A = import_A(filename) # compute the pagerank scores of all the nodes using PageRank algorithm implemented in problem 5 x = pagerank(A) # compute the sorted list of node IDs, higher ranked nodes should have higher pagerank scores. sorted_ids = score2rank(x) ######################################### return sorted_ids
def node_ranking(filename='network.csv', alpha=0.95): ''' Rank the nodes in the network imported from a CSV file. (1) import the adjacency matrix from `filename` file. (2) compute pagerank scores of all the nodes (3) return a list of node IDs sorted by descending order of pagerank scores Input: filename: the csv filename for the adjacency matrix, a string. alpha: a float scalar value, which is the probability of choosing option 1 (randomly follow a link on the node) Output: sorted_ids: the list of node IDs (starting from 0) in descending order of their pagerank scores, a python list of integer values, such as [2,0,1,3]. ''' A = import_A(filename) x = pagerank(A, alpha) sorted_ids = score2rank(x) return sorted_ids