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


Python networkx.read_gpickle方法代码示例

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


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

示例1: read_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gpickle [as 别名]
def read_graph(self, subgraph_file=None):
        if subgraph_file is None:
            subraph_file = self.context_graph_file
        logging.info("Writing graph.")
        # write the graph out
        file_format = subgraph_file.split(".")[-1]
        if file_format == "graphml":
            return nx.read_graphml(subgraph_file)
        elif file_format == "gml":
            return nx.read_gml(subgraph_file)
        elif file_format == "gexf":
            return nx.read_gexf(subgraph_file)
        elif file_format == "net":
            return nx.read_pajek(subgraph_file)
        elif file_format == "yaml":
            return nx.read_yaml(subgraph_file)
        elif file_format == "gpickle":
            return nx.read_gpickle(subgraph_file)
        else:
            logging.warning("File format not found, returning empty graph.")
        return nx.MultiDiGraph() 
开发者ID:vz-risk,项目名称:Verum,代码行数:23,代码来源:networkx.py

示例2: dbt_dag

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gpickle [as 别名]
def dbt_dag(start_date, schedule_interval, default_args):
    temp_dag = DAG('gospel_.dbt_sub_dag', start_date=start_date, schedule_interval=schedule_interval, default_args=default_args)
    G = nx.read_gpickle('/home/airflowuser/project/graph.gpickle')

    def make_dbt_task(model_name):
        simple_model_name = model_name.split('.')[-1]
        dbt_task = BashOperator(
                    task_id=model_name,
                    bash_command='cd ~/gospel && dbt run  --profile=warehouse --target=prod --non-destructive --models {simple_model_name}'.format(simple_model_name=simple_model_name),
                    dag=temp_dag
                    )
        return dbt_task


    dbt_tasks = {}
    for node_name in set(G.nodes()):
        dbt_task = make_dbt_task(node_name)
        dbt_tasks[node_name] = dbt_task

    for edge in G.edges():
        dbt_tasks[edge[0]].set_downstream(dbt_tasks[edge[1]])
    return temp_dag 
开发者ID:airflow-plugins,项目名称:Example-Airflow-DAGs,代码行数:24,代码来源:dbt_example.py

示例3: call_exps

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gpickle [as 别名]
def call_exps(params, data_set):
    print('Dataset: %s' % data_set)
    model_hyp = json.load(
        open('gem/experiments/config/%s.conf' % data_set, 'r')
    )
    if bool(params["node_labels"]):
        node_labels = cPickle.load(
            open('gem/data/%s/node_labels.pickle' % data_set, 'rb')
        )
    else:
        node_labels = None
    di_graph = nx.read_gpickle('gem/data/%s/graph.gpickle' % data_set)
    for d, meth in itertools.product(params["dimensions"], params["methods"]):
        dim = int(d)
        MethClass = getattr(
            importlib.import_module("gem.embedding.%s" % meth),
            methClassMap[meth]
        )
        hyp = {"d": dim}
        hyp.update(model_hyp[meth])
        MethObj = MethClass(hyp)
        run_exps(MethObj, di_graph, data_set, node_labels, params) 
开发者ID:palash1992,项目名称:GEM,代码行数:24,代码来源:exp.py

示例4: process

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gpickle [as 别名]
def process(self):
        G = nx.read_gpickle(self.raw_paths[0])
        data = [[v, w, d['e_label'].item()] for v, w, d in G.edges(data=True)]

        edge_index = torch.tensor(data)[:, :2].t().contiguous()
        edge_type = torch.tensor(data)[:, 2]

        data = Data(edge_index=edge_index, edge_type=edge_type,
                    num_nodes=G.number_of_nodes())

        if self.pre_transform is not None:
            data = self.pre_filter(data)

        torch.save(self.collate([data]), self.processed_paths[0]) 
开发者ID:rusty1s,项目名称:pytorch_geometric,代码行数:16,代码来源:word_net.py

示例5: load_cache

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gpickle [as 别名]
def load_cache(self):
        mg = nx.read_gpickle(os.path.join(self._dir, 'cached_mg.gpickle'))
        src = np.load(os.path.join(self._dir, 'cached_src.npy'))
        dst = np.load(os.path.join(self._dir, 'cached_dst.npy'))
        ntid = np.load(os.path.join(self._dir, 'cached_ntid.npy'))
        etid = np.load(os.path.join(self._dir, 'cached_etid.npy'))
        ntypes = load_strlist(os.path.join(self._dir, 'cached_ntypes.txt'))
        etypes = load_strlist(os.path.join(self._dir, 'cached_etypes.txt'))
        self.train_idx = F.tensor(np.load(os.path.join(self._dir, 'cached_train_idx.npy')))
        self.test_idx = F.tensor(np.load(os.path.join(self._dir, 'cached_test_idx.npy')))
        labels = np.load(os.path.join(self._dir, 'cached_labels.npy'))
        self.num_classes = labels.max() + 1
        self.labels = F.tensor(labels)

        self.build_graph(mg, src, dst, ntid, etid, ntypes, etypes) 
开发者ID:dmlc,项目名称:dgl,代码行数:17,代码来源:rdf.py

示例6: from_pickle

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gpickle [as 别名]
def from_pickle(path: Union[str, BinaryIO], check_version: bool = True) -> BELGraph:
    """Read a graph from a pickle file.

    :param path: File or filename to read. Filenames ending in .gz or .bz2 will be uncompressed.
    :param bool check_version: Checks if the graph was produced by this version of PyBEL
    """
    graph = nx.read_gpickle(path)

    raise_for_not_bel(graph)
    if check_version:
        raise_for_old_graph(graph)

    return graph 
开发者ID:pybel,项目名称:pybel,代码行数:15,代码来源:gpickle.py

示例7: loadSBMGraph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gpickle [as 别名]
def loadSBMGraph(file_prefix):
    graph_file = file_prefix + '_graph.gpickle'
    G = nx.read_gpickle(graph_file)
    node_file = file_prefix + '_node.pkl'
    with open(node_file, 'rb') as fp:
        node_community = pickle.load(fp)
    return (G, node_community) 
开发者ID:palash1992,项目名称:GEM-Benchmark,代码行数:9,代码来源:graph_util.py

示例8: loadRealGraphSeries

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gpickle [as 别名]
def loadRealGraphSeries(file_prefix, startId, endId):
    graphs = []
    for file_id in range(startId, endId + 1):
        graph_file = file_prefix + str(file_id) + '_graph.gpickle'
        graphs.append(nx.read_gpickle(graph_file))
    return graphs 
开发者ID:palash1992,项目名称:GEM-Benchmark,代码行数:8,代码来源:graph_util.py

示例9: loadDynamicSBmGraph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gpickle [as 别名]
def loadDynamicSBmGraph(file_perfix, length):
    graph_files = ['%s_%d_graph.gpickle' % (file_perfix, i) for i in xrange(length)]
    info_files = ['%s_%d_node.pkl' % (file_perfix, i) for i in xrange(length)]

    graphs = [nx.read_gpickle(graph_file) for graph_file in graph_files]

    nodes_comunities = []
    perturbations = []
    for info_file in info_files:
        with open(info_file, 'rb') as fp:
            node_infos = pickle.load(fp)
            nodes_comunities.append(node_infos['community'])
            perturbations.append(node_infos['perturbation'])

    return zip(graphs, nodes_comunities, perturbations) 
开发者ID:palash1992,项目名称:GEM-Benchmark,代码行数:17,代码来源:graph_util.py

示例10: deserialize_network

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gpickle [as 别名]
def deserialize_network(path):
    G = nx.read_gpickle(path + "graph.pickle")
    id_to_info = nx.read_gpickle(path + "id_info.pickle")
    table_to_ids = nx.read_gpickle(path + "table_ids.pickle")
    network = FieldNetwork(G, id_to_info, table_to_ids)
    return network 
开发者ID:mitdbg,项目名称:aurum-datadiscovery,代码行数:8,代码来源:fieldnetwork.py

示例11: load_network_from_gpickle

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gpickle [as 别名]
def load_network_from_gpickle(filename, verbose=True):

    filename = re.sub('~', expanduser('~'), filename)
    G = nx.read_gpickle(filename)

    return G 
开发者ID:baryshnikova-lab,项目名称:safepy,代码行数:8,代码来源:safe_io.py

示例12: cached_reading_graph_edges

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gpickle [as 别名]
def cached_reading_graph_edges(self):
        """
        Checks if networkx and edges dictionary pickles are present. If they are older than
        CACHING_RETENTION_MINUTES, make fresh pickles, else read them from the files.
        """
        cache_dir = os.path.join(settings.home_dir, 'cache')
        if not os.path.exists(cache_dir):
            os.mkdir(cache_dir)
        cache_edges_filename = os.path.join(cache_dir, 'graph.gpickle')
        cache_graph_filename = os.path.join(cache_dir, 'edges.gpickle')

        try:
            timestamp_graph = os.path.getmtime(cache_graph_filename)
        except FileNotFoundError:
            timestamp_graph = 0  # set very old timestamp

        if timestamp_graph < time.time() - settings.CACHING_RETENTION_MINUTES * 60:  # old graph in file
            logger.info(f"Saved graph is too old. Fetching new one.")
            self.set_graph_and_edges()
            nx.write_gpickle(self.graph, cache_graph_filename)
            with open(cache_edges_filename, 'wb') as file:
                pickle.dump(self.edges, file)
        else:  # recent graph in file
            logger.info("Reading graph from file.")
            self.graph = nx.read_gpickle(cache_graph_filename)
            with open(cache_edges_filename, 'rb') as file:
                self.edges = pickle.load(file) 
开发者ID:bitromortac,项目名称:lndmanage,代码行数:29,代码来源:network.py

示例13: load_cpnet

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gpickle [as 别名]
def load_cpnet():
    global cpnet,concept2id, relation2id, id2relation, id2concept, cpnet_simple
    print("loading cpnet....")
    cpnet = nx.read_gpickle(config["paths"]["conceptnet_en_graph"])
    print("Done")

    cpnet_simple = nx.Graph()
    for u, v, data in cpnet.edges(data=True):
        w = data['weight'] if 'weight' in data else 1.0
        if cpnet_simple.has_edge(u, v):
            cpnet_simple[u][v]['weight'] += w
        else:
            cpnet_simple.add_edge(u, v, weight=w) 
开发者ID:INK-USC,项目名称:KagNet,代码行数:15,代码来源:pathfinder.py

示例14: main

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gpickle [as 别名]
def main():
	# build up a graph
	filename = '../../florentine_families_graph.gpickle'
	G = nx.read_gpickle(filename)

	# Indepedent set
	maximal_iset = nx.maximal_independent_set(G)
	out_file = 'florentine_families_graph_maximal_iset.png'
	PlotGraph.plot_graph(G, filename=out_file, colored_nodes=maximal_iset)

	maximum_iset = nxaa.maximum_independent_set(G)
	out_file = 'florentine_families_graph_maximum_iset.png'
	PlotGraph.plot_graph(G, filename=out_file, colored_nodes=maximum_iset) 
开发者ID:sparkandshine,项目名称:complex_network,代码行数:15,代码来源:independent_sets.py

示例15: main

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import read_gpickle [as 别名]
def main():
	# build up a graph
	filename = '../../florentine_families_graph.gpickle'
	G = nx.read_gpickle(filename)

	# calculate a connected dominating set
	cds = DominatingSets.min_connected_dominating_sets_non_distributed(G)

	# draw the graph
	out_file = 'florentine_families_graph_cds_non_distributed.png'
	PlotGraph.plot_graph(G, filename=out_file, colored_nodes=cds) 
开发者ID:sparkandshine,项目名称:complex_network,代码行数:13,代码来源:main.py


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