@not_implemented_for('<STR_LIT>')<EOL>def divrank(G, alpha=<NUM_LIT>, d=<NUM_LIT>, personalization=None,<EOL>max_iter=<NUM_LIT:100>, tol=<NUM_LIT>, nstart=None, weight='<STR_LIT>',<EOL>dangling=None):
if len(G) == <NUM_LIT:0>:<EOL><INDENT>return {}<EOL><DEDENT>if not G.is_directed():<EOL><INDENT>D = G.to_directed()<EOL><DEDENT>else:<EOL><INDENT>D = G<EOL><DEDENT>W = nx.stochastic_graph(D, weight=weight)<EOL>N = W.number_of_nodes()<EOL>for n in W.nodes_iter():<EOL><INDENT>for n_ in W.nodes_iter():<EOL><INDENT>if n != n_ :<EOL><INDENT>if n_ in W[n]:<EOL><INDENT>W[n][n_][weight] *= alpha<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if n_ not in W[n]:<EOL><INDENT>W.add_edge(n, n_)<EOL><DEDENT>W[n][n_][weight] = <NUM_LIT:1.0> - alpha<EOL><DEDENT><DEDENT><DEDENT>if nstart is None:<EOL><INDENT>x = dict.fromkeys(W, <NUM_LIT:1.0> / N)<EOL><DEDENT>else:<EOL><INDENT>s = float(sum(nstart.values()))<EOL>x = dict((k, v / s) for k, v in list(nstart.items()))<EOL><DEDENT>if personalization is None:<EOL><INDENT>p = dict.fromkeys(W, <NUM_LIT:1.0> / N)<EOL><DEDENT>else:<EOL><INDENT>missing = set(G) - set(personalization)<EOL>if missing:<EOL><INDENT>raise NetworkXError('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % missing)<EOL><DEDENT>s = float(sum(personalization.values()))<EOL>p = dict((k, v / s) for k, v in list(personalization.items()))<EOL><DEDENT>if dangling is None:<EOL><INDENT>dangling_weights = p<EOL><DEDENT>else:<EOL><INDENT>missing = set(G) - set(dangling)<EOL>if missing:<EOL><INDENT>raise NetworkXError('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % missing)<EOL><DEDENT>s = float(sum(dangling.values()))<EOL>dangling_weights = dict((k, v/s) for k, v in list(dangling.items()))<EOL><DEDENT>dangling_nodes = [n for n in W if W.out_degree(n, weight=weight) == <NUM_LIT:0.0>]<EOL>for _ in range(max_iter):<EOL><INDENT>xlast = x<EOL>x = dict.fromkeys(list(xlast.keys()), <NUM_LIT:0>)<EOL>danglesum = d * sum(xlast[n] for n in dangling_nodes)<EOL>for n in x:<EOL><INDENT>D_t = sum(W[n][nbr][weight] * xlast[nbr] for nbr in W[n])<EOL>for nbr in W[n]:<EOL><INDENT>x[nbr] += (<EOL>d * (W[n][nbr][weight] * xlast[nbr] / D_t) * xlast[n]<EOL>)<EOL><DEDENT>x[n] += danglesum * dangling_weights[n] + (<NUM_LIT:1.0> - d) * p[n]<EOL><DEDENT>err = sum([abs(x[n] - xlast[n]) for n in x])<EOL>if err < N*tol:<EOL><INDENT>return x<EOL><DEDENT><DEDENT>raise NetworkXError('<STR_LIT>'<EOL>'<STR_LIT>' % max_iter)<EOL>
Returns the DivRank (Diverse Rank) of the nodes in the graph.
This code is based on networkx.pagerank.

Args: (diff from pagerank)
  alpha: controls strength of self-link [0.0-1.0]
  d: the damping factor

Reference:
  Qiaozhu Mei and Jian Guo and Dragomir Radev,
  DivRank: the Interplay of Prestige and Diversity in Information Networks,
  http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.174.7982