You don't need to assign---you can just return directly, so that'd
be
functions {
real generalized_inverse_gaussian_lpdf(real x, int p, real a, real b) {
return p * 0.5 * log(a / b)
- log(2 * modified_bessel_second_kind(p, sqrt(a * b)))
+ (p - 1) * log(x)
- (a * x + b / x) * 0.5;
}
}
I like to line up the additive terms on the log scale like this
to see the structure of the kernel; I'd probably also change x to y
and move the 0.5 out front, but that's even more cosmetic.
This could be rewritten to be a tiny bit more efficient by consolidating
terms inside the multiply by 0.5, but that hides the structure.
If you knew constant terms didn't matter, you could drop
* the 2* of the Bessel function
* if all of {p, a, b} are constants, the
first and econd terms can be dropped,
* if {p, x} are constants, then the third term can be dropped, and
* if {x, a, b} are constants, the fourth term can be dropped.
Our internal functions all do this, while at the same time being
careful to return the full result when used explicitly as functions
so as not to mess up things like mixtures.
- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
stan-users+...@googlegroups.com.