Task01:简单图论与环境配置与PyG库
近期参加了开源组织Datawhale的线上组队学习活动,因为之前有看过一些图神经的理论知识,之后的课题方向也想向图神经靠拢,所以打算跟着Datawhale再重新走一遍图神经。然后期间每个任务都会总结(估计会有很多不到位的地方拉~如果有人会看到,请多多包涵哦!)
Datawhale提供的课程链接:https://github.com/datawhalechina/team-learning-nlp/blob/master/GNN
一,简单图论
1.图的表示

节点和边的信息可以是类别型的(categorical),类别型数据的取值只能是哪一类别。一般称类别型的信息为标签(label)。
节点和边的信息可以是数值型的(numeric),数值型数据的取值范围为实数。一般称数值型的信息为属性(attribute)。


2.图的属性
2.1 结点的度

2.2 邻接结点(neighbors)

2.3 行走(walk)


2.4 路径(path)
路径是结点不可重复的行走。
2.5 子图(subgraph)

2.6 连通分量(connected component)

2.7 连通图(connected graph)
当一个图只包含一个连通分量,即其自身,那么该图是一个连通图。
2.8 最短路径(shortest path)

2.9 直径(diameter)

2.10 拉普拉斯矩阵

对称归一化的拉普拉斯矩阵如下所示:

3.图的基本类型
3.1 有向图和无向图

3.2 非加权图和加权图

3.3 连通图和非连通图

3.4 二部图

3.5 同质图和异质图
同质图(Homogeneous Graph):只有一种类型的节点和一种类型的边的图
异质图(Heterogeneous Graph):存在多种类型的节点和多种类型的边的图。
二,环境配置
1.使用nvidia-smi命令查看服务器上GPU情况

2.安装正确版本的pytorch和cudatoolkit,此处安装1.8.1版本的pytorch和11.1版本的cudatoolkit
在vscode上新建虚拟环境gnn_env_lj,用来安装正确版本的pytorch和cudatoolkit。
新建虚拟环境:conda create -n gnn_env_lj python=3.8.5,创建新的虚拟环境gnn_env_lj,并在里面安装了python3.8.5,然后conda activate gnn_env_lj,激活虚拟环境,在该虚拟环境里面安装相应版本的pytorch和cudatoolkit。
使用教程提供的conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c nvidia代码安装总是有几个包安装不上,如下图所示:


把装不上的四个包用pip install安装,发现只有不加版本号的时候才能装上,好奇怪!

最后在pytorch官网上找到对应版本的pip安装pytorch代码:pip3 install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html,
pytorch官网网址:https://pytorch.org/

运行这段代码后可以成功安装pytorch:

然后确认是否正确安装,以下结果表示安装正确。

3.安装正确版本的PyG

三.Data类——PyG中图的表示及其使用
1.PyG图数据的表示及其使用,即学习PyG中的Data类




2.PyG中图数据的表示及其使用,即学习PyG中Dataset类
PyG内置了大量常用的基准数据集,下面我们以PyG内置的Planetoid数据集为例,来学习PyG中图数据集的表示及使用


展示一个简单的GCN模型构造和训练过程,没有用到Dataset和DataLoader,我们将使用一个简单的GCN层,并在Cora数据集上实验。

4.作业

