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


Python networkx.relaxed_caveman_graph方法代码示例

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


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

示例1: test_relaxed_caveman_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import relaxed_caveman_graph [as 别名]
def test_relaxed_caveman_graph():
    G = nx.relaxed_caveman_graph(4,3,0)
    assert_equal(len(G),12)
    assert_equal(len(G.nodes()),12)
    
    G = nx.relaxed_caveman_graph(4,3,1)
    assert_equal(len(G),12)
    assert_equal(len(G.nodes()),12)

    G = nx.relaxed_caveman_graph(4,3,0.5)
    assert_equal(len(G),12)
    assert_equal(len(G.edges()),12) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:14,代码来源:test_community.py

示例2: test_relaxed_caveman_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import relaxed_caveman_graph [as 别名]
def test_relaxed_caveman_graph():
    G = nx.relaxed_caveman_graph(4, 3, 0)
    assert_equal(len(G), 12)
    G = nx.relaxed_caveman_graph(4, 3, 1)
    assert_equal(len(G), 12)
    G = nx.relaxed_caveman_graph(4, 3, 0.5)
    assert_equal(len(G), 12)
    G = nx.relaxed_caveman_graph(4, 3, 0.5, seed=42)
    assert_equal(len(G), 12) 
开发者ID:holzschu,项目名称:Carnets,代码行数:11,代码来源:test_community.py

示例3: test_relaxed_caveman_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import relaxed_caveman_graph [as 别名]
def test_relaxed_caveman_graph():
    G = nx.relaxed_caveman_graph(4, 3, 0)
    assert_equal(len(G), 12)
    G = nx.relaxed_caveman_graph(4, 3, 1)
    assert_equal(len(G), 12)
    G = nx.relaxed_caveman_graph(4, 3, 0.5)
    assert_equal(len(G), 12) 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:9,代码来源:test_community.py

示例4: relaxed_caveman_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import relaxed_caveman_graph [as 别名]
def relaxed_caveman_graph(l, k, p, seed=None):
    """Return a relaxed caveman graph.

    A relaxed caveman graph starts with ``l`` cliques of size ``k``.  Edges are
    then randomly rewired with probability ``p`` to link different cliques.

    Parameters
    ----------
    l : int
      Number of groups
    k : int
      Size of cliques
    p : float
      Probabilty of rewiring each edge.
    seed : int,optional
      Seed for random number generator(default=None)

    Returns
    -------
    G : NetworkX Graph
      Relaxed Caveman Graph

    Raises
    ------
    NetworkXError:
     If p is not in [0,1]

    Examples
    --------
    >>> G = nx.relaxed_caveman_graph(2, 3, 0.1, seed=42)

    References
    ----------
    .. [1] Santo Fortunato, Community Detection in Graphs,
       Physics Reports Volume 486, Issues 3-5, February 2010, Pages 75-174.
       http://arxiv.org/abs/0906.0612
    """
    if not seed is None:
        random.seed(seed)
    G = nx.caveman_graph(l, k)
    nodes = G.nodes()
    G.name = "relaxed_caveman_graph (%s,%s,%s)" % (l, k, p)
    for (u, v) in G.edges():
        if random.random() < p:  # rewire the edge
            x = random.choice(nodes)
            if G.has_edge(u, x):
                continue
            G.remove_edge(u, v)
            G.add_edge(u, x)
    return G 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:52,代码来源:community.py

示例5: relaxed_caveman_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import relaxed_caveman_graph [as 别名]
def relaxed_caveman_graph(l, k, p, seed=None):
    """Returns a relaxed caveman graph.

    A relaxed caveman graph starts with `l` cliques of size `k`.  Edges are
    then randomly rewired with probability `p` to link different cliques.

    Parameters
    ----------
    l : int
      Number of groups
    k : int
      Size of cliques
    p : float
      Probabilty of rewiring each edge.
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.

    Returns
    -------
    G : NetworkX Graph
      Relaxed Caveman Graph

    Raises
    ------
    NetworkXError:
     If p is not in [0,1]

    Examples
    --------
    >>> G = nx.relaxed_caveman_graph(2, 3, 0.1, seed=42)

    References
    ----------
    .. [1] Santo Fortunato, Community Detection in Graphs,
       Physics Reports Volume 486, Issues 3-5, February 2010, Pages 75-174.
       https://arxiv.org/abs/0906.0612
    """
    G = nx.caveman_graph(l, k)
    nodes = list(G)
    for (u, v) in G.edges():
        if seed.random() < p:  # rewire the edge
            x = seed.choice(nodes)
            if G.has_edge(u, x):
                continue
            G.remove_edge(u, v)
            G.add_edge(u, x)
    return G 
开发者ID:holzschu,项目名称:Carnets,代码行数:50,代码来源:community.py

示例6: relaxed_caveman_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import relaxed_caveman_graph [as 别名]
def relaxed_caveman_graph(l, k, p, seed=None):
    """Return a relaxed caveman graph.

    A relaxed caveman graph starts with `l` cliques of size `k`.  Edges are
    then randomly rewired with probability `p` to link different cliques.

    Parameters
    ----------
    l : int
      Number of groups
    k : int
      Size of cliques
    p : float
      Probabilty of rewiring each edge.
    seed : int,optional
      Seed for random number generator(default=None)

    Returns
    -------
    G : NetworkX Graph
      Relaxed Caveman Graph

    Raises
    ------
    NetworkXError:
     If p is not in [0,1]

    Examples
    --------
    >>> G = nx.relaxed_caveman_graph(2, 3, 0.1, seed=42)

    References
    ----------
    .. [1] Santo Fortunato, Community Detection in Graphs,
       Physics Reports Volume 486, Issues 3-5, February 2010, Pages 75-174.
       https://arxiv.org/abs/0906.0612
    """
    if seed is not None:
        random.seed(seed)
    G = nx.caveman_graph(l, k)
    nodes = list(G)
    for (u, v) in G.edges():
        if random.random() < p:  # rewire the edge
            x = random.choice(nodes)
            if G.has_edge(u, x):
                continue
            G.remove_edge(u, v)
            G.add_edge(u, x)
    return G 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:51,代码来源:community.py


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