In pytorch, is there pdf(),logpdf () function for distribution?

I couldn’t find through the documentations. I was looking for something similar to scipy.stats such that

from scipy.stats import multivariate_normal
mvn = multivariate_normal(np.zeros(2),np.identity(2))
mvn.pdf(np.array([[0,1],[1,0]]))

I can directly pass torch.Tensor object into scipy.stats but it only return numpy object and requires me to transform back.

https://pytorch.org/docs/master/distributions.html?highlight=distributions#module-torch.distributions

It looks like probs() and log_probs() are what you’re looking for

1 Like

It seems that it now disappeared ?
So to get dist.prob(x) I am doing

dist.log_prob(x).exp()

Is that the best way ?

1 Like

log is base 10 logarithm, you should use this:

10**dist.log_prob(x)

Thank you for your answer however I am pretty sure log_prob returns the natural logarithm.
For example you can see in the code for the uniform distribution that it uses torch.log() which is the natural logarithm.

3 Likes

Does this give similar results as scipy module?