-
Notifications
You must be signed in to change notification settings - Fork 86
Open
Description
This is from glmmTMB; it's lgamma() with the argument specified on the log scale.
It may be worth looking at/migrating other functions from there (e.g. dbetabinom, dbetabinom_robust).
namespace adaptive {
template<class T>
T logspace_gamma(const T &x) {
/* Tradeoff: The smaller x the better approximation *but* the higher
risk of psigamma() overflow */
if (x < -150)
return -x;
else
return lgamma(exp(x));
}
}
TMB_BIND_ATOMIC(logspace_gamma, 1, adaptive::logspace_gamma(x[0]))
template<class Type>
Type logspace_gamma(Type x) {
CppAD::vector<Type> args(2); // Last index reserved for derivative order
args[0] = x;
args[1] = 0;
return logspace_gamma(args)[0];
}
kaskr and bragef
Metadata
Metadata
Assignees
Labels
No labels