chenweize1998 / fully-hyperbolic-nn

Code for paper Fully Hyperbolic Neural Networks
74 stars 12 forks source link

about Definition 1 #4

Closed tigris2021 closed 2 years ago

tigris2021 commented 2 years ago

Hello Weize,

I have a mathematical problem when learning your great paper. Could you help me understand why Bx is on a hyperboloid. I tried my best to prove it, but failed. Thank you very much!

Best

chenweize1998 commented 2 years ago

We first consider such a problem: if we have a matrix $W$ satisfying $\forall x\in\mathbb{L}, Wx\in\mathbb{L}$, then what condition should $W$ meet? Following the definition of the Lorentz model, we have

$$ \begin{align} (Wx)^T\text{diag}(-1, 1, \dots, 1)Wx&=-1\ x^TW^T\text{diag}(-1, 1, \dots, 1)Wx&=-1. \end{align} $$

Note that the equation should hold for any x on the hyperboloid, and this only happens when $W^T\text{diag}(-1, 1, \dots, 1)W=I$. You can now check when $W=B$, $B^T\text{diag}(-1, 1, \dots, 1)B=I$.

chenweize1998 commented 2 years ago

Here's a snippet that will help you verify $B^T\text{diag}(-1, 1, \dots, 1)B=I$

import torch

# The speed ratio should be less than 1, and greater than 0
speed_ratio = 0.95   
# Randomly sample a speed   
v = torch.randn(1, 3)
v = v / torch.norm(v) * speed_ratio

gamma = 1. / torch.sqrt(1 - v.norm(keepdim=True)**2)
# Compute the B matrix
matrix = torch.cat([torch.cat([gamma, -gamma*v], dim=-1), 
                    torch.cat([-gamma*v.T, 
                                torch.eye(3)+gamma*gamma/(gamma+1)*v.T@v], dim=-1)
                                ])
mid = torch.eye(4)
mid[0][0] = -1
# Calculate B^T\text{diag}(-1, 1, \dots, 1)B
result = matrix.T@mid@matrix
print(matrix.T@mid@matrix)
tigris2021 commented 2 years ago

Thank you very much for your patience, it helps me a lot. By the way, the equation $B^T\text{diag}(-1, 1, \dots, 1)B=I$ should be corrected to $B^T\text{diag}(-1, 1, \dots, 1)B=\text{diag}(-1, 1, \dots, 1)$?

chenweize1998 commented 2 years ago

Yeah it should be $\text{diag}(-1, 1, \dots, 1)$, sorry for the typo!