Skip to content

Commit ea844b9

Browse files
committed
Re-added log-gamma.
1 parent a711792 commit ea844b9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/univariate.lisp

+7-2
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,11 @@ and c using the utility function above. "
492492
(return-from draw-standard-gamma1 (* d v))
493493
(go top)))))
494494

495+
(declaim (inline log-gamma))
496+
(defun log-gamma (alpha)
497+
"Log gamma function."
498+
(rmath:lgammafn (coerce alpha 'double-float)))
499+
495500
(define-rv r-gamma (alpha beta)
496501
(:documentation "Gamma(alpha,beta) distribution, with density proportional to x^(alpha-1) exp(-x*beta). Alpha and beta are known as shape and inverse scale (or rate) parameters, respectively.")
497502
((alpha :type internal-float :reader t)
@@ -507,7 +512,7 @@ and c using the utility function above. "
507512
ignore-constant?
508513
(with-floats (x)
509514
(- (+ (* alpha (log beta)) (* (1- alpha) (log x))) (* beta x)))
510-
(- (cl-rmath:lgammafn alpha))))
515+
(- (log-gamma alpha))))
511516
;; note that R uses scale=1/beta
512517
(cdf (x)
513518
(with-floats (x)
@@ -555,7 +560,7 @@ and c using the utility function above. "
555560
(maybe-ignore-constant
556561
ignore-constant?
557562
(- (* (- (1+ alpha)) (log x)) (/ beta x))
558-
(- (* alpha (log beta)) (cl-rmath:lgammafn alpha))))
563+
(- (* alpha (log beta)) (log-gamma alpha))))
559564
(draw (&key)
560565
(if (< alpha 1d0)
561566
(let+ ((1+alpha (1+ alpha))

0 commit comments

Comments
 (0)