decision2vec-neg-signed-node-attrs-jl.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:dec2vec 作者: snap-stanford 项目源码 文件源码
def read_graph():

    colnames = []
    edge_attributes = args.edge_attribute_names.split(',')
    colnames += edge_attributes

    node_attributes = dict()
    for node_input in args.node_names_attributes.split(':'):
        names = node_input.split(',')
        node_attributes[names[0]] = names[1:]
        colnames += names

    edge_attribute_types = []
    for edge_attr in edge_attributes:
        edge_attribute_types.append((edge_attr, str))


    if args.directed:
        g = nx.read_edgelist(args.input, nodetype=str, data=edge_attribute_types, create_using=nx.DiGraph())
    else:
        g = nx.read_edgelist(args.input, nodetype=str, data=edge_attribute_types, create_using=nx.Graph())

    x = np.genfromtxt(args.attributes_file, delimiter='\t', dtype=None, names=True, usecols=colnames)

    for i in range(len(x)):
        for node_type in node_attributes:
            for node_attr in node_attributes[node_type]:
                g.add_node(str(x[i][node_type]), {str(node_attr): x[i][node_attr]})
    myg = MyGraph(g, args.dimensions, args.window_size, is_directed=False, node_attributes=False, walks_per_node=args.num_walks)
    myg.create_pattern_nodes()

    print 'Graph created...'
    return myg
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号