PoonLab / Kaphi

Kernel-embedded ABC-SMC for phylodynamic inference
GNU Affero General Public License v3.0
4 stars 2 forks source link

Native R kernel computation is slow #145

Open ArtPoon opened 5 years ago

ArtPoon commented 5 years ago

To get rid of a large number of dependencies and make it easier to maintain and extend the kernel function, I've reimplemented the kernel in R. As expected, it is slower than the original C-igraph implementation. Unfortunately it is a lot slower. We're going to have to make the parallel library a prerequisite and use mclapply as much as possible. See test.speciation.model. See also #142 and #143

ArtPoon commented 5 years ago
require(microbenchmark)
require(Kaphi)
trees1 <- trees(c(0.1, 0.2, 0.003, 0.003, 0.01, 0.01), 
                    type='bisse', n=2, max.taxa=20)
t1 <- trees1[[1]]
t2 <- trees1[[2]]
> microbenchmark(tree.kernel(t1, t2), times=10)
Unit: milliseconds
                expr      min      lq     mean   median       uq      max neval
 tree.kernel(t1, t2) 343.7733 350.649 360.0597 354.9235 356.8686 417.4822    10  

We need to knock this down at least 10-fold.

ArtPoon commented 5 years ago

About 25% of the time is spent converting the phylo object into an igraph object:

> g1 <- .tree.to.igraph(t1)
> g2 <- .tree.to.igraph(t2)
> microbenchmark(.tsk(g1, g2, lambda=0.2, rbf.var=100), times=10)
Unit: milliseconds
                                      expr      min       lq     mean   median
 .tsk(g1, g2, lambda = 0.2, rbf.var = 100) 268.2636 270.8561 281.0074 274.6949
       uq      max neval
 286.7355 320.8223    10