You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was doing some testing with MixtureModels and logsumexp functions, and I happened to notice a couple of things about the logpdf/loglikelihood functions for Gamma and Inverse Gamma that had me scratching my head.
Specifically, they seem to handle variables outside the support differently. E.g.,
using Distributions
logpdf(Gamma(), 0) # 0.0, but shouldn't this be -Inf?logpdf(InverseGamma(), 0) # NaN, but again, shouldn't it be -Inf?logpdf(Gamma(), -1) # -Inf (seems correct)logpdf(InverseGamma(), -1) # Throws a domain error for "log", but shouldn't it just return -Inf?
Support for both of those distributions is supposed to be the positive reals, right? I would have expected that anything outside the support would just return -Inf for the logpdf.
[NOTE: I realize the Gamma logpdf may be correct -- I discovered that some implementations (e.g., Boost) allow a random variate of zero in the function. But in that case, perhaps the documentation might need to be updated to indicate that the range is [0, Inf), not (0, Inf)? Which is what the wikipedia link in the documentation says, and the way many (most?) implementations work, afaik.]
The same issues seem to affect the overall loglikelihood computation. E.g.,
loglikelihood(Gamma(), [1.0, 0.0]) # Gives -1.0, when I would expect -Inf, given the stated supportloglikelihood(InverseGamma(), [1.0, 0.0]) # Gives NaN, when I would expect -Infloglikelihood(Gamma(), [1.0, -1.0]) # Gives -Inf, which seems correctloglikelihood(InverseGamma(), [1.0, -1.0]) # Domain error, in "log" function
The text was updated successfully, but these errors were encountered:
I hadn't noticed that Wikipedia defines the distribution for x > 0. That surprises me and it also differs from R and Wolfram. IMO, the current behavior for Gamma is fine. Why is it a problem for the linked package?
The situation is different for InverseGamma. Here something needs to be adjusted to avoid the NaN and the exception.
I was doing some testing with MixtureModels and logsumexp functions, and I happened to notice a couple of things about the logpdf/loglikelihood functions for Gamma and Inverse Gamma that had me scratching my head.
Specifically, they seem to handle variables outside the support differently. E.g.,
Support for both of those distributions is supposed to be the positive reals, right? I would have expected that anything outside the support would just return
-Inf
for the logpdf.[NOTE: I realize the Gamma logpdf may be correct -- I discovered that some implementations (e.g., Boost) allow a random variate of zero in the function. But in that case, perhaps the documentation might need to be updated to indicate that the range is [0, Inf), not (0, Inf)? Which is what the wikipedia link in the documentation says, and the way many (most?) implementations work, afaik.]
The same issues seem to affect the overall loglikelihood computation. E.g.,
The text was updated successfully, but these errors were encountered: