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


Python Graph.vs["name"]方法代码示例

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


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

示例1: load_adjlist

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import vs["name"] [as 别名]
def load_adjlist(filename, directed=True):
    edgelist = []
    names = UniqueIdGenerator()
    for line in open(filename):
        parts = line.strip().split()
        u = names[parts.pop(0)]
        edgelist.extend([(u, names[v]) for v in parts])
    logging.debug("Edgelist for line %s : %s" % (parts, edgelist))
    g = Graph(edgelist, directed=directed)
    g.vs["name"] = names.values()
    return g
开发者ID:Peratham,项目名称:deepwalk_keras_igraph,代码行数:13,代码来源:skipgram_network.py

示例2: build_graph

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import vs["name"] [as 别名]
def build_graph(amplicons, relations):
    """
    Convert pairwise relations into a graph structure.
    """
    # Create vertices (= number of unique amplicons)
    g = Graph(len(amplicons))
    g.add_edges(relations)

    amplicon_ids = [amplicon[0] for amplicon in amplicons]
    abundances = [int(amplicon[1]) for amplicon in amplicons]
    minimum, maximum = min(abundances), max(abundances)

    # Determine canvas size
    if len(abundances) < 500:
        bbox = (1920, 1080)
    elif len(abundances) > 4000:
        bbox = (5760, 3240)
    else:
        bbox = (3840, 2160)

    # Compute node attributes
    node_colors = list()
    node_sizes = list()
    node_labels = list()
    print("Building graph", file=sys.stdout)
    for abundance in abundances:
        # Color is coded by a 3-tuple of float values (0.0 to 1.0)
        # Start from a max color in rgb(red, green, blue)
        max_color = (176, 196, 222)  # light steel blue
        color = [1.0 * (c + (255 - c) / abundance) / 255 for c in max_color]
        node_colors.append(color)
        node_size = 30 + (abundance * 70 / maximum)
        node_sizes.append(node_size)
        # Label nodes with an abundance greater than 10
        if abundance >= 10 or abundance == maximum:
            node_labels.append(str(abundance))
        else:
            node_labels.append("")  # Doesn't work with "None"

    g.vs["name"] = amplicon_ids
    g.vs["abundance"] = abundances
    g.vs["label"] = node_labels
    g.vs["color"] = node_colors
    g.vs["vertex_size"] = node_sizes

    return g, bbox
开发者ID:torognes,项目名称:swarm,代码行数:48,代码来源:graph_plot.py

示例3: repr

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import vs["name"] [as 别名]
                node_name = G.vs[path[-1]][node_name_attribute]
                if node_name == None:
                    node_name = repr(None)
                node_hashes.append((len(path), node_name))
        node_hashes.sort()
        node_hashes_string = ':'.join([repr(i) for i in node_hashes])
        node['hash_name'] = hash(node_hashes_string)
        
    # Use node hashes and generate a hash for each edge    
    edge_hashes = []
    if edge_name_attribute:
        edge_hashes = [(G.vs[edge.source]['hash_name'], G.vs[edge.target]['hash_name'], \
                                   edge[edge_name_attribute]) for edge in G.es]
    else:
        edge_hashes = [(G.vs[edge.source]['hash_name'], G.vs[edge.target]['hash_name']) \
                       for edge in G.es]
        
    # Combine these hashes and get a hash for the whole graph   
    edge_hashes.sort()
    edge_hashes_string = ':'.join([repr(i) for i in edge_hashes])
    return (hash(edge_hashes_string), G)

if __name__ == '__main__':
    g = Graph([(0,1), (0,2), (2,3), (3,4), (4,2), (2,5), (5,0), (6,3), (5,6)])
    # Give some names to vertices
    g.vs["name"] = ["Alice", "Bob", "Claire", "Dennis", "Esther", "Frank", "George"]
    # Give some names to edges. Note edge names are optional
    g.es["name"] = ["A", "B", "C", "D", "E", "F", "G", "H", "K"]
    ghash = graph_hash(g, "name", "name")
    print ghash
    
开发者ID:dksr,项目名称:graph_utils,代码行数:32,代码来源:graph_hash.py

示例4: make_cost_matrix

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import vs["name"] [as 别名]
    score_matrix = simm
    max_score = np.max(score_matrix) * 2
    # Apply the Hungarian algorithm to the score matrix
    # First compute the cost matrix from score matrix
    # Cost is opposite of score, so we use cost = (max_score * 2 - score) to compute cost.
    # Scores are sometimes very less, so using sys.maxint instead of max_score sometimes makes all scores equal
    cost_matrix = make_cost_matrix(score_matrix,
                                   lambda cost: max_score - cost)
    indexes = hungarian_alg.compute(cost_matrix)
    return score_matrix, indexes


if __name__  == "__main__":
    from igraph import Graph
    
    node_labels = ["before", "after", "s", "d", "c"]

    g1 = Graph([(0,1), (0,2), (2,3), (3,4), (4,2), (2,5), (5,0), (6,3), (5,6)],directed=True)
    g1.vs["name"] = ["before", "after", "s", "d", "c", "s", "d"]
    g1.vs["type"] = ["temporal", "temporal", "spatial", "spatial", "spatial", "spatial", "spatial"]
    compute_node_label_hist(g1,node_labels)
    g1.vs["hist"] = [[1,2,4],[1,2,4],[1,2,4],[1,2,4],[1,2,4],[1,2,4],[1,2,4]]
    g2 = Graph([(0,1), (0,2), (2,3), (3,4), (4,2), (2,5), (5,0), (6,3), (5,6)],directed=True)
    g2.vs["name"] = ["before", "after", "s", "d", "s", "s", "d"]
    g2.vs["type"] = ["temporal", "temporal", "spatial", "spatial", "spatial", "spatial", "spatial"]
    g2.vs["hist"] = [[1,2,4],[1,2,4],[1,2,4],[1,2,4],[1,2,4],[1,2,4],[1,2,4]]
    
    g1 = compute_node_label_hist(g1, node_labels)
    g2 = compute_node_label_hist(g2, node_labels)    
    print compute_similarity_score_from_node_label_hists(g1, g2)
    print compute_graph_similarity_score(g1, g2)
开发者ID:dksr,项目名称:graph_utils,代码行数:33,代码来源:graph_match.py


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