• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python json_graph.node_link_graph函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中networkx.readwrite.json_graph.node_link_graph函数的典型用法代码示例。如果您正苦于以下问题:Python node_link_graph函数的具体用法?Python node_link_graph怎么用?Python node_link_graph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: iso_json

 def iso_json(string1,string2):
     dataG1 = json.loads(string1)
     graph1 = json_graph.node_link_graph(dataG1)
     dataG2 = json.loads(string2)
     graph2 = json_graph.node_link_graph(dataG2)
    # return nx.is_isomorphic(graph1, graph2)
     return nx.faster_could_be_isomorphic(graph1, graph2)
开发者ID:yangxiaoxiaoo,项目名称:cs281sec09,代码行数:7,代码来源:Spark_auto_sim.py


示例2: restore_anm_nidb_from_json

def restore_anm_nidb_from_json(data):

    d = ank_json_custom_loads(data)
    anm = autonetkit.anm.AbstractNetworkModel()
    nidb = autonetkit.nidb.NIDB()

    for overlay_id, overlay_data in d.items():
        if overlay_id == "nidb":
            continue # don't restore nidb graph to anm
        anm._overlays[overlay_id] = json_graph.node_link_graph(overlay_data)

    nidb._graph = json_graph.node_link_graph(d['nidb'])
    rebind_interfaces(anm)

    return anm, nidb
开发者ID:backb1,项目名称:autonetkit,代码行数:15,代码来源:ank_json.py


示例3: graphs_json2networkx

def graphs_json2networkx(input_dict):
    from json import loads
    from networkx.readwrite import json_graph

    gtext = loads(input_dict['graph'])
    g =  json_graph.node_link_graph(gtext)
    return {'nxgraph': g}
开发者ID:Alshak,项目名称:clowdflows,代码行数:7,代码来源:library.py


示例4: main

def main(json_file, output_prefix, source, target):
    
    with open(json_file) as data_file:    
        data = json.load(data_file)

    G = json_graph.node_link_graph(data, directed=False)

    print "Finished Reading in Graph: {0}".format(datetime.datetime.now())

    id_seq = networkx.get_node_attributes(G, "sequence")

    seq_id = { seq : node_id for node_id, seq in id_seq.items()}

    print "Created inverse lookup table: {0}".format(datetime.datetime.now())

    if ',' in target:
        targets = target.split(',')

    for target in targets:
        paths = networkx.all_shortest_paths(G, seq_id[source], seq_id[target])

        with open("{0}_paths_{1}_{2}.txt".format(output_prefix, source, target), 'w') as o:
            for path in paths:
                o.write(",".join( [id_seq[node_id] for node_id in path ] ))
	        o.write("\n")

    print "Output paths: {0}".format(datetime.datetime.now())
开发者ID:arubenstein,项目名称:deep_seq,代码行数:27,代码来源:ShortestPaths.py


示例5: restore_anm_nidb_from_json

def restore_anm_nidb_from_json(data):
    # This can be used to extract from the json used to send to webserver

    d = ank_json_custom_loads(data)
    anm = autonetkit.anm.AbstractNetworkModel()
    nidb = autonetkit.nidb.DeviceModel()

    for overlay_id, overlay_data in d.items():
        if overlay_id == "nidb":
            continue # don't restore nidb graph to anm
        anm._overlays[overlay_id] = json_graph.node_link_graph(overlay_data)

    nidb._graph = json_graph.node_link_graph(d['nidb'])
    rebind_interfaces(anm)

    return anm, nidb
开发者ID:rackbone,项目名称:autonetkit,代码行数:16,代码来源:ank_json.py


示例6: graph

 def graph(self, node_links_data):
     self.g = json_graph.node_link_graph(node_links_data)
     remove = list()
     for _id in self.g.node:
         if self.g.node[_id]["node_type"] not in self.valid_type:
             remove.append(_id)
     self.g.remove_nodes_from(remove)
开发者ID:nemethf,项目名称:escape,代码行数:7,代码来源:Orchestrator.py


示例7: as_tree

 def as_tree(graph, root=OPENSTACK_CLUSTER, reverse=False):
     linked_graph = json_graph.node_link_graph(graph)
     if 0 == nx.number_of_nodes(linked_graph):
         return {}
     if reverse:
         linked_graph = linked_graph.reverse()
     return json_graph.tree_data(linked_graph, root=root)
开发者ID:openstack,项目名称:vitrage,代码行数:7,代码来源:rest.py


示例8: load_json

