Skip to content

超图实现具有不同超边权重的超图卷积模型 #49

@wpx-1

Description

@wpx-1

您好,我想请问下。在dhg文档中,有份示例代码,是用于构造具有不同超边权重的超图卷积模型(代码附在下面)。我想问的是,这个超边特征Y是不是得先进将顶点信息传递到边后,即先调用 hg.v2e才可以拿到这个超边特征。
class HGATConv(nn.Module):
def init(
self,
in_channels: int,
out_channels: int,
bias: bool = True,
drop_rate: float = 0.5,
atten_neg_slope: float = 0.2,
):
super().init()
self.atten_dropout = nn.Dropout(drop_rate)
self.atten_act = nn.LeakyReLU(atten_neg_slope)
self.act = nn.ELU(inplace=True)
self.theta_vertex = nn.Linear(in_channels, out_channels, bias=bias)
self.theta_hyperedge = nn.Linear(in_channels, out_channels, bias=bias)
self.atten_vertex = nn.Linear(out_channels, 1, bias=False)
self.atten_hyperedge = nn.Linear(out_channels, 1, bias=False)

def forward(self, X: torch.Tensor, Y: torch.Tensor, hg: dhg.Hypergraph) -> torch.Tensor:
    X = self.theta_vertex(X)
    Y = self.theta_hyperedge(Y)
    x_for_vertex = self.atten_vertex(X)
    y_for_hyperedge = self.atten_hyperedge(Y)
    v2e_atten_score = x_for_vertex[hg.v2e_src] + y_for_hyperedge[hg.v2e_dst]
    e2v_atten_score = y_for_hyperedge[hg.e2v_src] + x_for_vertex[hg.e2v_dst]
    v2e_atten_score = self.atten_dropout(self.atten_act(v2e_atten_score).squeeze())
    e2v_atten_score = self.atten_dropout(self.atten_act(e2v_atten_score).squeeze())
    Y_ = hg.v2e(X, aggr="softmax_then_sum", v2e_weight=v2e_atten_score)
    X_ = hg.e2v(Y_, aggr="softmax_then_sum", e2v_weight=e2v_atten_score)
    X_ = self.act(X_)
    Y_ = self.act(Y_)
    return X_

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions