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

Question about poincare distance #1

Closed
ttgump opened this issue Sep 1, 2021 · 1 comment
Closed

Question about poincare distance #1

ttgump opened this issue Sep 1, 2021 · 1 comment

Comments

@ttgump
Copy link

ttgump commented Sep 1, 2021

Hi,
In the manifolds.poincare.py, the square distance is defined as (line 26-32):

`

sqrt_c = c ** 0.5
dist_c = artanh(
    sqrt_c * self.mobius_add(-p1, p2, c, dim=-1).norm(dim=-1, p=2, keepdim=False)
)
dist = dist_c * 2 / sqrt_c
return dist ** 2

`

But according to the equation (2) in the paper, the square distance in Poincare ball should be like this
`

sqrt_c = c ** 0.5
sq_norms_p1 = torch.sum(p1**2, dim=-1)
sq_norms_p2 = torch.sum(p2**2, dim=-1)
sq_d = torch.sum((p1-yp2)**2, dim=-1)
dist_c = arcosh(
    1 + 2*c*sq_d/(1+c*sq_norms_p1)/1+c*sq_norms_p2)
)
dist = dist_c / sqrt_c
return dist ** 2

`

@junhocho
Copy link
Owner

junhocho commented Sep 2, 2021

Hi, we used code related to hyperbolic space referring to HGCN.
checkout, https://github.com/HazyResearch/hgcn/blob/a526385744da25fc880f3da346e17d0fe33817f8/manifolds/poincare.py#L25

Also, check this out another implementation, https://github.com/leymir/hyperbolic-image-embeddings/blob/9e84d35497598a1ba99a3c38ea79bfaf47f8d076/hyptorch/pmath.py#L205

I guess the mobius addition make both equation equivalent.

@junhocho junhocho closed this as completed Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants