syr-cn / SimSGT

[NeurIPS 2023] "Rethinking Tokenizer and Decoder in Masked Graph Modeling for Molecules"
27 stars 3 forks source link

The problem with NonParaGINConv #4

Closed wlgcqh closed 9 months ago

wlgcqh commented 9 months ago

`class NonParaGINConv(MessagePassing):

non-parametric gin

def __init__(self, eps, aggr = "add", **kwargs):
    kwargs.setdefault('aggr', aggr)
    super().__init__(**kwargs)
    self.aggr = aggr
    self.eps = eps

def forward(self, x, edge_index):
    return self.propagate(edge_index, x=x) + x * self.eps

def message(self, x_j):
    return x_j`

In the definition of GIN, the forward function should be self.propagate(edge_index, x=x) + x * (1 + self.eps)

syr-cn commented 9 months ago

Thanks for your interest. You are right, the forward function should be x * (1 + ε) according to the mathematic definition. Here we use the expression x * self.eps because we add selfloop for each molecular graph during pre-processing. For example, in line 390 of chem/dataloader.py:

edge_index, _ = add_self_loops(batch.edge_index, num_nodes = batch.x.size(0))
#add features corresponding to self-loop edges.
self_loop_attr = torch.zeros(batch.x.size(0), 2, dtype=torch.long)
self_loop_attr[:,0] = 4 #bond type for self-loop edge
edge_attr = torch.cat((batch.edge_attr, self_loop_attr), dim = 0)
batch.edge_index = edge_index
batch.edge_attr = edge_attr