diff --git a/机器学习/殷康龙/图表示学习/1 图表示学习.md b/机器学习/殷康龙/图表示学习/0 图表示学习概述.md similarity index 65% rename from 机器学习/殷康龙/图表示学习/1 图表示学习.md rename to 机器学习/殷康龙/图表示学习/0 图表示学习概述.md index d6130b19..6b475267 100644 --- a/机器学习/殷康龙/图表示学习/1 图表示学习.md +++ b/机器学习/殷康龙/图表示学习/0 图表示学习概述.md @@ -89,5 +89,34 @@ ## 4 基于邻域聚合的方法 +# 基于邻域聚合的图表示学习方法 + + + +## 概念 + +基于邻域聚合的图表示学习方法通过聚合本地邻居节点的信息得到当前节点的嵌入表示,该方法与计算机视觉领域中的“卷积”操作类似,因此基于邻域聚合的图表示学习方法也被称为基于卷积的图表示学习方法。基于邻域聚合的图表示学习方法过程如下所示,包括三个步骤: + + +``` +输入:𝐺(𝑉, 𝐸, 𝑥); W𝑡, ∀𝑡 𝜖 [1, 𝑇] +输出:节点嵌入表示𝑧𝜈, ∀𝜈 𝜖 𝑉 +初始化 ℎ𝜈0 ← 𝑥𝜈, ∀𝜈 𝜖 𝑉 +for 𝑡 = 1 to 𝑇 do + for 𝜈 𝜖 𝑉 do + ℎ𝑁(𝜈) 𝑡 ← AGGREGATE𝑡({ℎ𝑢𝑡−1, ∀𝑢 𝜖 𝑁(𝜈)}) + ℎ𝜈𝑡 ← 𝜎 (W𝑡 ∙ COMBINE(ℎ𝜈𝑡−1, ℎ𝑁(𝜈) 𝑡 )) + end + ℎ𝜈𝑡 ← NORMALIZE(ℎ𝜈𝑡 , ∀𝜈 𝜖 𝑉) +end +𝑧𝜈 ← ℎ𝜈𝑇, ∀𝜈 𝜖 𝑉 +``` +1. 信息发送。节点𝜈将自身的特征信息进行抽取变换,并发送给邻居节点𝑁(𝜈)。在初始时刻,节点𝜈的自身特征信息ℎ𝜈𝑘即为传入的节点特征𝑥𝜈;在接下来的时刻,节点的特征信息会随着每一轮信息聚合过程而发生改变。 +2. 信息聚合。节点𝜈通过信息聚合函数将邻域范围内的邻居节点的特征信息{$ℎ_𝑢^{𝑡−1}$, ∀𝑢 𝜖 𝑁(𝜈)}聚合起来,从而实现邻域内的结构信息融合。 +3. 信息变换。节点𝜈将上个时刻的节点特征ℎ𝜈𝑡−1与当前聚合到的邻居节点特征 $ℎ_{𝑁(v)}^t$结合,并进行非线性变换。 + +## 算法 + +基于邻域聚合的思路,研究者们提出了大量的图表示学习算法,如图卷积神经网络算法(GCN)[52]、GraphSAGE 算法[51]等,这些算法之间的主要区别在于信息聚合与信息变换所采用的方法不同,如 GraphSAGE 设计了通用的聚合函数框架,支持均值聚合、最大池化聚合与 LSTM 聚合等方法,并采用了特征向量拼接的方式进行信息变换;GCN 则设计了带权均值聚合函数,并采用了加权求和的方式进行信息变换,但是由于 GCN 依赖于矩阵分解运算,因此 GCN 并不具备和其它基于邻域聚合思路的图表示学习算法的同等程度的泛化能力,一旦网络中有新的节点出现,就必须重新训练模型得到新节点的嵌入表示。 ### GNN算法 \ No newline at end of file diff --git a/机器学习/殷康龙/图表示学习/1 图基础知识.md b/机器学习/殷康龙/图表示学习/1 图基础知识.md index 1de9c81b..197697c6 100644 --- a/机器学习/殷康龙/图表示学习/1 图基础知识.md +++ b/机器学习/殷康龙/图表示学习/1 图基础知识.md @@ -18,8 +18,30 @@ $$ ## 3 图的中心性 -7. 特征向量中心性。特征值越大,其相邻节点的度越大。 -8. 连接的中心性 +1. 度中心性 +2. 特征向量中心性。特征值越大,其相邻节点的度越大。 +3. 连接的中心性。节点在图中的重要性。其他节点两两到达是否经过该节点 + + ## 4 网页排序算法 ### page rank算法 +![](image/2022-01-06-16-30-51.png) + +* 节点值等于指向节点的边的值的和。 +* 边的值评分节点值 +* 阻尼系数,有0.85的概率按照路径传播。 + +具体的步骤: +1. 在初始阶段:网页通过链接关系构建起Web图,每个页面设置相同的PageRank值,通过若干轮的计算,会得到每个页面所获得的最终PageRank值。随着每一轮的计算进行,网页当前的PageRank值会不断得到更新。 + +2. 在一轮中更新页面PageRank得分的计算方法:在一轮更新页面PageRank得分的计算中,每个页面将其当前的PageRank值平均分配到本页面包含的出链上,这样每个链接即获得了相应的权值。而每个页面将所有指向本页面的入链所传入的权值求和,即可得到新的PageRank得分。当每个页面都获得了更新后的PageRank值,就完成了一轮PageRank计算。、 +![](image/2022-01-06-16-38-04.png) + +3. 由于存在一些出链为0,也就是那些不链接任何其他网页的网, 也称为孤立网页,使得很多网页能被访问到。因此需要对 PageRank公式进行修正,即在简单公式的基础上增加了阻尼系数(damping factor)q, q一般取值q=0.85。其意义是,在任意时刻,用户到达某页面后并继续向后浏览的概率。 1- q= 0.15就是用户停止点击,随机跳到新URL的概率)的算法被用到了所有页面上,估算页面可能被上网者放入书签的概率。最后,即所有这些被换算为一个百分比再乘上一个系数q。由于下面的算法,没有页面的PageRank会是0。所以,Google通过数学系统给了每个页面一个最小值。 +![](image/2022-01-06-16-37-19.png) + + + +### HITS算法 +![](image/2022-01-06-16-40-22.png) \ No newline at end of file diff --git a/机器学习/殷康龙/图表示学习/1.ipynb b/机器学习/殷康龙/图表示学习/1.ipynb new file mode 100644 index 00000000..2c261f0c --- /dev/null +++ b/机器学习/殷康龙/图表示学习/1.ipynb @@ -0,0 +1,26 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import pandas as pd\n", + "import networkx as nx\n", + "\n", + "edges = pd.DataFrame()\n", + "edges['source']" + ] + } + ], + "metadata": { + "language_info": { + "name": "python" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/机器学习/殷康龙/图表示学习/2 GraphEmbedding.md b/机器学习/殷康龙/图表示学习/2 GraphEmbedding.md new file mode 100644 index 00000000..c6abd3b4 --- /dev/null +++ b/机器学习/殷康龙/图表示学习/2 GraphEmbedding.md @@ -0,0 +1,64 @@ +# 图嵌入 + +## 0 引言 + +### 概述 +在图上进行每一个节点的embedding,最终得到的结果是图上每一个节点的嵌入表示。主要包括五种传统算法 + +1. Deepwalk +2. LINE +3. SDNE +4. node2vec +5. struct2vec + +![](image/2022-01-06-21-36-10.png) +### 作用 + +n维onehot向量表示图上的每一个节点。有多少个节点,就有多少onehot向量。如果节点的数量比较多,那么n的维度就会比较大。 + +### 代码 + +https://github.com/shenweichen/GraphEmbedding + +## 1 deepwalk + +* 对每一个节点进行多次随机游走得到一系列语义信息。 +![](image/2022-01-06-17-01-01.png) + +* w表示前后照顾的节点的数量、d表示嵌入后向量的维度、$\gamma$表示迭代的次数、t表示行走的步长 +![](image/2022-01-06-17-00-43.png) + +* 嵌入的维度为d=2的时候,就可以进行二维可视化了。如下所示,通过嵌入后的二维向量可是话,能够得到点的距离关系,相当于利用了图特征。 +![](image/2022-01-06-17-07-41.png) + + +## 2 LINE + +* 基于以下两个原理: + * 节点相互连接,并且相互连接的节点之间的权重很大,具有很高的相似性。 + * 节点的邻居如果很相似的话,那么这两个节点即使不连接,那么他们也非常相似。 +* 同时使用了一阶相似度和二阶相似度。 + + +## 3 node2vec + +* 同质性:节点和周围节点的是非常相似的。 +* 结构等价性:结构等价性 +* 有策略的随机游走。根据概率进行随机游走,选择游走序列。 + +![](image/2022-01-06-18-13-36.png) + + +## 4 struct2vec +> 这个可以以后再学,有点复杂。而且大概率用不到。 + +* 能够捕捉不相邻节点的同构信息。 + + + + +## 5 SDNE + +* 使用deeplearning的方式训练节点的embedding + +![](image/2022-01-06-21-33-56.png) \ No newline at end of file diff --git a/机器学习/殷康龙/图表示学习/2 基于邻域聚合的图表示学习方法.md b/机器学习/殷康龙/图表示学习/2 基于邻域聚合的图表示学习方法.md deleted file mode 100644 index a65bf978..00000000 --- a/机器学习/殷康龙/图表示学习/2 基于邻域聚合的图表示学习方法.md +++ /dev/null @@ -1,30 +0,0 @@ -# 基于邻域聚合的图表示学习方法 - - - - -## 概念 - -基于邻域聚合的图表示学习方法通过聚合本地邻居节点的信息得到当前节点的嵌入表示,该方法与计算机视觉领域中的“卷积”操作类似,因此基于邻域聚合的图表示学习方法也被称为基于卷积的图表示学习方法。基于邻域聚合的图表示学习方法过程如下所示,包括三个步骤: - - -``` -输入:𝐺(𝑉, 𝐸, 𝑥); W𝑡, ∀𝑡 𝜖 [1, 𝑇] -输出:节点嵌入表示𝑧𝜈, ∀𝜈 𝜖 𝑉 -初始化 ℎ𝜈0 ← 𝑥𝜈, ∀𝜈 𝜖 𝑉 -for 𝑡 = 1 to 𝑇 do - for 𝜈 𝜖 𝑉 do - ℎ𝑁(𝜈) 𝑡 ← AGGREGATE𝑡({ℎ𝑢𝑡−1, ∀𝑢 𝜖 𝑁(𝜈)}) - ℎ𝜈𝑡 ← 𝜎 (W𝑡 ∙ COMBINE(ℎ𝜈𝑡−1, ℎ𝑁(𝜈) 𝑡 )) - end - ℎ𝜈𝑡 ← NORMALIZE(ℎ𝜈𝑡 , ∀𝜈 𝜖 𝑉) -end -𝑧𝜈 ← ℎ𝜈𝑇, ∀𝜈 𝜖 𝑉 -``` -1. 信息发送。节点𝜈将自身的特征信息进行抽取变换,并发送给邻居节点𝑁(𝜈)。在初始时刻,节点𝜈的自身特征信息ℎ𝜈𝑘即为传入的节点特征𝑥𝜈;在接下来的时刻,节点的特征信息会随着每一轮信息聚合过程而发生改变。 -2. 信息聚合。节点𝜈通过信息聚合函数将邻域范围内的邻居节点的特征信息{$ℎ_𝑢^{𝑡−1}$, ∀𝑢 𝜖 𝑁(𝜈)}聚合起来,从而实现邻域内的结构信息融合。 -3. 信息变换。节点𝜈将上个时刻的节点特征ℎ𝜈𝑡−1与当前聚合到的邻居节点特征 $ℎ_{𝑁(v)}^t$结合,并进行非线性变换。 - -## 算法 - -基于邻域聚合的思路,研究者们提出了大量的图表示学习算法,如图卷积神经网络算法(GCN)[52]、GraphSAGE 算法[51]等,这些算法之间的主要区别在于信息聚合与信息变换所采用的方法不同,如 GraphSAGE 设计了通用的聚合函数框架,支持均值聚合、最大池化聚合与 LSTM 聚合等方法,并采用了特征向量拼接的方式进行信息变换;GCN 则设计了带权均值聚合函数,并采用了加权求和的方式进行信息变换,但是由于 GCN 依赖于矩阵分解运算,因此 GCN 并不具备和其它基于邻域聚合思路的图表示学习算法的同等程度的泛化能力,一旦网络中有新的节点出现,就必须重新训练模型得到新节点的嵌入表示。 \ No newline at end of file diff --git a/机器学习/殷康龙/图表示学习/graph.ipynb b/机器学习/殷康龙/图表示学习/2.ipynb similarity index 100% rename from 机器学习/殷康龙/图表示学习/graph.ipynb rename to 机器学习/殷康龙/图表示学习/2.ipynb diff --git a/机器学习/殷康龙/图表示学习/3 图神经网络GNN.md b/机器学习/殷康龙/图表示学习/3 图神经网络GNN.md new file mode 100644 index 00000000..d30b765e --- /dev/null +++ b/机器学习/殷康龙/图表示学习/3 图神经网络GNN.md @@ -0,0 +1,74 @@ +# 图神经网络GNN + + +## 简介 + + +### 概述 +包括主要的三个算法 + +* GCN +* GraphSAGE +* GAT + + +## 1 GCN +1. 原理都是利用节点周围节点的信息,聚合下一层的节点的信息。 +2. 使用对角阵D进行归一化操作。 +3. 使用邻接矩阵A和特征矩阵X相乘,聚合直接相连的节点的信息。 + +* 公式说明 +![](image/2022-01-07-09-24-40.png) + +* 物理含义 + +![](image/2022-01-07-09-29-32.png) + +* 具体目标 + * 还是得到节点的嵌入向量。 + * 利用节点的类型作为标签,进行有监督的学习 + +![](image/2022-01-07-09-33-42.png) +## 2 GraphSAGE + +### graphSAGE原理 +* 原理:聚合节点周围的节点的信息。 + +![](image/2022-01-07-09-36-53.png) + +* 算法流程。包括聚合和拼接两个关键步骤。可以定制这两个函数的具体形式。 + +![](image/2022-01-07-09-38-08.png) + +* 一个算法的实例。aggregate采用了均值函数。concat采用了直接拼接的函数。W会将节点高维的节点特征映射到低维节点特征当中。 + +![](image/2022-01-07-09-43-39.png) + +* 在以上运算的基础上进行采样。即选择固定数量的邻居节点,而不是所有的邻居节点。以下是一个采样的实例 + +![](image/2022-01-07-09-51-45.png) +* 可以选择不同的聚合函数 + +![](image/2022-01-07-09-58-37.png) + +### graphSAGE minibatch +* graphSAGE有minibatch版本。graphsage只聚合周围图的信息,而不是聚合图上所有节点的信息,所以可以通过采样选点的方式,进行训练。而不是全图训练。 +* 关于这里minibatch的含义进行说明:在GCN和上边的graphSAGE当中,全图相当于所有样本构成的样本集合,每一个图节点相当于一个样本,每个图节点都有一个类别,根据softmax层的输出和这个图节点的类别可以得到当前节点的损失,然后进行反向传播和梯度下降。输入如果是整个图,则相当于在全局的样本上进行batch梯度下降,而不是minibatch梯度下降。这样,如果图很大的话,就会导致输入过于庞大,迭代过于缓慢。所以通过采样(选择小批量的样本minibatch)的方式,进行训练,能够加快训练的速度。 + +![](image/2022-01-07-10-07-08.png) + +![](image/2022-01-07-10-07-24.png) + + +### graphSAGE embedding + +* graphSAGE无监督学习的方案。 +* 基于的原理:如果两个节点的比较相近,那么他们具有相近的表征。如果两个节点比较远,则他们的表征就会比较远。 + +![](image/2022-01-07-10-19-19.png) + +## 3 GAT +> 暂时不太需要。 +* 原理:图注意力网络。在GCN的基础上,加上了attension系数。 + +![](image/2022-01-07-10-22-08.png) \ No newline at end of file diff --git a/机器学习/殷康龙/图表示学习/3.ipynb b/机器学习/殷康龙/图表示学习/3.ipynb new file mode 100644 index 00000000..e69de29b diff --git a/机器学习/殷康龙/图表示学习/4 pgy.md b/机器学习/殷康龙/图表示学习/4 pgy.md new file mode 100644 index 00000000..3c42905f --- /dev/null +++ b/机器学习/殷康龙/图表示学习/4 pgy.md @@ -0,0 +1,27 @@ +# 入门教程 +> 常见的代码工具 +> * networkx是专门用来进行图计算的。 +> * matplotlib可以用来绘制图像的。 +> * pytorch geometric 是用来做图神经网络的 +> + +## 1 数据处理 + +### 图数据类型 + +``` +data.x: Node feature matrix with shape [num_nodes, num_node_features] + +data.edge_index: Graph connectivity in COO format with shape [2, num_edges] and type torch.long + +data.edge_attr: Edge feature matrix with shape [num_edges, num_edge_features] + +data.y: Target to train against (may have arbitrary shape), e.g., node-level targets of shape [num_nodes, *] or graph-level targets of shape [1, *] + +data.pos: Node position matrix with shape [num_nodes, num_dimensions] +``` + +## 2 常见数据集加载 + + +## \ No newline at end of file diff --git a/机器学习/殷康龙/图表示学习/4.ipynb b/机器学习/殷康龙/图表示学习/4.ipynb new file mode 100644 index 00000000..df7b9784 --- /dev/null +++ b/机器学习/殷康龙/图表示学习/4.ipynb @@ -0,0 +1,62 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "ename": "ModuleNotFoundError", + "evalue": "No module named 'torch_sparse'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mtorch\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mtorch_geometric\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdata\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mData\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m edge_index = torch.tensor([[0, 1, 1, 2],\n\u001b[0;32m 5\u001b[0m [1, 0, 2, 1]], dtype=torch.long)\n", + "\u001b[1;32mD:\\anaconda\\envs\\ml\\lib\\site-packages\\torch_geometric\\__init__.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mimportlib\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mimport_module\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mtorch_geometric\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 5\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mtorch_geometric\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloader\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mtorch_geometric\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtransforms\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mD:\\anaconda\\envs\\ml\\lib\\site-packages\\torch_geometric\\data\\__init__.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m\u001b[0mdata\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mData\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m\u001b[0mhetero_data\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mHeteroData\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m\u001b[0mtemporal\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mTemporalData\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m\u001b[0mbatch\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mBatch\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m\u001b[0mdataset\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mDataset\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mD:\\anaconda\\envs\\ml\\lib\\site-packages\\torch_geometric\\data\\data.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m from typing import (Optional, Dict, Any, Union, List, Iterable, Tuple,\n\u001b[0;32m 2\u001b[0m NamedTuple, Callable)\n\u001b[1;32m----> 3\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mtorch_geometric\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtyping\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mOptTensor\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mNodeType\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mEdgeType\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mtorch_geometric\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdeprecation\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mdeprecated\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mD:\\anaconda\\envs\\ml\\lib\\site-packages\\torch_geometric\\typing.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mtorch\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mTensor\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mtorch_sparse\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mSparseTensor\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;31m# Types for accessing data ####################################################\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'torch_sparse'" + ] + } + ], + "source": [ + "import torch\n", + "from torch_geometric.data import Data\n", + "\n", + "edge_index = torch.tensor([[0, 1, 1, 2],\n", + " [1, 0, 2, 1]], dtype=torch.long)\n", + "x = torch.tensor([[-1], [0], [1]], dtype=torch.float)\n", + "\n", + "data = Data(x=x, edge_index=edge_index)\n", + "Data(edge_index=[2, 4], x=[3, 1])" + ] + } + ], + "metadata": { + "interpreter": { + "hash": "5ef0042cb263260037aa2928643ae94e240dd3afaec7872ebebe4f07619ddd0c" + }, + "kernelspec": { + "display_name": "Python 3.8.8 64-bit ('ml': conda)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.8" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/机器学习/殷康龙/图表示学习/5 图网络的分类.md b/机器学习/殷康龙/图表示学习/5 图网络的分类.md new file mode 100644 index 00000000..e493b4c1 --- /dev/null +++ b/机器学习/殷康龙/图表示学习/5 图网络的分类.md @@ -0,0 +1,63 @@ +# 图神经网络的分类 + + +## 概述 + +主要是对图神经网络的综述,包括各种类型的图神经网络。 + +### 根据神经网络的类型进行分类 + + +![](image/2022-01-07-15-49-27.png) + +* 递归图神经网络 +![](image/2022-01-07-15-58-46.png) + +* 卷积图神经网络 +![](image/2022-01-07-16-01-30.png) + +* 自编码图神经网络 +![](image/2022-01-07-16-04-25.png) +* 注意力图神经网络 + +![](image/2022-01-07-16-06-08.png) +### 根据框架和机制进行分类 +* 基于消息传递机制的MPNN。 + * MPNN分两个阶段,消息传递阶段和Readout阶段,readout阶段可以读出整个网络的特征向量,用于图分类,这个很关键。现在缺的两个部分之一。 +![](image/2022-01-07-16-07-50.png) +* 局部图神经网络MLNN +![](image/2022-01-07-16-19-42.png) + +* 图网络GN框架统一了MPNN和MLNN + * 利用全局信息,更新每个点、每个边。 + * 利用更新后的信息,形成全局的边和点。 + * 利用全局的边和全局的点,构成新的全局信息 +![](image/2022-01-07-16-32-32.png) +![](image/2022-01-07-16-36-07.png) +![](image/2022-01-07-16-39-34.png) +![](image/2022-01-07-16-39-48.png) +### 根据图计算的任务进行分类 + +* 图计算任务的框架 + * 节点问题 + * 边问题:将两个节点作为输入,输出边的预测 + * 图问题:图分类、图匹配、图生成 +* 图上的任务类别 + * 半监督任务Node + * 有监督任务Graph Node + * 无监督任务Graph Embedding +* 图的类型 + * 异构图:点和点、边和边之间的关系不一样。节点不同。人和文章 + ![](image/2022-01-07-16-50-06.png) + * 二部图:将图中的节点分为两部分。不同部分的节点之间有边连接。但是各部分之间有连接。 + ![](image/2022-01-07-16-49-42.png) + * 多维图:边的类型有很多,多重关系组成的图。 + ![](image/2022-01-07-16-50-35.png) + * 符号图:边包含两种正负。 + ![](image/2022-01-07-16-51-01.png) + * 超图 + ![](image/2022-01-07-16-52-45.png) + * 动态图:节点之间的关系是会变化的。 + ![](image/2022-01-07-16-52-59.png) + + diff --git a/机器学习/殷康龙/图表示学习/5.ipynb b/机器学习/殷康龙/图表示学习/5.ipynb new file mode 100644 index 00000000..e69de29b diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-06-16-30-51.png b/机器学习/殷康龙/图表示学习/image/2022-01-06-16-30-51.png new file mode 100644 index 00000000..eb6ae9c0 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-06-16-30-51.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-06-16-37-19.png b/机器学习/殷康龙/图表示学习/image/2022-01-06-16-37-19.png new file mode 100644 index 00000000..1964c466 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-06-16-37-19.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-06-16-37-46.png b/机器学习/殷康龙/图表示学习/image/2022-01-06-16-37-46.png new file mode 100644 index 00000000..8d5a1921 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-06-16-37-46.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-06-16-38-04.png b/机器学习/殷康龙/图表示学习/image/2022-01-06-16-38-04.png new file mode 100644 index 00000000..0064e1e2 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-06-16-38-04.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-06-16-40-22.png b/机器学习/殷康龙/图表示学习/image/2022-01-06-16-40-22.png new file mode 100644 index 00000000..b9c2217b Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-06-16-40-22.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-06-17-00-43.png b/机器学习/殷康龙/图表示学习/image/2022-01-06-17-00-43.png new file mode 100644 index 00000000..a9d97162 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-06-17-00-43.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-06-17-01-01.png b/机器学习/殷康龙/图表示学习/image/2022-01-06-17-01-01.png new file mode 100644 index 00000000..a67be244 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-06-17-01-01.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-06-17-07-41.png b/机器学习/殷康龙/图表示学习/image/2022-01-06-17-07-41.png new file mode 100644 index 00000000..bbb1d05e Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-06-17-07-41.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-06-18-13-36.png b/机器学习/殷康龙/图表示学习/image/2022-01-06-18-13-36.png new file mode 100644 index 00000000..1dbf9586 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-06-18-13-36.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-06-21-33-56.png b/机器学习/殷康龙/图表示学习/image/2022-01-06-21-33-56.png new file mode 100644 index 00000000..b435779a Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-06-21-33-56.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-06-21-36-10.png b/机器学习/殷康龙/图表示学习/image/2022-01-06-21-36-10.png new file mode 100644 index 00000000..e0b1de2b Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-06-21-36-10.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-09-24-40.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-09-24-40.png new file mode 100644 index 00000000..c29a67f2 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-09-24-40.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-09-29-32.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-09-29-32.png new file mode 100644 index 00000000..bfaf346b Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-09-29-32.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-09-33-42.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-09-33-42.png new file mode 100644 index 00000000..a2e2ff4b Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-09-33-42.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-09-36-53.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-09-36-53.png new file mode 100644 index 00000000..7589c5d9 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-09-36-53.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-09-38-08.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-09-38-08.png new file mode 100644 index 00000000..72af2b06 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-09-38-08.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-09-43-39.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-09-43-39.png new file mode 100644 index 00000000..38a94136 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-09-43-39.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-09-51-45.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-09-51-45.png new file mode 100644 index 00000000..25ca7eb5 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-09-51-45.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-09-58-37.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-09-58-37.png new file mode 100644 index 00000000..9fefcfdc Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-09-58-37.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-10-07-08.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-10-07-08.png new file mode 100644 index 00000000..0a354d08 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-10-07-08.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-10-07-24.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-10-07-24.png new file mode 100644 index 00000000..9231ca72 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-10-07-24.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-10-19-19.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-10-19-19.png new file mode 100644 index 00000000..85fc44c1 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-10-19-19.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-10-22-08.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-10-22-08.png new file mode 100644 index 00000000..27351015 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-10-22-08.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-15-49-27.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-15-49-27.png new file mode 100644 index 00000000..9c1afa3c Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-15-49-27.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-15-58-46.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-15-58-46.png new file mode 100644 index 00000000..4cf7c330 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-15-58-46.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-16-01-30.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-01-30.png new file mode 100644 index 00000000..1186701f Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-01-30.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-16-04-25.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-04-25.png new file mode 100644 index 00000000..4765911a Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-04-25.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-16-06-08.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-06-08.png new file mode 100644 index 00000000..67e30a55 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-06-08.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-16-07-50.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-07-50.png new file mode 100644 index 00000000..7d891943 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-07-50.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-16-19-42.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-19-42.png new file mode 100644 index 00000000..fa464512 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-19-42.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-16-32-32.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-32-32.png new file mode 100644 index 00000000..31c61628 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-32-32.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-16-36-07.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-36-07.png new file mode 100644 index 00000000..4256c0af Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-36-07.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-16-39-34.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-39-34.png new file mode 100644 index 00000000..33f3650c Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-39-34.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-16-39-48.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-39-48.png new file mode 100644 index 00000000..d8200c9b Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-39-48.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-16-49-42.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-49-42.png new file mode 100644 index 00000000..a3b1090e Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-49-42.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-16-50-06.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-50-06.png new file mode 100644 index 00000000..a96f348f Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-50-06.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-16-50-35.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-50-35.png new file mode 100644 index 00000000..35fa666d Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-50-35.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-16-51-01.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-51-01.png new file mode 100644 index 00000000..d14d8e96 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-51-01.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-16-52-45.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-52-45.png new file mode 100644 index 00000000..9f14a114 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-52-45.png differ diff --git a/机器学习/殷康龙/图表示学习/image/2022-01-07-16-52-59.png b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-52-59.png new file mode 100644 index 00000000..30cd4ad9 Binary files /dev/null and b/机器学习/殷康龙/图表示学习/image/2022-01-07-16-52-59.png differ