def load_json(stream):
    """
    Args:
        stream: Open stream containing js

    Assumes the js is in networkx link-node format
    """
    
    js = json.load(stream)
    g = json_graph.node_link_graph(js)

    assert all([nd.has_key('coords') for nd in g.node.values()]),\
           "json node-link graph must have nodes with coords for GeoGraph"

    # get coords
    coords = [v['coords'] for v in g.node.values()]

    # set default projection
    input_proj = ""
    if gm.is_in_lon_lat(coords):
        input_proj = gm.PROJ4_LATLONG
    else:
        input_proj = gm.PROJ4_FLAT_EARTH

    coords_dict = {k: v['coords'] for k, v in g.node.items()}
    # now get rid of 'coords' key,val for each node
    for node in g.node.values():
        node.pop('coords', None)

    geo_nodes = GeoGraph(srs=input_proj, coords=coords_dict, data=g)
    return geo_nodes
开发者ID:invisibleroads,项目名称:networker,代码行数:31,代码来源:__init__.py


示例9: get_selected_reaction

def get_selected_reaction(jsonGraph, nodeDic, reacIDs, org):
    """
    Filtering selected Reactions and show Results from PyNetMet calculation.
    It returns a subgraph of the Graph from the jsonGraph. The output is a DOT-Language String.
    @param jsonGraph: Graph in JSON-Format
    @param nodeDic: dict mapping names to ids
    @param reacIDs: Name of reactions that contained in the nodeDic
    @param org: organism
    @return Subgraph
    """
    # Translate reac names to IDs
    # Get substrates and products of all reacs
    metabolites = []
    for reac in reacIDs:
        metabolites += org.get_reaction(reac).metabolites

    met_ids = list(map(lambda x: nodeDic[x], metabolites))
    g = json_graph.node_link_graph(jsonGraph)

    g.remove_edges_from(list(filter(lambda x: g.get_edge_data(*x)["object"].name not in reacIDs, g.edges(met_ids))))

    # Get products/substrates directly connected to filter
    #reacIDs += flatten(g.in_edges(reacIDs)) + flatten(g.out_edges(reacIDs))

    h = g.subgraph(met_ids)
    return h
开发者ID:CyanoFactory,项目名称:CyanoFactoryKB,代码行数:26,代码来源:helpers.py


示例10: read_from_json_gexf

def read_from_json_gexf(fname=None,label_field_name='APIs',conv_undir = False):
    '''
    Load the graph files (.gexf or .json only supported)
    :param fname: graph file name
    :param label_field_name: filed denoting the node label
    :param conv_undir: convert to undirected graph or not
    :return: graph in networkx format
    '''
    if not fname:
        logging.error('no valid path or file name')
        return None
    else:
        try:
            try:
                with open(fname, 'rb') as File:
                    org_dep_g = json_graph.node_link_graph(json.load(File))
            except:
                org_dep_g = nx.read_gexf (path=fname)

            g = nx.DiGraph()
            for n, d in org_dep_g.nodes_iter(data=True):
                g.add_node(n, attr_dict={'label': '-'.join(d[label_field_name].split('\n'))})
            g.add_edges_from(org_dep_g.edges_iter())
        except:
            logging.error("unable to load graph from file: {}".format(fname))
            # return 0
    logging.debug('loaded {} a graph with {} nodes and {} egdes'.format(fname, g.number_of_nodes(),g.number_of_edges()))
    if conv_undir:
        g = nx.Graph (g)
        logging.debug('converted {} as undirected graph'.format (g))
    return g
开发者ID:SongFGH,项目名称:subgraph2vec_tf,代码行数:31,代码来源:make_subgraph2vec_corpus.py


示例11: find_min_spanning_tree

def find_min_spanning_tree(A):
	"""
		Input:
			A : Adjecency matrix in scipy.sparse format.
		Output:
			T : Minimum spanning tree.
			run_time : Total runtime to find minimum spanning tree 

	"""
	# Record start time.
	start = time.time()

	# Check if graph is pre-processed, if yes then don't process it again.
	if os.path.exists('../Data/dcg_graph.json'):
		with open('../Data/dcg_graph.json') as data:
			d = json.load(data)
		G = json_graph.node_link_graph(d)

	# If graph is not preprocessed then convert it to a Graph and save it to a JSON file.
	else:
		G = from_scipy_sparse_matrix(A)
		data = json_graph.node_link_data(G)
		with open('../Data/dcg_graph.json', 'w') as outfile:
			json.dump(data, outfile)

	# Find MST.
	T = minimum_spanning_tree(G)

	#Record total Runtime
	run_time = time.time()-start
	return T, run_time
开发者ID:harshaneelhg,项目名称:Thesis,代码行数:31,代码来源:spanning_tree.py


示例12: main

def main(json_file, output_prefix, metric):
    
    with open(json_file) as data_file:    
        data = json.load(data_file)

    G = json_graph.node_link_graph(data)

    metrics = {}

    #metrics["degree"] = degree(G)
    metrics["closeness"] = closeness_centrality(G).values()
    #TODO: add any other metrics here using a similar format to above line.
    sequences = {}    	

    cleaved_seq = { key : val for key, val in sequences.items() if val["type"] == "CLEAVED" }

    if metric != "metrics":
	labels_to_plot = [metric]
    else:
	labels_to_plot = metrics.keys()
    n_to_plot = len(labels_to_plot)
    fig, axarr = pconv.create_ax(n_to_plot, 1, shx=False, shy=False)

    nbins = 20    

    for ind, key in enumerate(labels_to_plot):
	normed = True
        hist.draw_actual_plot(axarr[0,ind], metrics["key"], "", key.capitalize(), normed=normed, nbins=nbins)    
        axarr[0,ind].ticklabel_format(axis='x', style='sci', scilimits=(-2,2))

        #pconv.add_legend(axarr[0,ind], location="middle right")
    pconv.save_fig(fig, output_prefix, "metrics", n_to_plot*5, 5, tight=True, size=12) 
开发者ID:arubenstein,项目名称:deep_seq,代码行数:32,代码来源:NXGraphMetrics.py


示例13: transferRedditDataFormat

def transferRedditDataFormat(dataset_dir, output_file):
    G = json_graph.node_link_graph(json.load(open(dataset_dir + "/reddit-G.json")))
    labels = json.load(open(dataset_dir + "/reddit-class_map.json"))

    train_ids = [n for n in G.nodes() if not G.node[n]['val'] and not G.node[n]['test']]
    test_ids = [n for n in G.nodes() if G.node[n]['test']]
    val_ids = [n for n in G.nodes() if G.node[n]['val']]
    train_labels = [labels[i] for i in train_ids]
    test_labels = [labels[i] for i in test_ids]
    val_labels = [labels[i] for i in val_ids]
    feats = np.load(dataset_dir + "/reddit-feats.npy")
    ## Logistic gets thrown off by big counts, so log transform num comments and score
    feats[:, 0] = np.log(feats[:, 0] + 1.0)
    feats[:, 1] = np.log(feats[:, 1] - min(np.min(feats[:, 1]), -1))
    feat_id_map = json.load(open(dataset_dir + "reddit-id_map.json"))
    feat_id_map = {id: val for id, val in feat_id_map.iteritems()}

    # train_feats = feats[[feat_id_map[id] for id in train_ids]]
    # test_feats = feats[[feat_id_map[id] for id in test_ids]]

    # numNode = len(feat_id_map)
    # adj = sp.lil_matrix(np.zeros((numNode,numNode)))
    # for edge in G.edges():
    #     adj[feat_id_map[edge[0]], feat_id_map[edge[1]]] = 1

    train_index = [feat_id_map[id] for id in train_ids]
    val_index = [feat_id_map[id] for id in val_ids]
    test_index = [feat_id_map[id] for id in test_ids]
    np.savez(output_file, feats = feats, y_train=train_labels, y_val=val_labels, y_test = test_labels, train_index = train_index,
             val_index=val_index, test_index = test_index)
开发者ID:hammadhaleem,项目名称:FastGCN,代码行数:30,代码来源:train_batch_multiRank_inductive_reddit_onelayer.py


示例14: read_json_graph

def read_json_graph(istream):
    """
    Reads a json graph output by the algorithm and returns it
    """
    data = json.loads(istream.read())
    G = json_graph.node_link_graph(data)
    return G
开发者ID:bencrabbe,项目名称:nlp-toolbox,代码行数:7,代码来源:postprocess.py


示例15: simple_to_nx

def simple_to_nx(j_data):
    port_to_index_mapping = defaultdict(dict)
    for node in j_data['nodes']:
        if not "ports" in node:
            continue
        node_id = node['id']
        # first check for loopback zero
        ports = node['ports']
        _ports = {}  # output format
        try:
            lo_zero = [p for p in ports if p['id'] == "Loopback0"].pop()
        except IndexError:
            # can't pop -> no loopback zero, append
            lo_zero = {'category': 'loopback',
                       'description': "Loopback Zero"}
        else:
            ports.remove(lo_zero)
        finally:
            _ports[0] = lo_zero
        '''Sharad: below change is for 2nd loopback. currently commenting it out.
           change start in below loop to 2 while adding another loopback
        lo_one = {'category': 'loopback',
                      'description': "Loopback One",
                   'id':'loopback1'}
        _ports[1] = lo_one
        '''
        for index, port in enumerate(ports, start=1):
            _ports[index] = port
            port_to_index_mapping[node_id][port['id']] = index

        del node['ports']
        node['_ports'] = _ports

    nodes_by_id = {n['id']: i for i, n
                   in enumerate(j_data['nodes'])}

    unmapped_links = []

    if "links" in j_data:
        mapped_links = j_data['links']
        for link in mapped_links:
            src = link['src']
            dst = link['dst']
            src_pos = nodes_by_id[src]
            dst_pos = nodes_by_id[dst]
            src_port_id = port_to_index_mapping[src][link['src_port']]
            dst_port_id = port_to_index_mapping[dst][link['dst_port']]

            interfaces = {src: src_port_id,
                          dst: dst_port_id}

            unmapped_links.append({'source': src_pos,
                                   'target': dst_pos,
                                   '_ports': interfaces,
                                   'link_type': link['link_type']
                                   })

    j_data['links'] = unmapped_links
    return json_graph.node_link_graph(j_data)
开发者ID:datacenter,项目名称:ignite,代码行数:59,代码来源:load_json.py


示例16: load

    def load(self, content):
        loaded = json.loads(content)
        self.G = json_graph.node_link_graph(loaded['structure'])

        for folder in loaded['data']:
            temp = Folder()
            temp.load(loaded['data'][folder])
            self.data[folder] = temp
开发者ID:ZodiacWorkingGroup,项目名称:WalrusOS,代码行数:8,代码来源:classes.py


示例17: get_all_tags_graph

def get_all_tags_graph():
    try:
        j = AllTagsGraph.objects.all()[:1][0].graph
        d = simplejson.loads(j)
        g = json_graph.node_link_graph(d, directed=True)
    except IndexError:
        g = networkx.read_edgelist('taggraph/fixtures/wired_text_hubpagerank.edgelist',
            create_using=networkx.DiGraph())
        tg = BaseTagGraph()
        tg.graph = g
        tg._pagerank()
        j = tg.to_json()
        AllTagsGraph.objects.create(graph=simplejson.dumps(j))
        j = AllTagsGraph.objects.all()[:1][0].graph
        d = simplejson.loads(j)
        g = json_graph.node_link_graph(d, directed=True)
    return g
开发者ID:w121211,项目名称:noodle,代码行数:17,代码来源:utils.py


示例18: create_manhattan_scenario

def create_manhattan_scenario(load='high', reduced = False):
    #load graph, get positions
    if reduced:
        with open('assets/manhattan_road_netx_constrained.json','r') as data_file: 
            road_graph = json_graph.node_link_graph(json.load(data_file))
    else:
        with open('assets/manhattan_road_netx.json','r') as data_file: 
            road_graph = json_graph.node_link_graph(json.load(data_file))

    pos = OrderedDict({node: (road_graph.node[node]["latlon"][1],
                   road_graph.node[node]["latlon"][0]) for node in road_graph.nodes()})
    
    with open('assets/manhattan_demands_50.json','r') as f:
        raw_demands = json.loads(f.read())
    
    #implement 1-NN, get relationship of source, sink -> source_node, sink_node
    station_to_node = {}

    for station, loc in raw_demands['stations'].iteritems():
        node = get_neighbor(pos, (loc[1], loc[0]), 1)[0]
        station_to_node[station] = road_graph.nodes().index(node)


    #create demands list of tuples using the 1-NN relationship and the demands
    demands = {}

    for scenario in raw_demands['scenarios']:
        demands[scenario] = {}
        for demand in raw_demands['scenarios'][scenario]:
            src = station_to_node[demand[0]]
            snk = station_to_node[demand[1]]
            if src in demands[scenario]:
                if snk in demands[scenario][src]:
                    demands[scenario][src] += demand[2]
                else:
                    demands[scenario][src][snk] = demand[2]
            else:
                demands[scenario][src] = {}
                demands[scenario][src][snk] = demand[2]
        dems = []
        for src, sinks in demands[scenario].iteritems():
            for snk, d in sinks.iteritems():
                dems.append((src,snk,d))
        demands[scenario] = dems
     
    return road_graph, pos, demands[load]
开发者ID:huevosabio,项目名称:notebooks,代码行数:46,代码来源:test_cases.py


示例19: get_commit_tree_json

def get_commit_tree_json(repo):
    import json
    from networkx.readwrite import json_graph

    with open('./data/' + repo + ':commits', 'r') as f:
        data = f.read()
        json_data = json.loads(data)
        return json_graph.node_link_graph(json_data)
开发者ID:nhhughes,项目名称:eeros-community-analysis,代码行数:8,代码来源:Analysis.py


示例20: load_graph

def load_graph(path):
    try:
        json_data = open(path, 'r')
        image_graph = json_graph.node_link_graph(eval(json_data.read()))
        json_data.close()
    except FileNotFoundError:
        image_graph = networkx.Graph()
    return image_graph
开发者ID:Shoeboxam,项目名称:Texture_Synthesis,代码行数:8,代码来源:network.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python testing.assert_edges_equal函数代码示例发布时间:2022-05-27
下一篇:
Python json_graph.node_link_data函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap