daijiang / phyr

Functions for phylogenetic analyses
https://daijiang.github.io/phyr/
GNU General Public License v3.0
30 stars 10 forks source link

C++ version of optim #14

Closed lucasnell closed 6 years ago

lucasnell commented 6 years ago

Not going from R to C++ for every bootstrap replicate would provide a pretty significant performance boost, so is there any interest in implementing a C++ optimizer instead of using R's optim function?

I wrote some code a while ago that used the multidimensional optimizer from GSL (link here), and it worked pretty well. I used the Nelder-Mead version, but there are others available. There's also the RcppNumerical package that contains the L-BFGS algorithm, but it uses RcppEigen, which I've found very difficult to use.

I've never gotten simulated annealing to work in C++, but I also haven't explored that many options.

daijiang commented 6 years ago

Hi @lucasnell , thanks for the issue!

In terms of optim, I think both R's optim and nloptr::nlopt both were written in C. Just calling them within R will cost some time. At this moment, I still use them. I even import them into c++ first, so that I can write all functions, including the optimization, within c++. Not ideal, but I don't have the time or knowledge to figure out how to call them directly.

A potential solution may be found in this discussion: https://github.com/jyypma/nloptr/issues/39 but again, I didn't have the time to figure out yet. If you are interested in, feel free to test it out and make another pull request!

Thanks!

lucasnell commented 6 years ago

Hey @daijiang , given the issues we've had with implementing the C++ version directly, are you okay closing this?

daijiang commented 6 years ago

Sure. It has been implemented in this branch.