How to calculate the determinant of a variable?
maplewizard
<SCODE>import torch
import numpy as np
from torch.autograd import Variable

a = Variable(torch.randn(5,5))
np.linalg.det(a.data.numpy())
<ECODE>
AjayTalati
In fact, I want to get the gradient of the det w.r.t. each elements in the matrix.
maplewizard
Veril
It’s sad that PyTorch does not have a determinant function. This basically makes it impossible (ok, very hard) to implement Gaussian mixture density networks with a full covariance matrix.
dpernes
the happy news is that between the last post and yours, we added documentations to make the Cholesky functions easier to find, so <SCODE>torch.potrf(a).diag().prod()
<ECODE> gives you the determinant. (The functions are exactly the same as in 0.1.12, too, but be sure to use the master docs.) Best regards Thomas
tom
Yandong_Li
i can not use this function with new version of pytorch
Yandong_Li
Either use the above on Tensors or Cholesky.apply with the linked austograd Function. Best regards Thomas
tom
sure i can use this code torch.potrf(a).diag().prod() when a is a tensor but i need to do the operation to with autograd when i  call backward() function. Would you please help me solve this problems
Yandong_Li
Hi, Best regards Thomas
tom
Thanks for your help and i found that i got the square of the determinant with the code.
Yandong_Li
If anyone is looking at this thread: Note that potrf has gained differentiability in master/0.3. Best regards Thomas
tom
fehiepsi
Best regards Thomas
tom
fehiepsi
CNguyen