Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions about the knn_graph cosine distance calculation results #62

Closed
korcys opened this issue Mar 28, 2020 · 1 comment
Closed

Questions about the knn_graph cosine distance calculation results #62

korcys opened this issue Mar 28, 2020 · 1 comment
Labels

Comments

@korcys
Copy link

korcys commented Mar 28, 2020

Hi, I got some trouble while using torch_clsuter.knn_graph.
When I run this code, it gives the following results.

import torch
from torch_cluster import knn_graph

x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]]).cuda()
batch = torch.tensor([0, 0, 0, 0]).cuda()
edge_index = knn_graph(x, k=2, batch=batch, cosine=True)
print(edge_index)

>>>tensor([[1, 2, 0, 2, 0, 1, 0, 1, 2],
          [0, 0, 1, 1, 2, 2, 3, 3, 3]], device='cuda:0')

Shouldn't cosine <[-1, 1], [1, -1]> equal -1, and cosine <[-1, 1], [1, 1]> equal 0? Why the two nearset points to point 1 are 0, 2 instead of 0, 3.
Besides, why does point 3 have three nearest neighbors instead of two?

Versions:
python 3.7.4
pytorch 1.2.0
torch-cluster 1.4.5

@github-actions
Copy link

This issue had no activity for 6 months. It will be closed in 2 weeks unless there is some new activity. Is this issue already resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant