Skip to content

Commit

Permalink
Added timings to demonstrate efficacy of the approximations.
Browse files Browse the repository at this point in the history
This is done both in serial and with OpenMP-based parallelization.
  • Loading branch information
LTLA committed Aug 15, 2024
1 parent aacc1a2 commit 834b933
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*.o
*.swp
*.so
*.Rout
*.pdf
build/
docs/html
docs/latex
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ This eliminates near-redundant searches through the tree for each point $i$, wit
We call this approach the "leaf approximation", which is enabled through the `leaf_approximation` parameter.
Note that this only has an effect in `max_depth`-bounded trees where multiple points are assigned to a leaf node.

Some testing indicates that both approximations can significantly speed up calculation of the embeddings.
Timings are shown below in seconds, based on a mock dataset containing 50,000 points (see [`tests/R/examples/basic.R`](tests/R/examples/basic.R) for details).

|Strategy|Serial|Parallel (OpenMP, n = 4)|
|----|----|---|
|Default|136|42|
|`max_depth = 7`|85|26|
|`max_depth = 7`, `leaf_approximation = true`|46|16|

## Building projects

### CMake with `FetchContent`
Expand Down
4 changes: 4 additions & 0 deletions tests/R/examples/basic.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ par(mfrow=c(1,3))
plot(ref[,1], ref[,2], col=chosen, main="No approximation")
plot(maxd[,1], maxd[,2], col=chosen, main="Maximum depth")
plot(leaf[,1], leaf[,2], col=chosen, main="Leaf approximation")

system.time(ref <- runTsne(res$index, res$distance, init=init, num.threads=4))
system.time(maxd <- runTsne(res$index, res$distance, init=init, max.depth=7, num.threads=4))
system.time(leaf <- runTsne(res$index, res$distance, init=init, max.depth=7, leaf.approx=TRUE, num.threads=4))
2 changes: 2 additions & 0 deletions tests/R/package/src/Makevars
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
# are available.
BUILD_DIR=../../../../build/_deps
PKG_CPPFLAGS=-I${BUILD_DIR}/aarand-src/include -I${BUILD_DIR}/kmeans-src/include -I${BUILD_DIR}/powerit-src/include -I${BUILD_DIR}/knncolle-src/include -I../../../../include
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS)
1 change: 1 addition & 0 deletions tests/R/package/src/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Rcpp::NumericMatrix run_tsne(
opt.stop_lying_iter = lie_iter;
opt.mom_switch_iter = mom_iter;
opt.leaf_approximation = leaf_approx;
opt.num_threads = num_threads;

int nr = indices.nrow(), nc = indices.ncol();
qdtsne::NeighborList<int, double> neighbors(nc);
Expand Down

0 comments on commit 834b933

Please sign in to comment.