Label Propagation Algorithm

本文介绍了标签传播算法(LPA),一种基于图的半监督学习方法,用于预测未标记节点的标签信息。文章详细解释了LPA的基本原理、算法流程及其在社区检测领域的应用,并提出了算法的改进措施。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 Label Propagation Algorithm

1.1 简介

标签传播算法(label propagation algorithm,LPA)是Zhu等人2002年提出的一种基于图的半监督学习方法。其基本思想是用部分已标记标签的节点预测所有未标记的节点标签信息。Usha等人于2007年首次将LPA思想用于社区检测。标签传播的半监督学习形式为

minfi=1Lfiyi2+λijL+UWijfifj2minf∑i=1L‖fi−yi‖2+λ∑ijL+UWij‖fi−fj‖2

其中, LL为带标记样本总数,U为未标记样本总数,以及
Wij=exp(d2ijσ2)=exp(Dd=1||xidxjd||2σ2)Wij=exp⁡(−dij2σ2)=exp⁡(−∑d=1D||xid−xjd||2σ2)

LPA尽力给具有较大权值的两个样本具有相同的标签。
1.2 算法

首先,我们定一个概率转移矩阵PP:

Pij=P(ij)=WijkWik

PijPij表示从节点ii跳转到j的概率。

假设有CC个标签类别,L个标记样本YLRL×CYL∈RL×CUU个未标记样本YURU×C。我们将这两个数据矩阵合为一个数据矩阵,

X=[YL;YU]X=[YL;YU]

那么,LP算法如下所示:
while($X$收敛)
{
    执行传播: $X=PX$;
    重置标签: $X_L=Y_L$;
}
1.3 改进

LPA每次迭代第2)步的时候,这部分计算者可以省略。矩阵分块就可以做到。我们可以将矩阵PP做以下划分:

P=(PLLPLUPULPUU)

相应地,算法更新为,

XUPUUXU+PULXLXU←PUUXU+PULXL

2 Community Detection by LPA

Usha等人于2007年首次将标签传播算法用于社区识别(CDLPA)。不同于第一部分的LPA,Usha等人提出的算法并没有考虑到已标注的标签信息,这导致该算法的不稳定,即CDLPA可能得到多个不同的社区划分结果。

CDLPA的具体算法如下所示:

1) Initialize the labels at all nodes in the network. For a given node xx, set Cx(0)=x;
2) t1t←1;
3) Arrange the nodes in the network in a random order and set it to XX;
4) For each xX chosen in that specific order, let Cx(t)=f(Cxi1(t),...,Cxim(t),Cxi(m+1)(t1),...,Cxik(t1))Cx(t)=f(Cxi1(t),...,Cxim(t),Cxi(m+1)(t−1),...,Cxik(t−1)). ff returns the label occurring with the highest frequency among neighbors and ties are broken uniformly randomly.
5) If every node has a label that the maximum number of their neighbors have, then stop the algorithm. Else, set tt+1 and go to 3).

算法终止条件:

If i has label Cm then dCmidCjij.If i has label Cm then diCm≥diCj∀j.

说明:
Cx(t)Cx(t): 是结点xx在时刻t的标签。
dCjidiCj: 是结点xx具有标签Cj的邻居结点个数。
Here's a possible implementation of the modified label-propagation algorithm: ``` def label_propagation2(xs: np.ndarray, ys: np.ndarray, num_iter: int = 50, k_type: str = 'rbf', bandwidth: float = 0.1) -> np.ndarray: N, D = xs.shape N, K = ys.shape assert np.all(np.logical_or(ys == 0, ys == 1)), "Labels should be strictly 0 or 1" assert np.all(np.sum(ys, axis=1) == 1), "Each row of labels should sum up to 1" # Compute the kernel matrix if k_type == 'rbf': Kmat = rbf_kernel(xs, xs, gamma=1/(2*bandwidth**2)) elif k_type == 'gate': Kmat = gate_kernel(xs, xs, bandwidth=bandwidth) elif k_type == 'triangle': Kmat = triangle_kernel(xs, xs, bandwidth=bandwidth) elif k_type == 'linear': Kmat = linear_kernel(xs, xs) else: raise ValueError("Unknown kernel type") # Propagate the labels iteratively Y = ys.copy() for _ in range(num_iter): Y = Kmat @ Y / np.sum(Kmat, axis=1, keepdims=True) Y[ys > 0] = ys[ys > 0] # Fix the labeled rows return Y ``` The main changes compared to the original implementation are the assertion checks at the beginning, which ensure that the labels are valid (binary and summing up to 1), and the modification of the label propagation step, which preserves the labeled rows (i.e., those rows with at least one nonzero label). The kernel matrix is computed using one of four possible kernel functions: the radial basis function (RBF), the gate kernel, the triangle kernel, or the linear kernel. The RBF kernel uses the gamma parameter to control the width of the Gaussian function, while the gate and triangle kernels use the bandwidth parameter to control the width of the respective kernels. The linear kernel is simply the dot product between the feature vectors.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值