torch / torch7

http://torch.ch
Other
9k stars 2.38k forks source link

torch.eig problem #438

Open shanlior opened 9 years ago

shanlior commented 9 years ago

Hello, I've noticed that using MAGMA's torch.eig on a CUDA device leads to different results thatn using the torch.eig on CPU. I've implemented an algorithm using eigen decomposition, and while the GPU gave me good results, I got poor results on the CPU. There are not changes in the code, just using CPU instead of GPU. I tried to run a test case.

a = torch.eye(10)
a:add(0.0001)
mat_CPU = a:clone()
mat_GPU = a:clone()
mat_GPU =  mat_GPU:cuda()
e_CPU, V_CPU = torch.eig(mat_CPU,'V')
e_GPU, V_GPU = torch.eig(mat_GPU,'V')

While the eigen-values themselves are similar, I got different eigen-vectors on both calculations. I can suggest that the GPU has some errors due to numerical issues, but what's bothering me is that the GPU implementation got good results, and the CPU got no results. It is not very likely that it was done by chance (the algorithm's results were good over few examples), so it leads me to think that there is a problem with the eigenvectors on CPU. I also tried to calculate the test case above on MATLAB, and I got different results from, but more similar to those on CPU. That just made me more confused.

I'd like to have any comments on this matter,

Thanks a lot,

Lior

jarmstrong2 commented 9 years ago

Generally, I've notice that torch.eig() only returns the eigenvalues and not the eigenvectors...

andreaskoepf commented 8 years ago

@jarmstrong2 have you tried to add the 'V' option? e.g. torch.eig(torch.rand(4,4), 'V')

jarmstrong2 commented 8 years ago

thanks for the response, i think i found that out some time ago. :)