本文整理匯總了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()
示例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
示例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)
示例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])
示例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)
示例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
示例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)
示例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
示例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)
示例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
示例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
示例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)
示例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)
示例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)
示例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)