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


Python networkx.edges方法代码示例

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


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

示例1: overlap_generator

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import edges [as 别名]
def overlap_generator(args, graph):
    """
    Function to generate weight for all of the edges.
    """
    if args.overlap_weighting == "normalized_overlap":
        overlap_weighter = normalized_overlap
    elif args.overlap_weighting == "overlap":
        overlap_weighter = overlap
    elif args.overlap_weighting == "min_norm":
        overlap_weighter = min_norm
    else:
        overlap_weighter = unit
    print(" ")
    print("Weight calculation started.")
    print(" ")
    edges = nx.edges(graph)
    weights = {e: overlap_weighter(graph, e[0], e[1]) for e in tqdm(edges)}
    weights_prime = {(e[1], e[0]): value for e, value in weights.items()}
    weights.update(weights_prime)
    print(" ")
    return weights 
开发者ID:benedekrozemberczki,项目名称:GEMSEC,代码行数:23,代码来源:calculation_helper.py

示例2: test_info

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import edges [as 别名]
def test_info(self):
        G=nx.path_graph(5)
        info=nx.info(G)
        expected_graph_info='\n'.join(['Name: path_graph(5)',
                                       'Type: Graph',
                                       'Number of nodes: 5',
                                       'Number of edges: 4',
                                       'Average degree:   1.6000'])
        assert_equal(info,expected_graph_info)

        info=nx.info(G,n=1)
        expected_node_info='\n'.join(
            ['Node 1 has the following properties:',
             'Degree: 2',
             'Neighbors: 0 2'])
        assert_equal(info,expected_node_info) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:18,代码来源:test_function.py

示例3: test_info_digraph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import edges [as 别名]
def test_info_digraph(self):
        G=nx.DiGraph(name='path_graph(5)')
        G.add_path([0,1,2,3,4])
        info=nx.info(G)
        expected_graph_info='\n'.join(['Name: path_graph(5)',
                                       'Type: DiGraph',
                                       'Number of nodes: 5',
                                       'Number of edges: 4',
                                       'Average in degree:   0.8000',
                                       'Average out degree:   0.8000'])
        assert_equal(info,expected_graph_info)

        info=nx.info(G,n=1)
        expected_node_info='\n'.join(
            ['Node 1 has the following properties:',
             'Degree: 2',
             'Neighbors: 2'])
        assert_equal(info,expected_node_info)

        assert_raises(nx.NetworkXError,nx.info,G,n=-1) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:22,代码来源:test_function.py

示例4: test_non_edges

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import edges [as 别名]
def test_non_edges(self):
        # All possible edges exist
        graph = nx.complete_graph(5)
        nedges = list(nx.non_edges(graph))
        assert_equal(len(nedges), 0)

        graph = nx.path_graph(4)
        expected = [(0, 2), (0, 3), (1, 3)]
        nedges = list(nx.non_edges(graph))
        for (u, v) in expected:
            assert_true( (u, v) in nedges or (v, u) in nedges )

        graph = nx.star_graph(4)
        expected = [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
        nedges = list(nx.non_edges(graph))
        for (u, v) in expected:
            assert_true( (u, v) in nedges or (v, u) in nedges )

        # Directed graphs
        graph = nx.DiGraph()
        graph.add_edges_from([(0, 2), (2, 0), (2, 1)])
        expected = [(0, 1), (1, 0), (1, 2)]
        nedges = list(nx.non_edges(graph))
        for e in expected:
            assert_true(e in nedges) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:27,代码来源:test_function.py

示例5: test_set_edge_attributes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import edges [as 别名]
def test_set_edge_attributes():
    graphs = [nx.Graph(), nx.DiGraph()]
    for G in graphs:
        G = nx.path_graph(3, create_using=G)

        # Test single value
        attr = 'hello'
        vals = 3
        nx.set_edge_attributes(G, attr, vals)
        assert_equal(G[0][1][attr], vals)
        assert_equal(G[1][2][attr], vals)

        # Test multiple values
        attr = 'hi'
        edges = [(0,1), (1,2)]
        vals = dict(zip(edges, range(len(edges))))
        nx.set_edge_attributes(G, attr, vals)
        assert_equal(G[0][1][attr], 0)
        assert_equal(G[1][2][attr], 1) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:21,代码来源:test_function.py

示例6: test_add_star

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import edges [as 别名]
def test_add_star(self):
        G = self.G.copy()
        nlist = [12, 13, 14, 15]
        nx.add_star(G, nlist)
        assert_edges_equal(G.edges(nlist), [(12, 13), (12, 14), (12, 15)])

        G = self.G.copy()
        nx.add_star(G, nlist, weight=2.0)
        assert_edges_equal(G.edges(nlist, data=True),
                           [(12, 13, {'weight': 2.}),
                            (12, 14, {'weight': 2.}),
                            (12, 15, {'weight': 2.})])

        G = self.G.copy()
        nlist = [12]
        nx.add_star(G, nlist)
        assert_nodes_equal(G, list(self.G) + nlist)

        G = self.G.copy()
        nlist = []
        nx.add_star(G, nlist)
        assert_nodes_equal(G.nodes, self.Gnodes)
        assert_edges_equal(G.edges, self.G.edges) 
开发者ID:holzschu,项目名称:Carnets,代码行数:25,代码来源:test_function.py

示例7: test_info_digraph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import edges [as 别名]
def test_info_digraph(self):
        G = nx.DiGraph(name='path_graph(5)')
        nx.add_path(G, [0, 1, 2, 3, 4])
        info = nx.info(G)
        expected_graph_info = '\n'.join(['Name: path_graph(5)',
                                         'Type: DiGraph',
                                         'Number of nodes: 5',
                                         'Number of edges: 4',
                                         'Average in degree:   0.8000',
                                         'Average out degree:   0.8000'])
        assert_equal(info, expected_graph_info)

        info = nx.info(G, n=1)
        expected_node_info = '\n'.join(
            ['Node 1 has the following properties:',
             'Degree: 2',
             'Neighbors: 2'])
        assert_equal(info, expected_node_info)

        assert_raises(nx.NetworkXError, nx.info, G, n=-1) 
开发者ID:holzschu,项目名称:Carnets,代码行数:22,代码来源:test_function.py

示例8: test_non_edges

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import edges [as 别名]
def test_non_edges(self):
        # All possible edges exist
        graph = nx.complete_graph(5)
        nedges = list(nx.non_edges(graph))
        assert_equal(len(nedges), 0)

        graph = nx.path_graph(4)
        expected = [(0, 2), (0, 3), (1, 3)]
        nedges = list(nx.non_edges(graph))
        for (u, v) in expected:
            assert_true((u, v) in nedges or (v, u) in nedges)

        graph = nx.star_graph(4)
        expected = [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
        nedges = list(nx.non_edges(graph))
        for (u, v) in expected:
            assert_true((u, v) in nedges or (v, u) in nedges)

        # Directed graphs
        graph = nx.DiGraph()
        graph.add_edges_from([(0, 2), (2, 0), (2, 1)])
        expected = [(0, 1), (1, 0), (1, 2)]
        nedges = list(nx.non_edges(graph))
        for e in expected:
            assert_true(e in nedges) 
开发者ID:holzschu,项目名称:Carnets,代码行数:27,代码来源:test_function.py

示例9: test_add_cycle

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import edges [as 别名]
def test_add_cycle(self):
        G = self.G.copy()
        nlist = [12, 13, 14, 15]
        oklists = [[(12, 13), (12, 15), (13, 14), (14, 15)],
                   [(12, 13), (13, 14), (14, 15), (15, 12)]]
        nx.add_cycle(G, nlist)
        assert_true(sorted(G.edges(nlist)) in oklists)
        G = self.G.copy()
        oklists = [[(12, 13, {'weight': 1.}),
                    (12, 15, {'weight': 1.}),
                    (13, 14, {'weight': 1.}),
                    (14, 15, {'weight': 1.})],
                   [(12, 13, {'weight': 1.}),
                    (13, 14, {'weight': 1.}),
                    (14, 15, {'weight': 1.}),
                    (15, 12, {'weight': 1.})]]
        nx.add_cycle(G, nlist, weight=1.0)
        assert_true(sorted(G.edges(nlist, data=True)) in oklists) 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:20,代码来源:test_function.py

示例10: __init__

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import edges [as 别名]
def __init__(self, nx_G, is_directed, p, q):
        self.G = nx_G
        self.nodes = nx.nodes(self.G)
        print("Edge weighting.\n")
        for edge in tqdm(self.G.edges()):
            self.G[edge[0]][edge[1]]["weight"] = 1.0
            self.G[edge[1]][edge[0]]["weight"] = 1.0
        self.is_directed = is_directed
        self.p = p
        self.q = q 
开发者ID:benedekrozemberczki,项目名称:GEMSEC,代码行数:12,代码来源:calculation_helper.py

示例11: index_generation

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import edges [as 别名]
def index_generation(weights, a_walk):
    """
    Function to generate overlaps and indices.
    """
    edges = [(a_walk[i], a_walk[i+1]) for i in range(0, len(a_walk)-1)]
    edge_set_1 = np.array(range(0, len(a_walk)-1))
    edge_set_2 = np.array(range(1, len(a_walk)))
    overlaps = np.array(list(map(lambda x: weights[x], edges))).reshape((-1, 1))
    return edge_set_1, edge_set_2, overlaps 
开发者ID:benedekrozemberczki,项目名称:GEMSEC,代码行数:11,代码来源:calculation_helper.py

示例12: preprocess_transition_probs

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import edges [as 别名]
def preprocess_transition_probs(self):
        """
        Preprocessing of transition probabilities for guiding the random walks.
        """
        G = self.G
        is_directed = self.is_directed

        alias_nodes = {}
        print("")
        print("Preprocesing.\n")
        for node in tqdm(G.nodes()):
             unnormalized_probs = [G[node][nbr]["weight"] for nbr in sorted(G.neighbors(node))]
             norm_const = sum(unnormalized_probs)
             normalized_probs =  [float(u_prob)/norm_const for u_prob in unnormalized_probs]
             alias_nodes[node] = alias_setup(normalized_probs)

        alias_edges = {}
        triads = {}

        if is_directed:
            for edge in G.edges():
                alias_edges[edge] = self.get_alias_edge(edge[0], edge[1])
        else:
            for edge in tqdm(G.edges()):
                alias_edges[edge] = self.get_alias_edge(edge[0], edge[1])
                alias_edges[(edge[1], edge[0])] = self.get_alias_edge(edge[1], edge[0])

        self.alias_nodes = alias_nodes
        self.alias_edges = alias_edges

        return 
开发者ID:benedekrozemberczki,项目名称:GEMSEC,代码行数:33,代码来源:calculation_helper.py

示例13: overlap_generator

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import edges [as 别名]
def overlap_generator(metric, graph):
    """
    Calculating the overlap for each edge.
    :param metric: Weight metric.
    :param graph: NetworkX object.
    :return : Edge weight hash table.
    """
    edges =[(edge[0], edge[1]) for edge in nx.edges(graph)]
    edges = edges + [(edge[1], edge[0]) for edge in nx.edges(graph)]
    return {edge: metric(graph, edge[0], edge[1]) for edge in tqdm(edges)} 
开发者ID:benedekrozemberczki,项目名称:LabelPropagation,代码行数:12,代码来源:calculation_helper.py

示例14: modularity_generator

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import edges [as 别名]
def modularity_generator(G):
    """
    Function to generate a modularity matrix.
    :param G: Graph object.
    :return laps: Modularity matrix.
    """
    print("Modularity calculation.\n")
    degs = nx.degree(G)
    e_count = len(nx.edges(G))
    modu = np.array([[float(degs[n_1]*degs[n_2])/(2*e_count) for n_1 in nx.nodes(G)] for n_2 in tqdm(nx.nodes(G))], dtype=np.float64)
    return modu 
开发者ID:benedekrozemberczki,项目名称:M-NMF,代码行数:13,代码来源:calculation_helper.py

示例15: graph_reader

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import edges [as 别名]
def graph_reader(input_path):
    """
    Function to read a csv edge list and transform it to a networkx graph object.
    :param input_path: Path to the edge list csv.
    :return graph: NetworkX grapg object.
    """
    edges = pd.read_csv(input_path)
    graph = nx.from_edgelist(edges.values.tolist())
    return graph 
开发者ID:benedekrozemberczki,项目名称:M-NMF,代码行数:11,代码来源:calculation_helper.py


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