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))

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

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


Is that the best way ?

1 Like

log is base 10 logarithm, you should use this:


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.


Does this give similar results as scipy module?