0

I am trying to implement the Gamma PDF function for the integer argument. First I have implemented it with exponential terms but there were overflows, so I tried to compute the log of it, but the log goes to -inf as alpha and beta are increased. Is there any idea how to implement Gamma PDF from scratch? Here is my implementation:

log_gamma = a * np.log(b) + (a-1) * np.log(lam) - b * lam - np.log(factorial(a-1))
blazej
  • 927
  • 4
  • 11
  • 21
geradism
  • 97
  • 2
  • 14
  • Not sure if this helps but there are a number of implementations at [rosettacode.org](https://rosettacode.org/wiki/Gamma_function) you could look at. – Bill Jun 13 '21 at 21:18

1 Answers1

1

This was simply because of calculating factorial of 'a' and then applying the logarithm. Instead, we can calculate logarithm of factorial as sum of logarithms of numbers 1 to a.

geradism
  • 97
  • 2
  • 14