Skip to content

About aug.py #8

@ZhaoYuTJPU

Description

@ZhaoYuTJPU

Hello, first of all thank you very much for your excellent work.
Secondly, I have some questions about the data enhancement part of the unsupervised learning code you provided.
The code you gave only removes the discarded nodes in the data.edge_index, but not in the node attribute data.x.
I can understand that this is preventing them from messaging with undiscarded nodes, but I'm wondering if this will affect performance?
I think these discarded nodes also end up participating in pooling to generate graph-level vectors.
I look forward to your answer

`def drop_nodes_prob(data, node_score, rho):

node_num, _ = data.x.size()
_, edge_num = data.edge_index.size()
drop_num = int(node_num*(1.0-rho))

node_prob = node_score.float()
node_prob += 0.001
node_prob = np.array(node_prob)
node_prob /= node_prob.sum()

idx_nondrop = np.random.choice(node_num, node_num - drop_num, replace=False, p=node_prob)
idx_drop = np.setdiff1d(np.arange(node_num), idx_nondrop)
idx_nondrop.sort()

idx_dict = {idx_nondrop[n]: n for n in list(range(node_num - drop_num))}

edge_index = data.edge_index.numpy()

adj = torch.zeros((node_num, node_num))
adj[edge_index[0], edge_index[1]] = 1
adj[idx_drop, :] = 0
adj[:, idx_drop] = 0
edge_index = adj.nonzero().t()

data.edge_index = edge_index

return data

def drop_nodes_cp(data, node_score, rho):

node_num, _ = data.x.size()
_, edge_num = data.edge_index.size()
drop_num = int(node_num*(1.0-rho))

node_prob = node_prob = max(node_score.float()) - node_score.float()
node_prob += 0.001
node_prob = np.array(node_prob)
node_prob /= node_prob.sum()

idx_nondrop = np.random.choice(node_num, node_num - drop_num, replace=False, p=node_prob)
idx_drop = np.setdiff1d(np.arange(node_num), idx_nondrop)
idx_nondrop.sort()

idx_dict = {idx_nondrop[n]: n for n in list(range(node_num - drop_num))}

edge_index = data.edge_index.numpy()

adj = torch.zeros((node_num, node_num))
adj[edge_index[0], edge_index[1]] = 1
adj[idx_drop, :] = 0
adj[:, idx_drop] = 0
edge_index = adj.nonzero().t()

data.edge_index = edge_index

return data`

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions