当前位置: 首页>>代码示例>>Python>>正文


Python networkx.adamic_adar_index方法代码示例

本文整理汇总了Python中networkx.adamic_adar_index方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.adamic_adar_index方法的具体用法?Python networkx.adamic_adar_index怎么用?Python networkx.adamic_adar_index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkx的用法示例。


在下文中一共展示了networkx.adamic_adar_index方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_edge_weight

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import adamic_adar_index [as 别名]
def get_edge_weight(self, i, j):
        aa_index = nx.adamic_adar_index(self._G, [(i, j)])
        return six.next(aa_index)[2] 
开发者ID:palash1992,项目名称:GEM-Benchmark,代码行数:5,代码来源:aa.py

示例2: adamic_adar

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import adamic_adar_index [as 别名]
def adamic_adar(self):
    """Computes adamic adar scores."""
    graph = nx.from_scipy_sparse_matrix(self.adj_matrix)
    scores = nx.adamic_adar_index(graph)
    return scores 
开发者ID:google,项目名称:gcnn-survey-paper,代码行数:7,代码来源:link_prediction_utils.py

示例3: setUp

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import adamic_adar_index [as 别名]
def setUp(self):
        self.func = nx.adamic_adar_index
        self.test = partial(_test_func, predict_func=self.func) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:5,代码来源:test_link_prediction.py

示例4: adamic_adar_index

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import adamic_adar_index [as 别名]
def adamic_adar_index(G, ebunch=None):
    r"""Compute the Adamic-Adar index of all node pairs in ebunch.

    Adamic-Adar index of `u` and `v` is defined as

    .. math::

        \sum_{w \in \Gamma(u) \cap \Gamma(v)} \frac{1}{\log |\Gamma(w)|}

    where :math:`\Gamma(u)` denotes the set of neighbors of `u`.

    Parameters
    ----------
    G : graph
        NetworkX undirected graph.

    ebunch : iterable of node pairs, optional (default = None)
        Adamic-Adar index will be computed for each pair of nodes given
        in the iterable. The pairs must be given as 2-tuples (u, v)
        where u and v are nodes in the graph. If ebunch is None then all
        non-existent edges in the graph will be used.
        Default value: None.

    Returns
    -------
    piter : iterator
        An iterator of 3-tuples in the form (u, v, p) where (u, v) is a
        pair of nodes and p is their Adamic-Adar index.

    Examples
    --------
    >>> import networkx as nx
    >>> G = nx.complete_graph(5)
    >>> preds = nx.adamic_adar_index(G, [(0, 1), (2, 3)])
    >>> for u, v, p in preds:
    ...     '(%d, %d) -> %.8f' % (u, v, p)
    ...
    '(0, 1) -> 2.16404256'
    '(2, 3) -> 2.16404256'

    References
    ----------
    .. [1] D. Liben-Nowell, J. Kleinberg.
           The Link Prediction Problem for Social Networks (2004).
           http://www.cs.cornell.edu/home/kleinber/link-pred.pdf
    """
    if ebunch is None:
        ebunch = nx.non_edges(G)

    def predict(u, v):
        return sum(1 / math.log(G.degree(w))
                   for w in nx.common_neighbors(G, u, v))

    return ((u, v, predict(u, v)) for u, v in ebunch) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:56,代码来源:link_prediction.py

示例5: adamic_adar_index

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import adamic_adar_index [as 别名]
def adamic_adar_index(G, ebunch=None):
    r"""Compute the Adamic-Adar index of all node pairs in ebunch.

    Adamic-Adar index of `u` and `v` is defined as

    .. math::

        \sum_{w \in \Gamma(u) \cap \Gamma(v)} \frac{1}{\log |\Gamma(w)|}

    where $\Gamma(u)$ denotes the set of neighbors of $u$.

    Parameters
    ----------
    G : graph
        NetworkX undirected graph.

    ebunch : iterable of node pairs, optional (default = None)
        Adamic-Adar index will be computed for each pair of nodes given
        in the iterable. The pairs must be given as 2-tuples (u, v)
        where u and v are nodes in the graph. If ebunch is None then all
        non-existent edges in the graph will be used.
        Default value: None.

    Returns
    -------
    piter : iterator
        An iterator of 3-tuples in the form (u, v, p) where (u, v) is a
        pair of nodes and p is their Adamic-Adar index.

    Examples
    --------
    >>> import networkx as nx
    >>> G = nx.complete_graph(5)
    >>> preds = nx.adamic_adar_index(G, [(0, 1), (2, 3)])
    >>> for u, v, p in preds:
    ...     '(%d, %d) -> %.8f' % (u, v, p)
    ...
    '(0, 1) -> 2.16404256'
    '(2, 3) -> 2.16404256'

    References
    ----------
    .. [1] D. Liben-Nowell, J. Kleinberg.
           The Link Prediction Problem for Social Networks (2004).
           http://www.cs.cornell.edu/home/kleinber/link-pred.pdf
    """
    def predict(u, v):
        return sum(1 / log(G.degree(w)) for w in nx.common_neighbors(G, u, v))
    return _apply_prediction(G, predict, ebunch) 
开发者ID:holzschu,项目名称:Carnets,代码行数:51,代码来源:link_prediction.py


注:本文中的networkx.adamic_adar_index方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。