You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote a log-likelihood function in C++ to speed up the optimization routine (#66).
We decided to try improving the R code itself before adding the dependency to Rcpp.
First we added a scalar case to the log-likelihood function, which improves the speed for the scalar case required by stats::optimize().
As this was still slower than we would like, we next implemented a function to optimize a vector of all the probability values required for the deviance calculation at the same time.
Lastly, we added memoization to the log-likelihood function for the lgamma() calls that are functions of the data (x and size, which stay constant).
Based on the code below, we chose n = 800 as the criterion to use the memoized version of the function.
x <- 1:1000 + 0.5
lgamma3 <- function(x) {
lgamma(x) + lgamma(x + 1) + lgamma(x + 2)
}
lgamma3_mem <- memoise::memoise(lgamma3)
bench::mark(
for (i in 1:250) lgamma(x) + lgamma(x + 1) + lgamma(x + 2),
for (i in 1:250) lgamma3_mem(x)
)
Currently runs very slowly. Consider using C++ code.
The text was updated successfully, but these errors were encountered: