Closed b-steve closed 2 months ago
Here's a TMB function for the von-Mises PDF I wrote for a different project, with output that matches CircStats::dvm()
:
template<class Type>
Type dvm_stable(const Type &theta, const Type &mu, const Type &kappa, const int &give_log){
Type out;
out = kappa*(cos(theta - mu) - 1) - log(2*M_PI) - log(besselI(kappa, Type(0))/exp(kappa));
if (give_log == 0){
out = exp(out);
}
return out;
}
@b-steve If I recall correctly, we compared these and it ended up being slower when using the TMB besselI()
.
Can run some tests again if needed, otherwise I think we can close this issue.
EDIT: I think we came to the conclusion that the TMB built-in was likely slower due to it being a more accurate approximation, however our less-accurate approximation works just fine.
At the moment we use our own bessel function (top of
acreTMB.h
), which is used within the von-Mises PDF for observed bearings. My recollection is that models with observed bearings are surprisingly slow to fit, and I suspect the bessel function is the culprit.TMB now has an in-built function
besselI()
. It would be worth redefining our von-Mises PDF to use this in-built function and compare model-fitting speed.