RManLuo/GSNOP

Question about DGNN

inst15 opened this issue · 2 comments

inst15 commented

Hi RManLuo, thanks for your nice work! I have a question about DGNN. How can I change DGNN model of decoder? I would greatly appreciate your response!

Hi, you can change the decoder at here:

GSNOP/code/layers.py

Lines 45 to 81 in aaf6059

class EdgePredictor(torch.nn.Module):
def __init__(self, dim_in, dim_out=1):
super(EdgePredictor, self).__init__()
self.dim_in = dim_in
self.src_fc = torch.nn.Linear(dim_in, dim_in)
self.dst_fc = torch.nn.Linear(dim_in, dim_in)
self.out_fc = torch.nn.Linear(dim_in, 1)
self.droup = torch.nn.Dropout(0.2)
self.out = torch.nn.Sequential(
torch.nn.Linear(dim_in * 2, dim_in),
torch.nn.ReLU(),
torch.nn.Dropout(0.2),
torch.nn.Linear(dim_in, dim_in),
torch.nn.ReLU(),
torch.nn.Dropout(0.2),
torch.nn.Linear(dim_in, dim_out),
)
def forward(self, h, neg_samples=1):
num_edge = h.shape[0] // (neg_samples + 2)
h_src = h[:num_edge]
h_pos_dst = h[num_edge:2 * num_edge]
h_neg_dst = h[2 * num_edge:]
h_pos_edge = torch.cat([h_src, h_pos_dst], dim=-1)
if len(h.shape) > 2:
h_neg_edge = torch.cat([h_src.tile(neg_samples, 1, 1), h_neg_dst], dim=-1)
else:
h_neg_edge = torch.cat([h_src.tile(neg_samples, 1), h_neg_dst], dim=-1)
return self.out(h_pos_edge), self.out(h_neg_edge)
def predict(self, src_h, dst_h):
h_src = self.src_fc(src_h).unsqueeze(1)
h_dst = self.dst_fc(dst_h)
h_edge = torch.nn.functional.relu(h_src + h_dst)
return self.out_fc(h_edge)

inst15 commented

Thank you for your answer! But sorry, I made a mistake. My actual question is how can I change DGNN model of encoder.