#NEWLINE# @ not_implemented_for ( 'directed' ) #NEWLINE# @ not_implemented_for ( 'multigraph' ) #NEWLINE# def resource_allocation_index( G , ebunch = None ) : #NEWLINE# #INDENT# "Compute the resource allocation index of all node pairs in ebunch.\n\n    Resource allocation index of `u` and `v` is defined as\n\n    .. math::\n\n        \\sum_{w \\in \\Gamma(u) \\cap \\Gamma(v)} \\frac{1}{|\\Gamma(w)|}\n\n    where :math:`\\Gamma(u)` denotes the set of neighbors of `u`.\n\n    Parameters\n    ----------\n    G : graph\n        A NetworkX undirected graph.\n\n    ebunch : iterable of node pairs, optional (default = None)\n        Resource allocation index will be computed for each pair of\n        nodes given in the iterable. The pairs must be given as\n        2-tuples (u, v) where u and v are nodes in the graph. If ebunch\n        is None then all non-existent edges in the graph will be used.\n        Default value: None.\n\n    Returns\n    -------\n    piter : iterator\n        An iterator of 3-tuples in the form (u, v, p) where (u, v) is a\n        pair of nodes and p is their resource allocation index.\n\n    Examples\n    --------\n    >>> import networkx as nx\n    >>> G = nx.complete_graph(5)\n    >>> preds = nx.resource_allocation_index(G, [(0, 1), (2, 3)])\n    >>> for u, v, p in preds:\n    ...     '(%d, %d) -> %.8f' % (u, v, p)\n    ...\n    '(0, 1) -> 0.75000000'\n    '(2, 3) -> 0.75000000'\n\n    References\n    ----------\n    .. [1] T. Zhou, L. Lu, Y.-C. Zhang.\n       Predicting missing links via local information.\n       Eur. Phys. J. B 71 (2009) 623.\n       http://arxiv.org/pdf/0901.0553.pdf\n    " #NEWLINE# def predict( u , v ) : #NEWLINE# #INDENT# return sum ( ( ( 1 / G . degree ( w ) ) for w in nx . common_neighbors ( G , u , v ) ) ) #NEWLINE# #UNINDENT# return _apply_prediction ( predict , predict , ebunch )