Advanced Computing Platform for Theoretical Physics

commit大文件会使得服务器变得不稳定,请大家尽量只commit代码,不要commit大的文件。

Commit ca716f2a authored by Lei Wang's avatar Lei Wang
Browse files

added eigenvector grad to py

parent 44c1245d
''' '''
Three different ways of computing gradient of infinite matrix product trace Different ways of computing gradient of infinite matrix product trace
Z = Tr(T*T...*T) Z = Tr(T*T...*T)
''' '''
...@@ -34,5 +34,9 @@ loss = torch.log(w[-1]) ...@@ -34,5 +34,9 @@ loss = torch.log(w[-1])
loss.backward() loss.backward()
exact_grad = ((T.grad + T.grad.t())/2) # need to symmetrize since it is an upper triangular matrix exact_grad = ((T.grad + T.grad.t())/2) # need to symmetrize since it is an upper triangular matrix
# (4) use leading eigenvector of the transfer matrix $T$
eigenvector_grad= torch.ger(v[:,-1], v[:, -1])/w[-1] # outer product of the leading eigenvector and its transpose
print ((impurity_grad-exact_grad).abs().max().item()) print ((impurity_grad-exact_grad).abs().max().item())
print ((lnZ_grad-exact_grad).abs().max().item()) print ((lnZ_grad-exact_grad).abs().max().item())
print ((eigenvector_grad-exact_grad).abs().max().item())
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment