1.加载数据函数&数据保存
import numpy as np
import dill
#dill.dump_session('GAT.pkl')
dill.load_session('t20.pkl')
save_path = "../../data/Enron/graph.pkl"
with open(save_path, "wb") as f:
pkl.dump(graphs, f)
print("Processed Data Saved at {}".format(save_path))
2.权重图加载
def MG(filename):
k_MG = nx.MultiGraph()
pass_name=[]
for s in open(filename).readlines():
s = s.strip()
s = s.split()
k_MG.add_weighted_edges_from([(s[0],s[1],1)])
pass_name.append([s[0],s[1]])
dict(k_MG.degree(weight='weight'))
k_G = nx.Graph()
for n, nbrs in k_MG.adjacency():
for nbr, edict in nbrs.items():
minvalue=sum([d['weight'] for d in edict.values()])
k_G.add_edge(n, nbr, weight = minvalue)
return k_G
k_G=MG(".\\1998-2003.txt")
3.jupyter
jupyter notebook
4.新建环境
conda create -n paddle python=3.6
activate paddle
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple gevent
5.
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
G = nx.MultiGraph() # 创建多重无向图
MultiGraph:指多重无向图,即两个结点之间的边数多于一条,又允许顶点通过同一条边和自己关联。
6.import torch
# 异常检测开启
torch.autograd.set_detect_anomaly(True)
# 反向传播时检测是否有异常值,定位code
with torch.autograd.detect_anomaly():
loss.backward()
7.打开文档
with open("data/{}/{}".format(dataset_str, "graph.pkl"), "rb") as f:
graphs = pkl.load(f)
8.列表与for的妙用
adjs = [nx.adjacency_matrix(g) for g in graphs]
9.读取文档的方式
"r" 以读方式打开,只能读文件 , 如果文件不存在,会发生异常
"w" 以写方式打开,只能写文件, 如果文件不存在,创建该文件;如果文件已存在,先清空,再打开文件
"rb" 以二进制读方式打开,只能读文件 , 如果文件不存在,会发生异常
"wb" 以二进制写方式打开,只能写文件, 如果文件不存在,创建该文件;如果文件已存在,先清空,再打开文件
1.稀疏矩阵
scipy.sparse
2.有权网络
nx_G = nx.Graph()
for e in graph.edges():
nx_G.add_edge(e[0], e[1])
for edge in graph.edges():
nx_G[edge[0]][edge[1]]['weight'] = adj[edge[0], edge[1]]
pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.9.0+${cu102}.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.9.0+${cu102}.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.9.0+${cu102}.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.9.0+${cu102}.html
pip install torch-geometric
pip install torch-geometric-temporal
you-get --playlist -o F:\bilibili https://www.bilibili.com/video/av84506749
哔哩哔哩下载
该博客涉及数据的加载、保存以及图网络的操作。内容包括使用dill和pickle进行数据序列化,构建和操作权重图,环境配置,设备设置,以及在PyTorch中进行异常检测。此外,还提到了图数据的处理,如邻接矩阵的生成,并介绍了多个与图神经网络相关的库,如torch-sparse和torch-geometric。

7825

被折叠的 条评论
为什么被折叠?



