TWIRLSUnfoldingAndAttention

class dgl.nn.pytorch.conv.TWIRLSUnfoldingAndAttention(d, alp, lam, prop_step, attn_aft=-1, tau=0.2, T=-1, p=1, use_eta=False, init_att=False, attn_dropout=0, precond=True)[source]

基类: Module

描述

结合了传播和注意力。

参数 d:

图特征的维度。

类型 d:

int

参数 alp:

步长。论文中的 \(\alpha\)

类型 alp:

float

参数 lam:

图平滑项的系数。论文中的 \(\lambda\)

类型 lam:

int

参数 prop_step:

传播步数

类型 prop_step:

int

参数 attn_aft:

注意力层放置的位置。即在注意力之前进行的传播步数。如果设置为 -1,则不使用注意力。

类型 attn_aft:

int

参数 tau:

下限阈值参数。对应论文中的 \(\tau\)

类型 tau:

float

参数 T:

上限阈值参数。对应论文中的 \(T\)

类型 T:

float

参数 p:

对应论文中的 \(\rho\)

类型 p:

float

参数 use_eta:

如果为 True,则在执行注意力时为每个维度学习一个权重向量。

类型 use_eta:

bool

参数 init_att:

如果为 True,则在传播之前添加一个额外的注意力层。

类型 init_att:

bool

参数 attn_dropout:

注意力值的 dropout 率。默认值:0.0

类型 attn_dropout:

float

参数 precond:

如果为 True,则使用预处理和重新参数化的传播版本(公式 28),否则使用归一化拉普拉斯(公式 30)。

类型 precond:

bool

示例

>>> import dgl
>>> from dgl.nn import TWIRLSUnfoldingAndAttention
>>> import torch as th
>>> g = dgl.graph(([0, 1, 2, 3, 2, 5], [1, 2, 3, 4, 0, 3])).add_self_loop()
>>> feat = th.ones(6,5)
>>> prop = TWIRLSUnfoldingAndAttention(10, 1, 1, prop_step=3)
>>> res = prop(g,feat)
>>> res
tensor([[2.5000, 2.5000, 2.5000, 2.5000, 2.5000],
        [2.5000, 2.5000, 2.5000, 2.5000, 2.5000],
        [2.5000, 2.5000, 2.5000, 2.5000, 2.5000],
        [3.7656, 3.7656, 3.7656, 3.7656, 3.7656],
        [2.5217, 2.5217, 2.5217, 2.5217, 2.5217],
        [4.0000, 4.0000, 4.0000, 4.0000, 4.0000]])
forward(g, X)[source]

描述

计算传播和注意力的前向传播。

参数 g:

图。

类型 g:

DGLGraph

参数 X:

初始特征。

类型 X:

torch.Tensor

返回值:

图。

资源类型:

torch.Tensor