Skip to content

Commit

Permalink
Update pytorch_tools.py
Browse files Browse the repository at this point in the history
  • Loading branch information
davidireland3 committed Jun 7, 2022
1 parent f2852fd commit 188df78
Showing 1 changed file with 0 additions and 21 deletions.
21 changes: 0 additions & 21 deletions MVC/pytorch_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,3 @@ def _init_is_better(self, mode, min_delta, percentage):
self.is_better = lambda a, best: a > best + (
best * min_delta / 100)


def unsupervised_loss_geom(embeddings, graph_obj, num_nodes, rw_length, num_neg_examples):
# first we will get the positive embeddings
# embedding_size = embeddings.shape[1]
f = nn.LogSigmoid()
cos = nn.CosineSimilarity()
start = torch.LongTensor([i for i in range(num_nodes)]).to(device)
rw_ids = random_walk(graph_obj.edge_index[0], graph_obj.edge_index[1], start, rw_length)[:, -1]
# loss = -f(torch.sum(embeddings * embeddings[rw_ids], dim=1))
pos = cos(embeddings, embeddings[rw_ids])

# now get the negatives
neg = 0
for _ in range(num_neg_examples):
neg_ids = torch.LongTensor(np.random.randint(0, num_nodes, size=num_nodes)).to(device)
# loss -= f(torch.sum(-embeddings * embeddings[neg_ids], dim=1))
neg += cos(embeddings, embeddings[neg_ids])

loss = -pos + neg

return loss.mean()

0 comments on commit 188df78

Please sign in to comment.