Binary files /tmp/tmpk33p8tdb/RWREQ5Dw4C/r-cran-leiden-0.3.10+dfsg/build/vignette.rds and /tmp/tmpk33p8tdb/EN2EFyJOde/r-cran-leiden-0.4.2+dfsg/build/vignette.rds differ diff -Nru r-cran-leiden-0.3.10+dfsg/debian/changelog r-cran-leiden-0.4.2+dfsg/debian/changelog --- r-cran-leiden-0.3.10+dfsg/debian/changelog 2022-05-04 07:54:23.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/debian/changelog 2022-05-17 10:18:42.000000000 +0000 @@ -1,3 +1,13 @@ +r-cran-leiden (0.4.2+dfsg-1) unstable; urgency=medium + + * New upstream version + * Standards-Version: 4.6.1 (routine-update) + * dh-update-R to update Build-Depends (routine-update) + * Needs Test-Depends r-cran-multiplex which is not available yet so + ignore this test for the moment + + -- Andreas Tille Tue, 17 May 2022 12:18:42 +0200 + r-cran-leiden (0.3.10+dfsg-1) unstable; urgency=medium * Disable reprotest diff -Nru r-cran-leiden-0.3.10+dfsg/debian/control r-cran-leiden-0.4.2+dfsg/debian/control --- r-cran-leiden-0.3.10+dfsg/debian/control 2022-05-04 07:54:23.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/debian/control 2022-05-17 10:18:42.000000000 +0000 @@ -6,14 +6,14 @@ Vcs-Browser: https://salsa.debian.org/r-pkg-team/r-cran-leiden Vcs-Git: https://salsa.debian.org/r-pkg-team/r-cran-leiden.git Homepage: https://cran.r-project.org/package=leiden -Standards-Version: 4.6.0 +Standards-Version: 4.6.1 Rules-Requires-Root: no Build-Depends: debhelper-compat (= 13), dh-r, r-base-dev, r-cran-reticulate, r-cran-matrix, - r-cran-igraph + r-cran-igraph (>= 1.2.7) Testsuite: autopkgtest-pkg-r Package: r-cran-leiden diff -Nru r-cran-leiden-0.3.10+dfsg/debian/tests/control r-cran-leiden-0.4.2+dfsg/debian/tests/control --- r-cran-leiden-0.3.10+dfsg/debian/tests/control 2022-05-04 07:54:23.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/debian/tests/control 2022-05-17 10:18:42.000000000 +0000 @@ -1,5 +1,6 @@ Tests: run-unit-test Depends: @, r-cran-testthat, r-cran-data.table, r-cran-tibble +# r-cran-multiplex # r-cran-bipartite has licensing issues (see #973872) Restrictions: allow-stderr diff -Nru r-cran-leiden-0.3.10+dfsg/debian/tests/run-unit-test r-cran-leiden-0.4.2+dfsg/debian/tests/run-unit-test --- r-cran-leiden-0.3.10+dfsg/debian/tests/run-unit-test 2022-05-04 07:54:23.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/debian/tests/run-unit-test 2022-05-17 10:18:42.000000000 +0000 @@ -17,6 +17,12 @@ exit -1 fi find . -name "*bipartite*" -delete +echo "FIXME: Do not delete tests requiring multiplex once r-cran-multiplex is available" +if apt-cache show r-cran-multiplex > /dev/null 2>/dev/null ; then + echo "Package r-cran-multiplex is available now - do not remove the test requiring it any more" + exit -1 +fi +find . -name "*multiplex*" -delete for testfile in *.R; do echo "BEGIN TEST $testfile" diff -Nru r-cran-leiden-0.3.10+dfsg/DESCRIPTION r-cran-leiden-0.4.2+dfsg/DESCRIPTION --- r-cran-leiden-0.3.10+dfsg/DESCRIPTION 2022-04-27 22:00:02.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/DESCRIPTION 2022-05-09 13:20:02.000000000 +0000 @@ -1,8 +1,8 @@ Package: leiden Type: Package Title: R Implementation of Leiden Clustering Algorithm -Version: 0.3.10 -Date: 2022-04-25 +Version: 0.4.2 +Date: 2022-05-09 Authors@R: c(person("S. Thomas", "Kelly", email = "tomkellygenetics@gmail.com", role = c("aut", "cre", "trl")), person("Vincent A.", "Traag", email = "v.a.traag@cwts.leidenuniv.nl", role = c("com"))) Description: Implements the 'Python leidenalg' module to be called in R. @@ -12,19 +12,19 @@ License: GPL-3 | file LICENSE URL: https://github.com/TomKellyGenetics/leiden BugReports: https://github.com/TomKellyGenetics/leiden/issues -Imports: methods, reticulate, Matrix, igraph +Imports: methods, reticulate, Matrix, igraph (>= 1.2.7) Encoding: UTF-8 -RoxygenNote: 7.1.1 +RoxygenNote: 7.1.2 Suggests: bipartite, covr, data.table, devtools, graphsim, knitr, - multiplex, multinet, markdown, network, RColorBrewer, - rmarkdown, spelling, testthat, tibble + markdown, multiplex, multinet, network, qpdf, RColorBrewer, + remotes, rmarkdown, spelling, testthat, tibble Language: en-US VignetteBuilder: knitr Collate: 'find_partition.R' 'leiden.R' 'py_objects.R' NeedsCompilation: no -Packaged: 2022-04-27 21:23:22 UTC; tom +Packaged: 2022-05-09 12:34:44 UTC; kelly-t Author: S. Thomas Kelly [aut, cre, trl], Vincent A. Traag [com] Maintainer: S. Thomas Kelly Repository: CRAN -Date/Publication: 2022-04-27 22:00:02 UTC +Date/Publication: 2022-05-09 13:20:02 UTC diff -Nru r-cran-leiden-0.3.10+dfsg/inst/CITATION r-cran-leiden-0.4.2+dfsg/inst/CITATION --- r-cran-leiden-0.3.10+dfsg/inst/CITATION 2022-04-25 07:52:27.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/inst/CITATION 2022-05-09 12:32:13.000000000 +0000 @@ -4,11 +4,14 @@ title = "leiden: R implementation of the Leiden algorithm", author = personList(as.person("S. Thomas Kelly")), year = "2022", - note = "R package version 0.3.10", + note = "R package version 0.4.2", url = "https://github.com/TomKellyGenetics/leiden", textVersion = - paste("S. Thomas Kelly (2022). leiden: R implementation of the Leiden algorithm. R package version 0.3.10", + paste("S. Thomas Kelly (2020). leiden: R implementation of the Leiden algorithm. R package version 0.4.2", + year = "2022", + note = "R package version 0.4.2", + url = "https://github.com/TomKellyGenetics/leiden", "https://github.com/TomKellyGenetics/leiden") ) diff -Nru r-cran-leiden-0.3.10+dfsg/inst/doc/benchmarking.R r-cran-leiden-0.4.2+dfsg/inst/doc/benchmarking.R --- r-cran-leiden-0.3.10+dfsg/inst/doc/benchmarking.R 2022-04-27 21:22:58.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/inst/doc/benchmarking.R 2022-05-09 12:34:38.000000000 +0000 @@ -114,7 +114,7 @@ summary(G) ## ---- eval=module------------------------------------------------------------- -partition <- leiden(G, "ModularityVertexPartition") +partition <- leiden(G, "ModularityVertexPartition", legacy = TRUE) partition ## ---- eval=module------------------------------------------------------------- @@ -128,7 +128,7 @@ plot(G, vertex.color = node.cols, layout=layout_with_kk) ## ---- eval=module------------------------------------------------------------- -partition <- leiden(G, "CPMVertexPartition", resolution_parameter = 0.5) +partition <- leiden(G, "CPMVertexPartition", resolution_parameter = 0.05, legacy = TRUE) partition ## ---- eval=module------------------------------------------------------------- @@ -149,12 +149,42 @@ node.cols <- brewer.pal(max(c(3, partition)),"Pastel1")[partition] plot(G, vertex.color = node.cols, layout=layout_with_kk) +## ---- eval=module------------------------------------------------------------- +G <- as.undirected(G, mode = "each") +is.directed(G) +partition <- leiden(G, "ModularityVertexPartition", legacy = FALSE) +partition + +## ---- eval=module------------------------------------------------------------- +table(partition) + +## ----------------------------------------------------------------------------- +library("igraph") +library("reticulate") +library("RColorBrewer") +node.cols <- brewer.pal(max(c(3, partition)),"Pastel1")[partition] +plot(G, vertex.color = node.cols, layout=layout_with_kk) + +## ---- eval=module------------------------------------------------------------- +partition <- membership(cluster_leiden(G, objective_function = "modularity")) +partition +table(partition) + +## ---- eval=module------------------------------------------------------------- +partition <- leiden(G, "CPMVertexPartition", resolution_parameter = 0.1, legacy = FALSE) +partition +table(partition) + +## ---- eval=module------------------------------------------------------------- +node.cols <- brewer.pal(max(c(3, partition)),"Pastel1")[partition] +plot(G, vertex.color = node.cols, layout=layout_with_kk) + ## ---- cache=TRUE, , eval=module----------------------------------------------- G <- graph.famous('Zachary') summary(G) start <- Sys.time() for(ii in 1:100){ - partition = leiden(G, "ModularityVertexPartition") + partition <- leiden(G, "ModularityVertexPartition", legacy = TRUE) } end <- Sys.time() table(partition) @@ -458,41 +488,119 @@ print(paste(c("total:", timing, "seconds"), collapse = " ")) partition +## ----------------------------------------------------------------------------- +time9 <- Sys.time() +partition <- membership(cluster_leiden(G, objective_function = "modularity")) +partition +table(partition) +time10 <- Sys.time() +timing = difftime(time10, time9)[[1]] +print(paste(c("run with igraph:", timing, "seconds"), collapse = " ")) + +## ---- eval=module------------------------------------------------------------- +time11 <- Sys.time() +partition <- leiden(G, "ModularityVertexPartition", legacy = FALSE) +partition +table(partition) +time12 <- Sys.time() +timing = difftime(time12, time11)[[1]] +print(paste(c("run with leiden in igraph:", timing, "seconds"), collapse = " ")) + +## ---- eval=module------------------------------------------------------------- +time13 <- Sys.time() +partition <- leiden(G, "ModularityVertexPartition", legacy = TRUE) +partition +table(partition) +time14 <- Sys.time() +timing = difftime(time14, time13)[[1]] +print(paste(c("run with leiden with reticulate:", timing, "seconds"), collapse = " ")) + +## ---- eval=module------------------------------------------------------------- +library("Matrix") +adj_mat <- as(as_adjacency_matrix(G), Class = "dgCMatrix") +time15 <- Sys.time() +partition <- leiden(adj_mat, "ModularityVertexPartition", legacy = TRUE) +partition +table(partition) +time16 <- Sys.time() +timing = difftime(time16, time15)[[1]] +print(paste(c("run with leiden with reticulate:", timing, "seconds"), collapse = " ")) + +## ---- eval=module------------------------------------------------------------- +adj_mat <- as_adjacency_matrix(G) +time15 <- Sys.time() +partition <- leiden(adj_mat, "ModularityVertexPartition", legacy = TRUE) +partition +table(partition) +time16 <- Sys.time() +timing = difftime(time16, time15)[[1]] +print(paste(c("run with leiden with reticulate:", timing, "seconds"), collapse = " ")) + +## ---- cache=TRUE, , eval=module----------------------------------------------- +G <- graph.famous('Zachary') +summary(G) +start <- Sys.time() +for(ii in 1:100){ + partition <- membership(cluster_leiden(G, objective_function = "modularity")) +} +end <- Sys.time() +table(partition) +igraph_time = difftime(end, start)[[1]] +print(paste(c("leiden time:", igraph_time, "seconds"), collapse = " ")) + +## ---- cache=TRUE, , eval=module----------------------------------------------- +G <- graph.famous('Zachary') +summary(G) +start <- Sys.time() +for(ii in 1:100){ + partition <- leiden(G, "ModularityVertexPartition", legacy = FALSE) +} +end <- Sys.time() +table(partition) +R_cigraph_time = difftime(end, start)[[1]] +print(paste(c("leiden time:", R_cigraph_time, "seconds"), collapse = " ")) + ## ---- fig.align = 'center', fig.height = 3, fig.width = 6, fig.keep = 'last', eval=module---- -barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, - R_mat_time, R_sparse_mat_time), - names = c("Python (shell)", "Python (Rmd)", "Reticulate", "R igraph", +barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, + R_cigraph_time, igraph_time, R_mat_time, R_sparse_mat_time), + names = c("Python (shell)", "Python (Rmd)", "Reticulate", + "R igraph reticulate", "R igraph (C)", "R igraph cluster_leiden", "R matrix","R dgCMatrix"), col = brewer.pal(9,"Pastel1"), las = 2, srt = 45, ylab = "time (seconds)", main = "benchmarking 100 computations") abline(h=0) ## ---- fig.align = 'center', fig.height = 3, fig.width = 6, fig.keep = 'last', eval=module---- -barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, R_mat_time+R_mat_cast_time, +barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, + R_cigraph_time, igraph_time, R_mat_time+R_mat_cast_time, R_sparse_mat_time+R_sparse_mat_cast_time), - names = c("Python (shell)", "Python (Rmd)", "Reticulate", "R igraph", + names = c("Python (shell)", "Python (Rmd)", "Reticulate", + "R igraph reticulate", "R igraph (C)", "R igraph cluster_leiden", "R matrix","R dgCMatrix"), col = "grey80", las = 2, srt = 45, ylab = "time (seconds)", main = "benchmarking 100 computations") barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, - R_mat_time, R_sparse_mat_time), - names = c("Python (shell)", "Python (Rmd)", "Reticulate", "R igraph", - "R matrix","R dgCMatrix"), + R_cigraph_time, igraph_time, R_mat_time, R_sparse_mat_time), + names = c("Python (shell)", "Python (Rmd)", "Reticulate", + "R igraph reticulate", "R igraph (C)", "R igraph cluster_leiden", + "R matrix","R dgCMatrix"), col = brewer.pal(9,"Pastel1"), las = 2, srt = 45, ylab = "time (seconds)", main = "benchmarking 100 computations", add = TRUE) abline(h=0) ## ---- fig.align = 'center', fig.height = 3, fig.width = 6, fig.keep = 'last', eval=module---- R_graph_create_time = difftime(time4, time3)[[1]] -barplot(c(bash_py_time, py$py_time+reticulate_create_time*100, reticulate_time+reticulate_create_time*100, R_graph_time+R_graph_create_time*100, R_mat_time, - R_sparse_mat_time), - names = c("Python (shell)", "Python (Rmd)", "Reticulate", "R igraph", +barplot(c(bash_py_time, py$py_time+reticulate_create_time*100, reticulate_time+reticulate_create_time*100, R_graph_time+R_graph_create_time*100, + R_cigraph_time, igraph_time, R_mat_time, R_sparse_mat_time), + names = c("Python (shell)", "Python (Rmd)", "Reticulate", + "R igraph reticulate", "R igraph (C)", "R igraph cluster_leiden", "R matrix","R dgCMatrix"), col = "grey80", las = 2, srt = 45, ylab = "time (seconds)", main = "benchmarking 100 computations") -barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, - R_mat_time, R_sparse_mat_time), - names = c("Python (shell)", "Python (Rmd)", "Reticulate", "R igraph", +barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, + R_cigraph_time, igraph_time, R_mat_time, R_sparse_mat_time), + names = c("Python (shell)", "Python (Rmd)", "Reticulate", + "R igraph reticulate", "R igraph (C)", "R igraph cluster_leiden", "R matrix","R dgCMatrix"), col = brewer.pal(9,"Pastel1"), las = 2, srt = 45, ylab = "time (seconds)", main = "benchmarking 100 computations", add = TRUE) diff -Nru r-cran-leiden-0.3.10+dfsg/inst/doc/benchmarking.Rmd r-cran-leiden-0.4.2+dfsg/inst/doc/benchmarking.Rmd --- r-cran-leiden-0.3.10+dfsg/inst/doc/benchmarking.Rmd 2022-04-25 11:50:37.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/inst/doc/benchmarking.Rmd 2022-05-09 12:32:13.000000000 +0000 @@ -280,7 +280,7 @@ Note that these require the Python version as a dependency. -### Running in R +### Running in R via reticulate and igraph We can reproduce these by running the Leiden algorithm in R using the functions in the leiden package. @@ -304,8 +304,13 @@ G <- graph.famous("Zachary") summary(G) ``` + +#### Calling python in R via reticulate + +Here run "legacy" mode to call "leidenalg" in python with the R reticulate package. + ```{r, eval=module} -partition <- leiden(G, "ModularityVertexPartition") +partition <- leiden(G, "ModularityVertexPartition", legacy = TRUE) partition ``` @@ -326,8 +331,8 @@ We can reproduce passing arguments in this manner as well. -```{r, eval=module} -partition <- leiden(G, "CPMVertexPartition", resolution_parameter = 0.5) +````{r, eval=module} +partition <- leiden(G, "CPMVertexPartition", resolution_parameter = 0.05, legacy = TRUE) partition ``` @@ -361,6 +366,55 @@ plot(G, vertex.color = node.cols, layout=layout_with_kk) ``` +#### Calling C in R with igraph + +We can improve performance for undirected graphs for Modularity and CPM cost functions by calling C in igraph. + +```{r, eval=module} +G <- as.undirected(G, mode = "each") +is.directed(G) +partition <- leiden(G, "ModularityVertexPartition", legacy = FALSE) +partition +``` + +```{r, eval=module} +table(partition) +``` + +We can plot the result in R to show it in the network. This reproduces the example in the Python leidenalg documentation. + +```{r} +library("igraph") +library("reticulate") +library("RColorBrewer") +node.cols <- brewer.pal(max(c(3, partition)),"Pastel1")[partition] +plot(G, vertex.color = node.cols, layout=layout_with_kk) +``` + +We check here that it returns the same results as in igraph. + +````{r, eval=module} +partition <- membership(cluster_leiden(G, objective_function = "modularity")) +partition +table(partition) +``` + +We can also run CPM cost functions. + +````{r, eval=module} +partition <- leiden(G, "CPMVertexPartition", resolution_parameter = 0.1, legacy = FALSE) +partition +table(partition) +``` + +We can plot the result in R to show it in the network. This reproduces the example in the Python leidenalg documentation. + +```{r, eval=module} +node.cols <- brewer.pal(max(c(3, partition)),"Pastel1")[partition] +plot(G, vertex.color = node.cols, layout=layout_with_kk) +``` + + #### Benchmarking the R version with reticulate Now we can time how long the computation of the algorithm takes (for 1000 runs) calling with R on a graph object: @@ -370,7 +424,7 @@ summary(G) start <- Sys.time() for(ii in 1:100){ - partition = leiden(G, "ModularityVertexPartition") + partition <- leiden(G, "ModularityVertexPartition", legacy = TRUE) } end <- Sys.time() table(partition) @@ -378,7 +432,7 @@ print(paste(c("leiden time:", R_graph_time, "seconds"), collapse = " ")) ``` -We can see that the R implementation does not perform as well as the Python version but it is convenient for R users. Calling from a graph object avoids casting to a dense adjacency matrix which reduces memory load for large graph objects. +We can see that the R reticualte implementation does not perform as well as the Python version but it is convenient for R users. Calling from a graph object avoids casting to a dense adjacency matrix which reduces memory load for large graph objects. We can see that calling leiden in R on an adjacency matrix has faster performance but it does require more memory. For example, on a dense adjacency matrix: @@ -704,14 +758,108 @@ Here we can see that the current approach to pass adjacency matrices to Python and generate graphs in Python is more efficient for a dense matrix than computing the graph in R. Therefore the leiden.matrix method will not call the leiden.igraph method and they will remain distinct. +#### Calling C in R with igraph + +Here we compare calling modularity clustering in igraph (R and C) to calling Python via reticulate. Note this is only available for undirected graphs with modularity or CPM. Calling igraph in R does not have a python dependency. + +```{r} +time9 <- Sys.time() +partition <- membership(cluster_leiden(G, objective_function = "modularity")) +partition +table(partition) +time10 <- Sys.time() +timing = difftime(time10, time9)[[1]] +print(paste(c("run with igraph:", timing, "seconds"), collapse = " ")) +``` + +The updated leiden package calls this implementation when available. We can see this is considerably faster and may be faster than call leidenalg in Python. + +```{r, eval=module} +time11 <- Sys.time() +partition <- leiden(G, "ModularityVertexPartition", legacy = FALSE) +partition +table(partition) +time12 <- Sys.time() +timing = difftime(time12, time11)[[1]] +print(paste(c("run with leiden in igraph:", timing, "seconds"), collapse = " ")) +``` + +This is considerably faster than the reticulate implementation, especially for larger matrices. + +```{r, eval=module} +time13 <- Sys.time() +partition <- leiden(G, "ModularityVertexPartition", legacy = TRUE) +partition +table(partition) +time14 <- Sys.time() +timing = difftime(time14, time13)[[1]] +print(paste(c("run with leiden with reticulate:", timing, "seconds"), collapse = " ")) +``` + +Matrix methods in R are significantly slower than the updated igraph version. + +```{r, eval=module} +library("Matrix") +adj_mat <- as(as_adjacency_matrix(G), Class = "dgCMatrix") +time15 <- Sys.time() +partition <- leiden(adj_mat, "ModularityVertexPartition", legacy = TRUE) +partition +table(partition) +time16 <- Sys.time() +timing = difftime(time16, time15)[[1]] +print(paste(c("run with leiden with reticulate:", timing, "seconds"), collapse = " ")) +``` + +```{r, eval=module} +adj_mat <- as_adjacency_matrix(G) +time15 <- Sys.time() +partition <- leiden(adj_mat, "ModularityVertexPartition", legacy = TRUE) +partition +table(partition) +time16 <- Sys.time() +timing = difftime(time16, time15)[[1]] +print(paste(c("run with leiden with reticulate:", timing, "seconds"), collapse = " ")) +``` + +#### Benchmarking C in R with igraph + +For comparison with other methods we compute multiple iterations. + +```{r, cache=TRUE, , eval=module} +G <- graph.famous('Zachary') +summary(G) +start <- Sys.time() +for(ii in 1:100){ + partition <- membership(cluster_leiden(G, objective_function = "modularity")) +} +end <- Sys.time() +table(partition) +igraph_time = difftime(end, start)[[1]] +print(paste(c("leiden time:", igraph_time, "seconds"), collapse = " ")) +``` + +```{r, cache=TRUE, , eval=module} +G <- graph.famous('Zachary') +summary(G) +start <- Sys.time() +for(ii in 1:100){ + partition <- leiden(G, "ModularityVertexPartition", legacy = FALSE) +} +end <- Sys.time() +table(partition) +R_cigraph_time = difftime(end, start)[[1]] +print(paste(c("leiden time:", R_cigraph_time, "seconds"), collapse = " ")) +``` + ## Summary Here we compare the compute time for the Zachary datasets between each method for computing paritions from the leiden clustering algorithm in R or Python. ```{r, fig.align = 'center', fig.height = 3, fig.width = 6, fig.keep = 'last', eval=module} -barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, - R_mat_time, R_sparse_mat_time), - names = c("Python (shell)", "Python (Rmd)", "Reticulate", "R igraph", +barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, + R_cigraph_time, igraph_time, R_mat_time, R_sparse_mat_time), + names = c("Python (shell)", "Python (Rmd)", "Reticulate", + "R igraph reticulate", "R igraph (C)", "R igraph cluster_leiden", "R matrix","R dgCMatrix"), col = brewer.pal(9,"Pastel1"), las = 2, srt = 45, ylab = "time (seconds)", main = "benchmarking 100 computations") @@ -721,16 +869,19 @@ If we account for time to cast matrices from graph objects. Then these are the time taken to compute partitions from a graph in R. ```{r, fig.align = 'center', fig.height = 3, fig.width = 6, fig.keep = 'last', eval=module} -barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, R_mat_time+R_mat_cast_time, +barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, + R_cigraph_time, igraph_time, R_mat_time+R_mat_cast_time, R_sparse_mat_time+R_sparse_mat_cast_time), - names = c("Python (shell)", "Python (Rmd)", "Reticulate", "R igraph", + names = c("Python (shell)", "Python (Rmd)", "Reticulate", + "R igraph reticulate", "R igraph (C)", "R igraph cluster_leiden", "R matrix","R dgCMatrix"), col = "grey80", las = 2, srt = 45, ylab = "time (seconds)", main = "benchmarking 100 computations") barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, - R_mat_time, R_sparse_mat_time), - names = c("Python (shell)", "Python (Rmd)", "Reticulate", "R igraph", - "R matrix","R dgCMatrix"), + R_cigraph_time, igraph_time, R_mat_time, R_sparse_mat_time), + names = c("Python (shell)", "Python (Rmd)", "Reticulate", + "R igraph reticulate", "R igraph (C)", "R igraph cluster_leiden", + "R matrix","R dgCMatrix"), col = brewer.pal(9,"Pastel1"), las = 2, srt = 45, ylab = "time (seconds)", main = "benchmarking 100 computations", add = TRUE) abline(h=0) @@ -740,15 +891,17 @@ ```{r, fig.align = 'center', fig.height = 3, fig.width = 6, fig.keep = 'last', eval=module} R_graph_create_time = difftime(time4, time3)[[1]] -barplot(c(bash_py_time, py$py_time+reticulate_create_time*100, reticulate_time+reticulate_create_time*100, R_graph_time+R_graph_create_time*100, R_mat_time, - R_sparse_mat_time), - names = c("Python (shell)", "Python (Rmd)", "Reticulate", "R igraph", +barplot(c(bash_py_time, py$py_time+reticulate_create_time*100, reticulate_time+reticulate_create_time*100, R_graph_time+R_graph_create_time*100, + R_cigraph_time, igraph_time, R_mat_time, R_sparse_mat_time), + names = c("Python (shell)", "Python (Rmd)", "Reticulate", + "R igraph reticulate", "R igraph (C)", "R igraph cluster_leiden", "R matrix","R dgCMatrix"), col = "grey80", las = 2, srt = 45, ylab = "time (seconds)", main = "benchmarking 100 computations") -barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, - R_mat_time, R_sparse_mat_time), - names = c("Python (shell)", "Python (Rmd)", "Reticulate", "R igraph", +barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, + R_cigraph_time, igraph_time, R_mat_time, R_sparse_mat_time), + names = c("Python (shell)", "Python (Rmd)", "Reticulate", + "R igraph reticulate", "R igraph (C)", "R igraph cluster_leiden", "R matrix","R dgCMatrix"), col = brewer.pal(9,"Pastel1"), las = 2, srt = 45, ylab = "time (seconds)", main = "benchmarking 100 computations", add = TRUE) diff -Nru r-cran-leiden-0.3.10+dfsg/inst/doc/run_leiden.R r-cran-leiden-0.4.2+dfsg/inst/doc/run_leiden.R --- r-cran-leiden-0.3.10+dfsg/inst/doc/run_leiden.R 2022-04-27 21:23:11.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/inst/doc/run_leiden.R 2022-05-09 12:34:42.000000000 +0000 @@ -86,7 +86,7 @@ ## ---- warning=FALSE, message=FALSE, eval=module----------------------------------------------------------------------- partition <- leiden(adjacency_matrix, max_comm_size = 12) -node.cols <- brewer.pal(max(c(10, partition)),"Pastel1")[partition] +node.cols <- brewer.pal(min(c(9, partition)),"Pastel1")[partition] plot(graph_object, vertex.color = node.cols) ## ---- warning=FALSE, message=FALSE, eval=module----------------------------------------------------------------------- diff -Nru r-cran-leiden-0.3.10+dfsg/inst/doc/run_leiden.Rmd r-cran-leiden-0.4.2+dfsg/inst/doc/run_leiden.Rmd --- r-cran-leiden-0.3.10+dfsg/inst/doc/run_leiden.Rmd 2021-05-24 04:25:32.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/inst/doc/run_leiden.Rmd 2022-05-09 12:32:13.000000000 +0000 @@ -157,7 +157,7 @@ ```{r, warning=FALSE, message=FALSE, eval=module} partition <- leiden(adjacency_matrix, max_comm_size = 12) -node.cols <- brewer.pal(max(c(10, partition)),"Pastel1")[partition] +node.cols <- brewer.pal(min(c(9, partition)),"Pastel1")[partition] plot(graph_object, vertex.color = node.cols) ``` diff -Nru r-cran-leiden-0.3.10+dfsg/inst/doc/run_multiplex.R r-cran-leiden-0.4.2+dfsg/inst/doc/run_multiplex.R --- r-cran-leiden-0.3.10+dfsg/inst/doc/run_multiplex.R 2022-04-27 21:23:20.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/inst/doc/run_multiplex.R 2022-05-09 12:34:44.000000000 +0000 @@ -256,13 +256,13 @@ ## ---- warning=FALSE, message=FALSE, fig.align='center', out.width="80%",fig.height = 6, fig.width = 6, fig.retina=1.5---- library("graphsim") library("RColorBrewer") -node.cols <- brewer.pal(max(c(10, partition)),"Pastel1")[partition] +node.cols <- brewer.pal(min(c(9, partition)),"Pastel1")[partition] par(mfrow = c(2, 3)) -plot_directed(multiplex_graph$lunch, main = "lunch", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$work, main = "work", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$facebook, main = "facebook", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$leisure, main = "leisure", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$coauthor, main = "coauthor", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$lunch, main = "lunch", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$work, main = "work", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$facebook, main = "facebook", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$leisure, main = "leisure", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$coauthor, main = "coauthor", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) ## ---- eval=module----------------------------------------------------------------------------------------------------- partition <- leiden(multiplex_matrix, @@ -292,13 +292,13 @@ ## ---- warning=FALSE, message=FALSE, fig.align='center', out.width="80%",fig.height = 6, fig.width = 6, fig.retina=1.5---- library("graphsim") library("RColorBrewer") -node.cols <- brewer.pal(max(c(10, partition)),"Pastel1")[partition] +node.cols <- brewer.pal(min(c(9, partition)),"Pastel1")[partition] par(mfrow = c(2, 3)) -plot_directed(multiplex_graph$lunch, main = "lunch", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$work, main = "work", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$facebook, main = "facebook", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$leisure, main = "leisure", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$coauthor, main = "coauthor", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$lunch, main = "lunch", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$work, main = "work", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$facebook, main = "facebook", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$leisure, main = "leisure", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$coauthor, main = "coauthor", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) ## ---- eval=module----------------------------------------------------------------------------------------------------- partition <- leiden(multiplex_graph, partition_type = "CPMVertexPartition", max_comm_size = 8, resolution_parameter = 0.1, seed = 42) @@ -315,13 +315,13 @@ ## ---- warning=FALSE, message=FALSE, fig.align='center', out.width="80%",fig.height = 6, fig.width = 6, fig.retina=1.5---- library("graphsim") library("RColorBrewer") -node.cols <- brewer.pal(max(c(10, partition)),"Pastel1")[partition] +node.cols <- brewer.pal(min(c(9, partition)),"Pastel1")[partition] par(mfrow = c(2, 3)) -plot_directed(multiplex_graph$lunch, main = "lunch", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$work, main = "work", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$facebook, main = "facebook", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$leisure, main = "leisure", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$coauthor, main = "coauthor", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$lunch, main = "lunch", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$work, main = "work", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$facebook, main = "facebook", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$leisure, main = "leisure", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$coauthor, main = "coauthor", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) ## ---- eval=module----------------------------------------------------------------------------------------------------- partition <- leiden(multiplex_graph, partition_type = "ModularityVertexPartition", resolution_parameter = 0.02, seed = 42) @@ -339,9 +339,9 @@ library("RColorBrewer") node.cols <- brewer.pal(max(c(8, partition)),"Pastel1")[partition] par(mfrow = c(2, 3)) -plot_directed(multiplex_graph$lunch, main = "lunch", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$work, main = "work", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$facebook, main = "facebook", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$leisure, main = "leisure", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$coauthor, main = "coauthor", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$lunch, main = "lunch", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$work, main = "work", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$facebook, main = "facebook", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$leisure, main = "leisure", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$coauthor, main = "coauthor", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) diff -Nru r-cran-leiden-0.3.10+dfsg/inst/doc/run_multiplex.Rmd r-cran-leiden-0.4.2+dfsg/inst/doc/run_multiplex.Rmd --- r-cran-leiden-0.3.10+dfsg/inst/doc/run_multiplex.Rmd 2022-04-25 11:51:03.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/inst/doc/run_multiplex.Rmd 2022-05-09 12:32:13.000000000 +0000 @@ -305,13 +305,13 @@ ```{r, warning=FALSE, message=FALSE, fig.align='center', out.width="80%",fig.height = 6, fig.width = 6, fig.retina=1.5} library("graphsim") library("RColorBrewer") -node.cols <- brewer.pal(max(c(10, partition)),"Pastel1")[partition] +node.cols <- brewer.pal(min(c(9, partition)),"Pastel1")[partition] par(mfrow = c(2, 3)) -plot_directed(multiplex_graph$lunch, main = "lunch", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$work, main = "work", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$facebook, main = "facebook", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$leisure, main = "leisure", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$coauthor, main = "coauthor", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$lunch, main = "lunch", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$work, main = "work", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$facebook, main = "facebook", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$leisure, main = "leisure", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$coauthor, main = "coauthor", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) ``` This can also be run on a list of adjacency matrices giving the same results. @@ -354,13 +354,13 @@ ```{r, warning=FALSE, message=FALSE, fig.align='center', out.width="80%",fig.height = 6, fig.width = 6, fig.retina=1.5} library("graphsim") library("RColorBrewer") -node.cols <- brewer.pal(max(c(10, partition)),"Pastel1")[partition] +node.cols <- brewer.pal(min(c(9, partition)),"Pastel1")[partition] par(mfrow = c(2, 3)) -plot_directed(multiplex_graph$lunch, main = "lunch", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$work, main = "work", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$facebook, main = "facebook", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$leisure, main = "leisure", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$coauthor, main = "coauthor", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$lunch, main = "lunch", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$work, main = "work", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$facebook, main = "facebook", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$leisure, main = "leisure", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$coauthor, main = "coauthor", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) ``` ### Fine-tuning with maximum community size @@ -385,13 +385,13 @@ ```{r, warning=FALSE, message=FALSE, fig.align='center', out.width="80%",fig.height = 6, fig.width = 6, fig.retina=1.5} library("graphsim") library("RColorBrewer") -node.cols <- brewer.pal(max(c(10, partition)),"Pastel1")[partition] +node.cols <- brewer.pal(min(c(9, partition)),"Pastel1")[partition] par(mfrow = c(2, 3)) -plot_directed(multiplex_graph$lunch, main = "lunch", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$work, main = "work", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$facebook, main = "facebook", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$leisure, main = "leisure", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$coauthor, main = "coauthor", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$lunch, main = "lunch", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$work, main = "work", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$facebook, main = "facebook", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$leisure, main = "leisure", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$coauthor, main = "coauthor", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) ``` ### Multiplex cost functions @@ -420,10 +420,10 @@ library("RColorBrewer") node.cols <- brewer.pal(max(c(8, partition)),"Pastel1")[partition] par(mfrow = c(2, 3)) -plot_directed(multiplex_graph$lunch, main = "lunch", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$work, main = "work", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$facebook, main = "facebook", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$leisure, main = "leisure", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$coauthor, main = "coauthor", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$lunch, main = "lunch", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$work, main = "work", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$facebook, main = "facebook", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$leisure, main = "leisure", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$coauthor, main = "coauthor", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) ``` diff -Nru r-cran-leiden-0.3.10+dfsg/man/leiden.Rd r-cran-leiden-0.4.2+dfsg/man/leiden.Rd --- r-cran-leiden-0.3.10+dfsg/man/leiden.Rd 2022-04-25 06:44:47.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/man/leiden.Rd 2022-05-09 12:32:13.000000000 +0000 @@ -18,7 +18,8 @@ n_iterations = 2L, max_comm_size = 0L, degree_as_node_size = FALSE, - laplacian = FALSE + laplacian = FALSE, + legacy = FALSE ) } \arguments{ @@ -39,6 +40,8 @@ \item{degree_as_node_size}{(defaults to FALSE). If True use degree as node size instead of 1, to mimic modularity for Bipartite graphs.} \item{laplacian}{(defaults to FALSE). Derive edge weights from the Laplacian matrix.} + +\item{legacy}{(defaults to FALSE). Force calling python implementation via reticulate. Default behaviour is calling cluster_leiden in igraph with Modularity (for undirected graphs) and CPM cost functions.} } \value{ A partition of clusters as a vector of integers diff -Nru r-cran-leiden-0.3.10+dfsg/MD5 r-cran-leiden-0.4.2+dfsg/MD5 --- r-cran-leiden-0.3.10+dfsg/MD5 2022-04-27 22:00:02.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/MD5 2022-05-09 13:20:02.000000000 +0000 @@ -1,39 +1,39 @@ -a45dbe5672eb7cd004cc351ca23c6a5f *DESCRIPTION +1c39b1ad9e8499306af7d51b7a18c65f *DESCRIPTION 84dcc94da3adb52b53ae4fa38fe49e5d *LICENSE -e1e2ba67990be7b63bc52329e505b833 *NAMESPACE -ecb38ba236f650fb95ab9e7f450d3b03 *NEWS.md -abd9a1428a40c56a57e3efc227d41e63 *R/find_partition.R -75238aada0ce651a55fc3eea19f95337 *R/leiden.R +394c3debbdc3de0f4251a0d5f2321630 *NAMESPACE +e9e1b5b8705bc9ee46ce996d25f33fb1 *NEWS.md +50c1221b1176db3d5b47eac421efd104 *R/find_partition.R +baf3438a7919a6f62f914f13426a9a71 *R/leiden.R 6ba0a146b84a8509099bb71d658f1f5d *R/py_objects.R -50a5917f7fbe3919fae7c71464f05ada *build/vignette.rds -b6a2396000ac44b272d3d655577cf7f9 *inst/CITATION +afc6fe1f7bf74cb09d6244564daf1017 *build/vignette.rds +05c6a297b5d8299713a2afae9c33fc98 *inst/CITATION 933d1f1517634865c15b8242a81398a5 *inst/WORDLIST -7145815cc649ae3479b357927bacc3c5 *inst/doc/benchmarking.R -418187aa78daa6b7052c4c5964e5ee49 *inst/doc/benchmarking.Rmd -09e726eb62de6bc7e9dd92b225c7cea0 *inst/doc/benchmarking.html +250aa3c666a8bb44139837c97e192522 *inst/doc/benchmarking.R +68f25348a3f579422492481ee23dc73c *inst/doc/benchmarking.Rmd +dac6d43e36c100c86708e5f84af32c51 *inst/doc/benchmarking.html 7bd5ae95d01296c5f3bf43cb0e157574 *inst/doc/run_bipartite.R 2e07d6c9463e8afcd95bb6f3e767e7c4 *inst/doc/run_bipartite.Rmd -75a390be66578154151aa57da23cd3e7 *inst/doc/run_bipartite.html +521ebc406a75731d9d1ae96a7778c772 *inst/doc/run_bipartite.html 4b75a7ec733803bf8301491f9c14197c *inst/doc/run_igraph.R 137c000cb316fd2e11ffd5c8d1a702ba *inst/doc/run_igraph.Rmd -03853c8bb95e50852198f50ef6519391 *inst/doc/run_igraph.html -d55559ddee0fdea807fb56db399d62c7 *inst/doc/run_leiden.R -bc00f62c77077bb27e544a72b10007ee *inst/doc/run_leiden.Rmd -34a48d2a4b2621b6cdc9ca95d07a4445 *inst/doc/run_leiden.html -3862f3769a6388b218536fc7d91cbed6 *inst/doc/run_multiplex.R -6b0b5fbbdf67c98210d1779dac5200da *inst/doc/run_multiplex.Rmd -eb189d2bf5ba915520c743e3b4f09aa5 *inst/doc/run_multiplex.html -1bc4aa58f6b48b4f2f01707ef40c016c *man/leiden.Rd +ea5f9a0b7826699eb636a4142c907247 *inst/doc/run_igraph.html +fc22d3c2310bc57f6c6349e8c19e5dfa *inst/doc/run_leiden.R +489808ae73b9f8ad78889809b7868ac5 *inst/doc/run_leiden.Rmd +ab2bf87c6915d7ab4c57d8780bc77e0d *inst/doc/run_leiden.html +c72984ce2f3847bbba158cb951ac5576 *inst/doc/run_multiplex.R +72be80152aa69ab2dadc7405e6eba5dc *inst/doc/run_multiplex.Rmd +528fc429a42e5272d817cf9779088873 *inst/doc/run_multiplex.html +202bec76774bf54f4dd055cd8bb63da2 *man/leiden.Rd 0622a97a2aaa3c342f09636052c2d7f5 *tests/spelling.R 0673a2cb3b3bbd102bab6fbafe799fe7 *tests/testthat.R 5b0379db2dfd476e55fc6952f249344e *tests/testthat/test_bipartite.R -f99a3d78e22397b9c2700ed69e07bc3f *tests/testthat/test_igraph.R +1605d12d2ee239f8099bfb09c2dcc703 *tests/testthat/test_igraph.R 71157703139362d1b7676d99ed27d46f *tests/testthat/test_leiden.R f863e5cf12f3d7274e0622270363f8d3 *tests/testthat/test_methods.R -0c12882206c600d080624a8a7f46c208 *tests/testthat/test_multiplex.R -3eb96b069e9d85e14eefc8496cfb0d88 *tests/testthat/test_weighted.R -418187aa78daa6b7052c4c5964e5ee49 *vignettes/benchmarking.Rmd +0fd74e633387f5004cfebbd3cdf02279 *tests/testthat/test_multiplex.R +6d176a79d6d9e3b751e3e56a3a7a5a04 *tests/testthat/test_weighted.R +68f25348a3f579422492481ee23dc73c *vignettes/benchmarking.Rmd 2e07d6c9463e8afcd95bb6f3e767e7c4 *vignettes/run_bipartite.Rmd 137c000cb316fd2e11ffd5c8d1a702ba *vignettes/run_igraph.Rmd -bc00f62c77077bb27e544a72b10007ee *vignettes/run_leiden.Rmd -6b0b5fbbdf67c98210d1779dac5200da *vignettes/run_multiplex.Rmd +489808ae73b9f8ad78889809b7868ac5 *vignettes/run_leiden.Rmd +72be80152aa69ab2dadc7405e6eba5dc *vignettes/run_multiplex.Rmd diff -Nru r-cran-leiden-0.3.10+dfsg/NAMESPACE r-cran-leiden-0.4.2+dfsg/NAMESPACE --- r-cran-leiden-0.3.10+dfsg/NAMESPACE 2022-04-25 06:44:47.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/NAMESPACE 2022-05-09 12:32:13.000000000 +0000 @@ -11,22 +11,27 @@ importClassesFrom(Matrix,dgeMatrix) importFrom(igraph,E) importFrom(igraph,V) +importFrom(igraph,as.undirected) importFrom(igraph,as_adjacency_matrix) importFrom(igraph,as_edgelist) importFrom(igraph,bipartite_mapping) +importFrom(igraph,cluster_leiden) +importFrom(igraph,communities) importFrom(igraph,edge_attr) importFrom(igraph,graph_from_adjacency_matrix) importFrom(igraph,is.igraph) -importFrom(igraph,is.named) -importFrom(igraph,is.weighted) importFrom(igraph,is_bipartite) +importFrom(igraph,is_directed) importFrom(igraph,is_named) importFrom(igraph,is_weighted) importFrom(igraph,laplacian_matrix) +importFrom(igraph,membership) importFrom(igraph,set_edge_attr) importFrom(igraph,set_vertex_attr) importFrom(igraph,simplify) importFrom(igraph,vertex_attr) +importFrom(igraph,which_loop) +importFrom(igraph,which_mutual) importFrom(methods,as) importFrom(methods,is) importFrom(reticulate,import) diff -Nru r-cran-leiden-0.3.10+dfsg/NEWS.md r-cran-leiden-0.4.2+dfsg/NEWS.md --- r-cran-leiden-0.3.10+dfsg/NEWS.md 2022-04-25 07:50:36.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/NEWS.md 2022-05-09 12:32:13.000000000 +0000 @@ -1,8 +1,30 @@ +# leiden 0.4.2 + +* migrates bug fixes to conda environment and limit on total cells to refactored package + +* allows calling igraph::community_leiden for supported parameters (requires igraph v1.2.7 or later) + +* automatically calls native R version of leiden rather than Python to improve performance + +* updates vignettes and unit tests to ensure consistent results with past versions + +# leiden 0.4.1 + +* migrates changes to retain on CRAN to leiden 0.4.0 (alpha) + +# leiden 0.4.0 + +* migrate to calling community_leiden in igraph + +* updates the benchmarking vignette to compare performance to legacy versions using reticulate + # leiden 0.3.10 -* removes limitation on number of cells (disables scientific notation within function call) +* removes limitation on number of cells (disables scientific notation within function call): resolves #12 + +* resolves conflict between base and r-reticulate conda environments on loading: resolves #20 -* resolves conflict between base and r-reticulate conda environments on loading +* updates conda environment in interactive sessions only for compliance to CRAN checks * resolves formatting error in Rmarkdown vignettes (https://github.com/yihui/knitr/issues/2057) diff -Nru r-cran-leiden-0.3.10+dfsg/R/find_partition.R r-cran-leiden-0.4.2+dfsg/R/find_partition.R --- r-cran-leiden-0.3.10+dfsg/R/find_partition.R 2022-04-25 06:44:47.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/R/find_partition.R 2022-05-09 12:32:13.000000000 +0000 @@ -88,7 +88,8 @@ seed = NULL, n_iterations = 2L, max_comm_size = 0L, -degree_as_node_size = TRUE +degree_as_node_size = TRUE, +legacy = FALSE ) { # disable printing numerals in scientific notation oo <- options(scipen = 100000000000) @@ -295,7 +296,7 @@ n_iterations = 2L, max_comm_size = 0L, degree_as_node_size = TRUE, -legacy = FALSE +legacy = TRUE ) { # disable printing numerals in scientific notation oo <- options(scipen = 100000000000) diff -Nru r-cran-leiden-0.3.10+dfsg/R/leiden.R r-cran-leiden-0.4.2+dfsg/R/leiden.R --- r-cran-leiden-0.3.10+dfsg/R/leiden.R 2022-04-27 21:12:21.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/R/leiden.R 2022-05-09 12:32:13.000000000 +0000 @@ -15,6 +15,7 @@ ##' @param max_comm_size (non-negative int) – Maximal total size of nodes in a community. If zero (the default), then communities can be of any size. ##' @param degree_as_node_size (defaults to FALSE). If True use degree as node size instead of 1, to mimic modularity for Bipartite graphs. ##' @param laplacian (defaults to FALSE). Derive edge weights from the Laplacian matrix. +##' @param legacy (defaults to FALSE). Force calling python implementation via reticulate. Default behaviour is calling cluster_leiden in igraph with Modularity (for undirected graphs) and CPM cost functions. ##' @return A partition of clusters as a vector of integers ##' @examples ##' #check if python is availble @@ -99,7 +100,8 @@ n_iterations = 2L, max_comm_size = 0L, degree_as_node_size = FALSE, - laplacian = FALSE) { + laplacian = FALSE, + legacy = FALSE) { UseMethod("leiden", object) } @@ -125,7 +127,8 @@ n_iterations = 2L, max_comm_size = 0L, degree_as_node_size = FALSE, - laplacian = FALSE + laplacian = FALSE, + legacy = FALSE ) { # disable printing numerals in scientific notation oo <- options(scipen = 100000000000) @@ -201,8 +204,12 @@ n_iterations = 2L, max_comm_size = 0L, degree_as_node_size = FALSE, - laplacian = FALSE + laplacian = FALSE, + legacy = FALSE ) { + if(length(partition_type) > 1) partition_type <- partition_type[[1]][1] + partition_type <- match.arg(partition_type) + # disable printing numerals in scientific notation oo <- options(scipen = 100000000000) # restore options when function terminates @@ -227,7 +234,8 @@ seed = seed, n_iterations = n_iterations, degree_as_node_size = degree_as_node_size, - laplacian = laplacian + laplacian = laplacian, + legacy = legacy ) } @@ -255,7 +263,8 @@ n_iterations = 2L, max_comm_size = 0L, degree_as_node_size = FALSE, - laplacian = FALSE + laplacian = FALSE, + legacy = FALSE ) { # disable printing numerals in scientific notation oo <- options(scipen = 100000000000) @@ -276,7 +285,8 @@ n_iterations = n_iterations, max_comm_size = max_comm_size, degree_as_node_size = degree_as_node_size, - laplacian = laplacian + laplacian = laplacian, + legacy = legacy ) } else{ @@ -323,7 +333,7 @@ ##' @export leiden.default <- leiden.matrix -##' @importFrom igraph V as_edgelist is.weighted is.named edge_attr as_adjacency_matrix laplacian_matrix vertex_attr is_bipartite bipartite_mapping set_vertex_attr simplify is_named is_weighted +##' @importFrom igraph V as_edgelist is_weighted is_named edge_attr as_adjacency_matrix laplacian_matrix vertex_attr is_bipartite bipartite_mapping set_vertex_attr simplify as.undirected is_directed communities membership cluster_leiden which_mutual which_loop is_named is_weighted ##' @export leiden.igraph <- function(object, partition_type = c( @@ -345,8 +355,13 @@ n_iterations = 2L, max_comm_size = 0L, degree_as_node_size = FALSE, - laplacian = FALSE + laplacian = FALSE, + legacy = FALSE ) { + #default partition + if(length(partition_type) > 1) partition_type <- partition_type[[1]][1] + partition_type <- match.arg(partition_type) + # disable printing numerals in scientific notation oo <- options(scipen = 100000000000) # restore options when function terminates @@ -357,85 +372,122 @@ leidenalg <- import("leidenalg", delay_load = TRUE) ig <- import("igraph", delay_load = TRUE) - #default partition - if(length(partition_type) > 1) partition_type <- partition_type[[1]][1] - partition_type <- match.arg(partition_type) - - ##convert to python numpy.ndarray, then a list - if(!is.named(object)){ - vertices <- as.list(as.character(V(object))) - } else { - vertices <- as.list(names(V(object))) - } - - edges <- as_edgelist(object) - dim(edges) - edgelist <- list(rep(NA, nrow(edges))) - for(ii in 1:nrow(edges)){ - edgelist[[ii]] <- as.character(edges[ii,]) + #pass weights to igraph if not found + if(!is_weighted(object) && !is.null(weights)){ + #assign weights to edges (without dependancy on igraph) + if(length(E(object)) == length(weights)){ + set_edge_attr(object, "weight", value = weights) + } else { + warning(paste("weights but be same length as number of edges:", length(E(object)))) + weights <- NULL + } } #derive Laplacian if(laplacian == TRUE){ object <- simplify(object, remove.multiple = TRUE, remove.loops = TRUE) laplacian <- laplacian_matrix(object) - if(!is.weighted(object)){ - edge_attr(object)$weight + if(!is_weighted(object)){ object <- set_edge_attr(object, "weight", value = -as.matrix(laplacian)[as.matrix(laplacian) < 0]) } } - py_graph <- make_py_graph(object, weights = weights) + #check whether compatible with igraph implementations in R + if(is_directed(object) && !is_bipartite(object)){ + #coerce to undirected graph object if possible + if(all(which_mutual(object) | which_loop(object)) || partition_type == "CPMVertexPartition"){ + object <- as.undirected(object, mode = "each") + } + } + call_igraph <- !is_directed(object) && !is_bipartite(object) && legacy == FALSE && (partition_type == "CPMVertexPartition" || partition_type == "ModularityVertexPartition") + #print(call_igraph) - if(length(partition_type) > 1) partition_type <- partition_type[1] - if(partition_type == "ModularityVertexPartition.Bipartite"){ - if(is.null(vertex_attr(object, "type"))){ - if(bipartite_mapping(object)$res){ - packageStartupMessage("computing bipartite partitions") - object <- set_vertex_attr(object, "type", value = bipartite_mapping(object)$type) - } else { - packageStartupMessage("cannot compute bipartite types, defaulting to partition type ModularityVertexPartition") - partition_type <- "ModularityVertexPartition" + if(call_igraph == TRUE){ + #call igraph implementation + if(partition_type == "CPMVertexPartition"){ + objective_function <- "cpm" + } + if(partition_type == "ModularityVertexPartition"){ + objective_function <- "modularity" + } + + #compute partitions with igraph in C + if(!is.null(seed)) set.seed(seed) + partition <- membership(cluster_leiden(graph = object, + objective_function = objective_function, + weights = weights, + resolution_parameter = resolution_parameter, + initial_membership = initial_membership, + n_iterations = n_iterations, + vertex_weights = NULL + )) + partition <- as.numeric(partition) + } else { + #call python reticulate implementation + #import python modules with reticulate + numpy <- import("numpy", delay_load = TRUE) + leidenalg <- import("leidenalg", delay_load = TRUE) + ig <- import("igraph", delay_load = TRUE) + + py_graph <- make_py_object(object, weights = weights) + + if(is_bipartite(object) && partition_type == "ModularityVertexPartition"){ + partition_type <- "ModularityVertexPartition.Bipartite" + } + if(partition_type == "ModularityVertexPartition.Bipartite"){ + if(is.null(vertex_attr(object, "type"))){ + if(bipartite_mapping(object)$res){ + packageStartupMessage("computing bipartite partitions") + object <- set_vertex_attr(object, "type", value = bipartite_mapping(object)$type) + partition_type <- "ModularityVertexPartition.Bipartite" + } else { + packageStartupMessage("cannot compute bipartite types, defaulting to partition type ModularityVertexPartition") + partition_type <- "ModularityVertexPartition" + } } } - } - if(partition_type == "CPMVertexPartition.Bipartite"){ - if(is.null(vertex_attr(object, "type"))){ - if(bipartite_mapping(object)$res){ - packageStartupMessage("computing bipartite partitions") - object <- set_vertex_attr(object, "type", value = bipartite_mapping(object)$type) - } else { - packageStartupMessage("cannot compute bipartite types, defaulting to partition type CPMVertexPartition") - partition_type <- "CPMVertexPartition" + if(is_bipartite(object) && partition_type == "CPMVertexPartition"){ + partition_type <- "CPMVertexPartition.Bipartite" + } + if(partition_type == "CPMVertexPartition.Bipartite"){ + if(is.null(vertex_attr(object, "type"))){ + if(bipartite_mapping(object)$res){ + packageStartupMessage("computing bipartite partitions") + object <- set_vertex_attr(object, "type", value = bipartite_mapping(object)$type) + partition_type <- "CPMVertexPartition.Bipartite" + } else { + packageStartupMessage("cannot compute bipartite types, defaulting to partition type CPMVertexPartition") + partition_type <- "CPMVertexPartition" + } } } - } - if(!is.null(vertex_attr(object, "type")) || is_bipartite(object)){ - type <- as.integer(unlist(V(object)$type)) - py_graph$vs$set_attribute_values('type', r_to_py(as.integer(type))) - } + if(!is.null(vertex_attr(object, "type")) || is_bipartite(object)){ + type <- as.integer(unlist(V(object)$type)) + py_graph$vs$set_attribute_values('type', r_to_py(as.integer(type))) + } - #compute partitions - partition <- find_partition(py_graph, partition_type = partition_type, - initial_membership = initial_membership , - weights = weights, - node_sizes = node_sizes, - resolution_parameter = resolution_parameter, - seed = seed, - n_iterations = n_iterations, - max_comm_size = max_comm_size, - degree_as_node_size = degree_as_node_size - ) + #compute partitions with reticulate + partition <- find_partition(py_graph, partition_type = partition_type, + initial_membership = initial_membership, + weights = weights, + node_sizes = node_sizes, + resolution_parameter = resolution_parameter, + seed = seed, + n_iterations = n_iterations, + max_comm_size = max_comm_size, + degree_as_node_size = degree_as_node_size + ) + } partition } # global reference to python modules (will be initialized in .onLoad) -leidenalg <<- NULL -ig <<- NULL -numpy <<- NULL -pd <<- NULL +leidenalg <- NULL +ig <- NULL +numpy <- NULL +pd <- NULL #' @importFrom utils install.packages capture.output @@ -516,43 +568,31 @@ Sys.setenv(RETICULATE_PYTHON = reticulate::conda_python()) } } else { - # shell <- strsplit(Sys.getenv("SHELL"), "/")[[1]] - # shell <- shell[length(shell)] - # eval(parse(text = paste0(c('system("conda init ', shell, '")'), collapse = ""))) - # eval(parse(text = paste0(c('system("source ~/.', shell, 'rc")'), collapse = ""))) - # shell <- as.list(system("echo $0")) - # if(shell == sh) shell <- "bash" - # system("conda init") - # eval(parse(text = paste0(c('system("source ~/.', shell, '_profile")'), collapse = ""))) - # system("conda init") - # system("conda activate r-reticulate") if(!reticulate::py_module_available("numpy")) suppressWarnings(suppressMessages(reticulate::py_install("numpy"))) if(!reticulate::py_module_available("pandas")) suppressWarnings(suppressMessages(reticulate::py_install("pandas"))) if(!reticulate::py_module_available("igraph")) suppressWarnings(suppressMessages(reticulate::py_install("python-igraph", method = method, conda = conda))) if(!reticulate::py_module_available("umap")) suppressWarnings(suppressMessages(reticulate::py_install("umap-learn"))) if(!reticulate::py_module_available("leidenalg")) suppressWarnings(suppressMessages(reticulate::py_install("leidenalg", method = method, conda = conda, forge = TRUE))) - #Sys.setenv(PATH = paste0(strsplit(reticulate::py_config()$pythonhome, ":")[[1]][1], "/bin:$PATH")) Sys.setenv(RETICULATE_PYTHON = reticulate::py_config()$python) } } - quiet <- function(expr, all = TRUE) { - if (Sys.info()['sysname'] == "Windows") { - file <- "NUL" - } else { - file <- "/dev/null" - } + } + quiet <- function(expr, all = TRUE) { + if (Sys.info()['sysname'] == "Windows") { + file <- "NUL" + } else { + file <- "/dev/null" + } - if (all) { - suppressWarnings(suppressMessages(suppressPackageStartupMessages( - capture.output(expr, file = file) - ))) - } else { + if (all) { + suppressWarnings(suppressMessages(suppressPackageStartupMessages( capture.output(expr, file = file) - } - + ))) + } else { + capture.output(expr, file = file) } - quiet(install_python_modules()) } + quiet(install_python_modules()) } }, error = function(e){ packageStartupMessage("Unable to install python modules igraph and leidenalg") diff -Nru r-cran-leiden-0.3.10+dfsg/tests/testthat/test_igraph.R r-cran-leiden-0.4.2+dfsg/tests/testthat/test_igraph.R --- r-cran-leiden-0.3.10+dfsg/tests/testthat/test_igraph.R 2022-04-25 06:44:47.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/tests/testthat/test_igraph.R 2022-05-09 12:32:13.000000000 +0000 @@ -80,3 +80,126 @@ partition <- leiden(snn_graph) expect_length(partition, 100) }) + +mat1 <- matrix(round(runif(10000, 0, 1)), 100, 100) +mat2 <- matrix(round(rbinom(10000, 1, 0.1)), 100, 100) +adj_mat <- rbind(cbind(mat1, mat2), cbind(mat2, mat1)) + +snn_graph <- graph_from_adjacency_matrix(adj_mat) +snn_graph <- as.undirected(snn_graph, mode = "each") + +test_that("run with reticulate in legacy mode with 2 clusters", { + skip_if_no_python() + set.seed(42) + partition <- leiden(snn_graph, + partition_type = "ModularityVertexPartition", + seed = 42L, + legacy = TRUE, + resolution_parameter = 0.95) + expect_length(partition, 200) +}) + +test_that("run with igraph modewith 2 clusters", { + skip_if_no_python() + set.seed(42) + partition <- leiden(snn_graph, + partition_type = "ModularityVertexPartition", + seed = 42L, + legacy = FALSE, + resolution_parameter = 0.95) + expect_length(partition, 200) +}) + +test_that("run consistent results bewteen igraph and reticulate legacy mode with 2 clusters", { + skip_if_no_python() + set.seed(42) + partition <- leiden(snn_graph, + partition_type = "ModularityVertexPartition", + seed = 42L, + legacy = TRUE, + resolution_parameter = 0.95) + expect_length(partition, 200) + set.seed(42) + partition2 <- leiden(snn_graph, + partition_type = "ModularityVertexPartition", + seed = 42L, + legacy = FALSE, + resolution_parameter = 0.95) + expect_true(all(table(partition, partition2) %in% c(0, 100))) + set.seed(42) + partition <- leiden(snn_graph, + partition_type = "CPMVertexPartition", + seed = 42L, + legacy = TRUE, + resolution_parameter = 0.5) + expect_length(partition, 200) + set.seed(42) + partition2 <- leiden(snn_graph, + partition_type = "CPMVertexPartition", + seed = 42L, + legacy = FALSE, + resolution_parameter = 0.5) + expect_true(all(table(partition, partition2) %in% c(0, 100))) +}) + +mat1 <- matrix(round(runif(10000, 0, 1)), 100, 100) +mat2 <- matrix(round(rbinom(10000, 1, 0.1)), 100, 100) +mat3 <- matrix(round(rbinom(10000, 1, 0.01)), 100, 100) +adj_mat <- rbind(cbind(mat1, mat2, mat3), cbind(mat2, mat1, mat2), cbind(mat3, mat2, mat1)) + +snn_graph <- graph_from_adjacency_matrix(adj_mat) +snn_graph <- as.undirected(snn_graph, mode = "each") + +test_that("run with reticulate in legacy mode with 3 clusters", { + skip_if_no_python() + set.seed(42) + partition <- leiden(snn_graph, + partition_type = "ModularityVertexPartition", + seed = 42L, + legacy = TRUE, + resolution_parameter = 0.95) + expect_length(partition, 300) +}) + +test_that("run with igraph mode with 3 clusters", { + skip_if_no_python() + set.seed(42) + partition <- leiden(snn_graph, + partition_type = "ModularityVertexPartition", + seed = 42L, + legacy = FALSE, + resolution_parameter = 0.95) + expect_length(partition, 300) +}) + +test_that("run consistent results bewteen igraph and reticulate legacy mode with 3 clusters", { + skip_if_no_python() + set.seed(42) + partition <- leiden(snn_graph, + partition_type = "ModularityVertexPartition", + seed = 42L, + legacy = TRUE, + resolution_parameter = 0.95) + expect_length(partition, 300) + set.seed(42) + partition2 <- leiden(snn_graph, + partition_type = "ModularityVertexPartition", + seed = 42L, + legacy = FALSE, + resolution_parameter = 0.95) + expect_true(all(table(partition, partition2) %in% c(0, 100))) + set.seed(42) + partition <- leiden(snn_graph, + partition_type = "CPMVertexPartition", + seed = 42L, + legacy = TRUE, + resolution_parameter = 0.5) + expect_length(partition, 300) + set.seed(42) + partition2 <- leiden(snn_graph, + partition_type = "CPMVertexPartition", + seed = 42L, + legacy = FALSE, + resolution_parameter = 0.5) + expect_true(all(table(partition, partition2) %in% c(0, 100))) +}) diff -Nru r-cran-leiden-0.3.10+dfsg/tests/testthat/test_multiplex.R r-cran-leiden-0.4.2+dfsg/tests/testthat/test_multiplex.R --- r-cran-leiden-0.3.10+dfsg/tests/testthat/test_multiplex.R 2022-04-25 06:44:47.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/tests/testthat/test_multiplex.R 2022-05-09 12:32:13.000000000 +0000 @@ -1,6 +1,7 @@ library("reticulate") library("igraph") library("leiden") +library("multiplex") set.seed(9000) context("running Leiden on multiplex igraph objects") @@ -214,7 +215,7 @@ testthat::skip("leidenalg not available for testing") } - +set.seed(9000) test_that("run with CPMVertexPartition multiplexed", { skip_if_no_python() partition <- leiden(multiplex_graph, @@ -226,11 +227,12 @@ expect_equal(partition, c(8, 2, 7, 5, 2, 5, 1, 2, 6, 5, 5, 2, 2, 5, 5, 5, 3, 6, 1, 2, 7, 10, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 4, 4, 2, - 2, 2, 6, 4, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 6, 7, 6, 4, 9, 4 + 2, 2, 6, 4, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 3, 7, 6, 4, 9, 4 )) multiplex_graph }) +set.seed(9000) test_that("run with ModularityVertexPartition multiplexed", { skip_if_no_python() partition <- leiden(multiplex_graph, @@ -240,12 +242,17 @@ seed = 9001) expect_length(partition, length(V(multiplex_graph[[1]]))) expect_equal(sort(unique(partition)), 1:6) + expect_equal(table(partition), + structure(c(`1` = 15L, `2` = 13L, `3` = 13L, `4` = 11L, `5` = 8L, + `6` = 1L), .Dim = 6L, .Dimnames = list(partition = c("1", "2", + "3", "4", "5", "6")), class = "table")) expect_equal(partition, - c(3, 3, 1, 4, 3, 4, 4, 3, 1, 4, 4, 3, 3, 4, 4, 4, 1, 1, 2, 3, - 1, 3, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 5, 5, 3, 3, - 3, 1, 5, 3, 1, 1, 1, 1, 1, 1, 1, 5, 5, 5, 1, 1, 1, 5, 6, 5)) + c(4, 2, 4, 4, 2, 4, 4, 2, 1, 4, 4, 2, 2, 4, 4, 4, 1, 1, 3, 2, + 2, 2, 1, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 5, 5, 2, 2, + 2, 1, 5, 2, 1, 1, 1, 1, 1, 1, 1, 5, 5, 5, 1, 4, 1, 5, 6, 5)) }) +set.seed(9000) test_that("run with ModularityVertexPartition multiplexed and max_comm_size", { skip_if_no_python() partition <- leiden(multiplex_graph, @@ -257,8 +264,9 @@ expect_length(partition, length(V(multiplex_graph[[1]]))) expect_equal(sort(unique(partition)), 1:10) expect_equal(max(table(partition)), 8) - expect_equal(partition, - c(4, 4, 2, 3, 8, 3, 3, 4, 2, 3, 3, 8, 8, 3, 3, 3, 6, 6, 5, 8, - 2, 8, 6, 7, 2, 5, 5, 5, 7, 5, 7, 7, 5, 5, 7, 5, 4, 1, 1, 4, 4, - 4, 2, 1, 4, 6, 6, 6, 6, 9, 2, 6, 1, 1, 1, 2, 2, 7, 1, 10, 1)) + expect_equal(table(partition), + structure(c(`1` = 8L, `2` = 8L, `3` = 8L, `4` = 8L, `5` = 8L, + `6` = 8L, `7` = 6L, `8` = 5L, `9` = 1L, `10` = 1L), .Dim = 10L, .Dimnames = list( + partition = c("1", "2", "3", "4", "5", "6", "7", "8", "9", + "10")), class = "table")) }) diff -Nru r-cran-leiden-0.3.10+dfsg/tests/testthat/test_weighted.R r-cran-leiden-0.4.2+dfsg/tests/testthat/test_weighted.R --- r-cran-leiden-0.3.10+dfsg/tests/testthat/test_weighted.R 2022-04-25 06:44:47.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/tests/testthat/test_weighted.R 2022-05-09 12:32:13.000000000 +0000 @@ -22,39 +22,54 @@ test_that("run with unweighted dense matrix", { skip_if_no_python() set.seed(9000) - mat <- round(matrix(runif(100, max = 1), 10, 10, ), 0) + mat <- round(matrix(runif(100, max = 1), 10, 10), 0) mat - part_mat0 <- leiden::leiden(mat, seed = 9000) - expect_equal(part_mat0, c(1, 2, 2, 2, 1, 2, 2, 1, 1, 1)) + part_mat0 <- leiden::leiden(mat, seed = 9000, resolution_parameter = 0.8) + expect_equal(table(part_mat0), structure(c(`1` = 5L, `2` = 5L), .Dim = 2L, .Dimnames = list( + part_mat0 = c("1", "2")), class = "table")) + expect_length(object = unique(part_mat0[which(c(1, 2, 2, 2, 1, 2, 2, 1, 1, 1) == 1)]), n = 1) + expect_length(object = unique(part_mat0[which(c(1, 2, 2, 2, 1, 2, 2, 1, 1, 1) == 2)]), n = 1) }) +set.seed(9000) test_that("run with unweighted sparse matrix", { skip_if_no_python() + set.seed(9000) sp.mat <- as(mat, Class = "dgCMatrix") part_sp.mat0 <- leiden::leiden(sp.mat, seed = 9000) - expect_equal(part_sp.mat0, c(1, 2, 2, 2, 1, 2, 2, 1, 1, 1)) + expect_equal(table(part_sp.mat0), structure(c(`1` = 5L, `2` = 5L), .Dim = 2L, .Dimnames = list( + part_sp.mat0 = c("1", "2")), class = "table")) + expect_length(object = unique(part_sp.mat0[which(c(1, 2, 2, 2, 1, 2, 2, 1, 1, 1) == 1)]), n = 1) + expect_length(object = unique(part_sp.mat0[which(c(1, 2, 2, 2, 1, 2, 2, 1, 1, 1) == 2)]), n = 1) }) - +set.seed(9000) test_that("run with unweighted graph object", { skip_if_no_python() + set.seed(9000) graph <- igraph::graph_from_adjacency_matrix(mat, weighted = NULL) graph part_graph0 <- leiden::leiden(graph, seed = 9000) part_graph0 - expect_equal(part_graph0, c(1, 2, 2, 2, 1, 2, 2, 1, 1, 1)) + expect_equal(table(part_graph0), structure(c(`1` = 5L, `2` = 5L), .Dim = 2L, .Dimnames = list( + part_graph0 = c("1", "2")), class = "table")) + expect_length(object = unique(part_graph0[which(c(1, 2, 2, 2, 1, 2, 2, 1, 1, 1) == 1)]), n = 1) + expect_length(object = unique(part_graph0[which(c(1, 2, 2, 2, 1, 2, 2, 1, 1, 1) == 2)]), n = 1) + }) +set.seed(9000) test_that("same output with different input class", { skip_if_no_python() - part_mat0 <- leiden::leiden(mat, seed = 9000) - part_graph0 <- leiden::leiden(graph, seed = 9000) - expect_equivalent(part_mat0, c(1, 2, 2, 2, 1, 2, 2, 1, 1, 1)) - expect_equivalent(part_graph0, c(1, 2, 2, 2, 1, 2, 2, 1, 1, 1)) - expect_equivalent(part_mat0, part_graph0) - expect_equal(sum(diag(table(part_mat0, part_graph0))), length(part_mat0)) - expect_equal(sum(diag(table(part_mat0, part_graph0))), nrow(mat)) - expect_equal(sum(diag(table(part_mat0, part_graph0))), length(V(graph))) + set.seed(9000) + part_mat0 <- leiden::leiden(mat, seed = 9000, resolution_parameter = 0.8) + set.seed(9000) + part_graph0 <- leiden::leiden(graph, seed = 9000, resolution_parameter = 0.8) + expect_length(object = unique(part_mat0[which(c(1, 2, 2, 2, 1, 2, 2, 1, 1, 1) == 1)]), n = 1) + expect_length(object = unique(part_mat0[which(c(1, 2, 2, 2, 1, 2, 2, 1, 1, 1) == 2)]), n = 1) + expect_length(object = unique(part_graph0[which(c(1, 2, 2, 2, 1, 2, 2, 1, 1, 1) == 1)]), n = 1) + expect_length(object = unique(part_graph0[which(c(1, 2, 2, 2, 1, 2, 2, 1, 1, 1) == 2)]), n = 1) + expect_true(all(part_mat0 + part_graph0 == 3) || all(part_mat0 == part_graph0)) }) # # Test Seurat (development version) @@ -103,6 +118,7 @@ test_that("run with weighted sparse matrix", { skip_if_no_python() + set.seed(9000) sp.mat <- as(mat, Class = "dgCMatrix") #passing weights part_sp.mat1 <- leiden::leiden(sp.mat, seed = 9000, weights = mat[mat != 0]) @@ -115,6 +131,7 @@ test_that("run with weighted graph object", { skip_if_no_python() + set.seed(9000) graph <- igraph::graph_from_adjacency_matrix(mat, weighted = NULL) graph #passing weights @@ -127,6 +144,7 @@ test_that("same output with different input class", { skip_if_no_python() + set.seed(9000) part_mat1 <- leiden::leiden(mat, seed = 9000) part_graph1 <- leiden::leiden(graph, seed = 9000) expect_equivalent(part_mat1, c(2, 1, 1, 1, 2, 1, 1, 2, 2, 2)) @@ -159,4 +177,3 @@ # sum(diag(table(part_mat2, part_graph2))) == length(part_mat) # sum(diag(table(part_mat2, part_graph2))) == nrow(mat) # sum(diag(table(part_mat2, part_graph2))) == length(V(graph)) - diff -Nru r-cran-leiden-0.3.10+dfsg/vignettes/benchmarking.Rmd r-cran-leiden-0.4.2+dfsg/vignettes/benchmarking.Rmd --- r-cran-leiden-0.3.10+dfsg/vignettes/benchmarking.Rmd 2022-04-25 11:50:37.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/vignettes/benchmarking.Rmd 2022-05-09 12:32:13.000000000 +0000 @@ -280,7 +280,7 @@ Note that these require the Python version as a dependency. -### Running in R +### Running in R via reticulate and igraph We can reproduce these by running the Leiden algorithm in R using the functions in the leiden package. @@ -304,8 +304,13 @@ G <- graph.famous("Zachary") summary(G) ``` + +#### Calling python in R via reticulate + +Here run "legacy" mode to call "leidenalg" in python with the R reticulate package. + ```{r, eval=module} -partition <- leiden(G, "ModularityVertexPartition") +partition <- leiden(G, "ModularityVertexPartition", legacy = TRUE) partition ``` @@ -326,8 +331,8 @@ We can reproduce passing arguments in this manner as well. -```{r, eval=module} -partition <- leiden(G, "CPMVertexPartition", resolution_parameter = 0.5) +````{r, eval=module} +partition <- leiden(G, "CPMVertexPartition", resolution_parameter = 0.05, legacy = TRUE) partition ``` @@ -361,6 +366,55 @@ plot(G, vertex.color = node.cols, layout=layout_with_kk) ``` +#### Calling C in R with igraph + +We can improve performance for undirected graphs for Modularity and CPM cost functions by calling C in igraph. + +```{r, eval=module} +G <- as.undirected(G, mode = "each") +is.directed(G) +partition <- leiden(G, "ModularityVertexPartition", legacy = FALSE) +partition +``` + +```{r, eval=module} +table(partition) +``` + +We can plot the result in R to show it in the network. This reproduces the example in the Python leidenalg documentation. + +```{r} +library("igraph") +library("reticulate") +library("RColorBrewer") +node.cols <- brewer.pal(max(c(3, partition)),"Pastel1")[partition] +plot(G, vertex.color = node.cols, layout=layout_with_kk) +``` + +We check here that it returns the same results as in igraph. + +````{r, eval=module} +partition <- membership(cluster_leiden(G, objective_function = "modularity")) +partition +table(partition) +``` + +We can also run CPM cost functions. + +````{r, eval=module} +partition <- leiden(G, "CPMVertexPartition", resolution_parameter = 0.1, legacy = FALSE) +partition +table(partition) +``` + +We can plot the result in R to show it in the network. This reproduces the example in the Python leidenalg documentation. + +```{r, eval=module} +node.cols <- brewer.pal(max(c(3, partition)),"Pastel1")[partition] +plot(G, vertex.color = node.cols, layout=layout_with_kk) +``` + + #### Benchmarking the R version with reticulate Now we can time how long the computation of the algorithm takes (for 1000 runs) calling with R on a graph object: @@ -370,7 +424,7 @@ summary(G) start <- Sys.time() for(ii in 1:100){ - partition = leiden(G, "ModularityVertexPartition") + partition <- leiden(G, "ModularityVertexPartition", legacy = TRUE) } end <- Sys.time() table(partition) @@ -378,7 +432,7 @@ print(paste(c("leiden time:", R_graph_time, "seconds"), collapse = " ")) ``` -We can see that the R implementation does not perform as well as the Python version but it is convenient for R users. Calling from a graph object avoids casting to a dense adjacency matrix which reduces memory load for large graph objects. +We can see that the R reticualte implementation does not perform as well as the Python version but it is convenient for R users. Calling from a graph object avoids casting to a dense adjacency matrix which reduces memory load for large graph objects. We can see that calling leiden in R on an adjacency matrix has faster performance but it does require more memory. For example, on a dense adjacency matrix: @@ -704,14 +758,108 @@ Here we can see that the current approach to pass adjacency matrices to Python and generate graphs in Python is more efficient for a dense matrix than computing the graph in R. Therefore the leiden.matrix method will not call the leiden.igraph method and they will remain distinct. +#### Calling C in R with igraph + +Here we compare calling modularity clustering in igraph (R and C) to calling Python via reticulate. Note this is only available for undirected graphs with modularity or CPM. Calling igraph in R does not have a python dependency. + +```{r} +time9 <- Sys.time() +partition <- membership(cluster_leiden(G, objective_function = "modularity")) +partition +table(partition) +time10 <- Sys.time() +timing = difftime(time10, time9)[[1]] +print(paste(c("run with igraph:", timing, "seconds"), collapse = " ")) +``` + +The updated leiden package calls this implementation when available. We can see this is considerably faster and may be faster than call leidenalg in Python. + +```{r, eval=module} +time11 <- Sys.time() +partition <- leiden(G, "ModularityVertexPartition", legacy = FALSE) +partition +table(partition) +time12 <- Sys.time() +timing = difftime(time12, time11)[[1]] +print(paste(c("run with leiden in igraph:", timing, "seconds"), collapse = " ")) +``` + +This is considerably faster than the reticulate implementation, especially for larger matrices. + +```{r, eval=module} +time13 <- Sys.time() +partition <- leiden(G, "ModularityVertexPartition", legacy = TRUE) +partition +table(partition) +time14 <- Sys.time() +timing = difftime(time14, time13)[[1]] +print(paste(c("run with leiden with reticulate:", timing, "seconds"), collapse = " ")) +``` + +Matrix methods in R are significantly slower than the updated igraph version. + +```{r, eval=module} +library("Matrix") +adj_mat <- as(as_adjacency_matrix(G), Class = "dgCMatrix") +time15 <- Sys.time() +partition <- leiden(adj_mat, "ModularityVertexPartition", legacy = TRUE) +partition +table(partition) +time16 <- Sys.time() +timing = difftime(time16, time15)[[1]] +print(paste(c("run with leiden with reticulate:", timing, "seconds"), collapse = " ")) +``` + +```{r, eval=module} +adj_mat <- as_adjacency_matrix(G) +time15 <- Sys.time() +partition <- leiden(adj_mat, "ModularityVertexPartition", legacy = TRUE) +partition +table(partition) +time16 <- Sys.time() +timing = difftime(time16, time15)[[1]] +print(paste(c("run with leiden with reticulate:", timing, "seconds"), collapse = " ")) +``` + +#### Benchmarking C in R with igraph + +For comparison with other methods we compute multiple iterations. + +```{r, cache=TRUE, , eval=module} +G <- graph.famous('Zachary') +summary(G) +start <- Sys.time() +for(ii in 1:100){ + partition <- membership(cluster_leiden(G, objective_function = "modularity")) +} +end <- Sys.time() +table(partition) +igraph_time = difftime(end, start)[[1]] +print(paste(c("leiden time:", igraph_time, "seconds"), collapse = " ")) +``` + +```{r, cache=TRUE, , eval=module} +G <- graph.famous('Zachary') +summary(G) +start <- Sys.time() +for(ii in 1:100){ + partition <- leiden(G, "ModularityVertexPartition", legacy = FALSE) +} +end <- Sys.time() +table(partition) +R_cigraph_time = difftime(end, start)[[1]] +print(paste(c("leiden time:", R_cigraph_time, "seconds"), collapse = " ")) +``` + ## Summary Here we compare the compute time for the Zachary datasets between each method for computing paritions from the leiden clustering algorithm in R or Python. ```{r, fig.align = 'center', fig.height = 3, fig.width = 6, fig.keep = 'last', eval=module} -barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, - R_mat_time, R_sparse_mat_time), - names = c("Python (shell)", "Python (Rmd)", "Reticulate", "R igraph", +barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, + R_cigraph_time, igraph_time, R_mat_time, R_sparse_mat_time), + names = c("Python (shell)", "Python (Rmd)", "Reticulate", + "R igraph reticulate", "R igraph (C)", "R igraph cluster_leiden", "R matrix","R dgCMatrix"), col = brewer.pal(9,"Pastel1"), las = 2, srt = 45, ylab = "time (seconds)", main = "benchmarking 100 computations") @@ -721,16 +869,19 @@ If we account for time to cast matrices from graph objects. Then these are the time taken to compute partitions from a graph in R. ```{r, fig.align = 'center', fig.height = 3, fig.width = 6, fig.keep = 'last', eval=module} -barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, R_mat_time+R_mat_cast_time, +barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, + R_cigraph_time, igraph_time, R_mat_time+R_mat_cast_time, R_sparse_mat_time+R_sparse_mat_cast_time), - names = c("Python (shell)", "Python (Rmd)", "Reticulate", "R igraph", + names = c("Python (shell)", "Python (Rmd)", "Reticulate", + "R igraph reticulate", "R igraph (C)", "R igraph cluster_leiden", "R matrix","R dgCMatrix"), col = "grey80", las = 2, srt = 45, ylab = "time (seconds)", main = "benchmarking 100 computations") barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, - R_mat_time, R_sparse_mat_time), - names = c("Python (shell)", "Python (Rmd)", "Reticulate", "R igraph", - "R matrix","R dgCMatrix"), + R_cigraph_time, igraph_time, R_mat_time, R_sparse_mat_time), + names = c("Python (shell)", "Python (Rmd)", "Reticulate", + "R igraph reticulate", "R igraph (C)", "R igraph cluster_leiden", + "R matrix","R dgCMatrix"), col = brewer.pal(9,"Pastel1"), las = 2, srt = 45, ylab = "time (seconds)", main = "benchmarking 100 computations", add = TRUE) abline(h=0) @@ -740,15 +891,17 @@ ```{r, fig.align = 'center', fig.height = 3, fig.width = 6, fig.keep = 'last', eval=module} R_graph_create_time = difftime(time4, time3)[[1]] -barplot(c(bash_py_time, py$py_time+reticulate_create_time*100, reticulate_time+reticulate_create_time*100, R_graph_time+R_graph_create_time*100, R_mat_time, - R_sparse_mat_time), - names = c("Python (shell)", "Python (Rmd)", "Reticulate", "R igraph", +barplot(c(bash_py_time, py$py_time+reticulate_create_time*100, reticulate_time+reticulate_create_time*100, R_graph_time+R_graph_create_time*100, + R_cigraph_time, igraph_time, R_mat_time, R_sparse_mat_time), + names = c("Python (shell)", "Python (Rmd)", "Reticulate", + "R igraph reticulate", "R igraph (C)", "R igraph cluster_leiden", "R matrix","R dgCMatrix"), col = "grey80", las = 2, srt = 45, ylab = "time (seconds)", main = "benchmarking 100 computations") -barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, - R_mat_time, R_sparse_mat_time), - names = c("Python (shell)", "Python (Rmd)", "Reticulate", "R igraph", +barplot(c(bash_py_time, py$py_time, reticulate_time, R_graph_time, + R_cigraph_time, igraph_time, R_mat_time, R_sparse_mat_time), + names = c("Python (shell)", "Python (Rmd)", "Reticulate", + "R igraph reticulate", "R igraph (C)", "R igraph cluster_leiden", "R matrix","R dgCMatrix"), col = brewer.pal(9,"Pastel1"), las = 2, srt = 45, ylab = "time (seconds)", main = "benchmarking 100 computations", add = TRUE) diff -Nru r-cran-leiden-0.3.10+dfsg/vignettes/run_leiden.Rmd r-cran-leiden-0.4.2+dfsg/vignettes/run_leiden.Rmd --- r-cran-leiden-0.3.10+dfsg/vignettes/run_leiden.Rmd 2021-05-24 04:25:32.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/vignettes/run_leiden.Rmd 2022-05-09 12:32:13.000000000 +0000 @@ -157,7 +157,7 @@ ```{r, warning=FALSE, message=FALSE, eval=module} partition <- leiden(adjacency_matrix, max_comm_size = 12) -node.cols <- brewer.pal(max(c(10, partition)),"Pastel1")[partition] +node.cols <- brewer.pal(min(c(9, partition)),"Pastel1")[partition] plot(graph_object, vertex.color = node.cols) ``` diff -Nru r-cran-leiden-0.3.10+dfsg/vignettes/run_multiplex.Rmd r-cran-leiden-0.4.2+dfsg/vignettes/run_multiplex.Rmd --- r-cran-leiden-0.3.10+dfsg/vignettes/run_multiplex.Rmd 2022-04-25 11:51:03.000000000 +0000 +++ r-cran-leiden-0.4.2+dfsg/vignettes/run_multiplex.Rmd 2022-05-09 12:32:13.000000000 +0000 @@ -305,13 +305,13 @@ ```{r, warning=FALSE, message=FALSE, fig.align='center', out.width="80%",fig.height = 6, fig.width = 6, fig.retina=1.5} library("graphsim") library("RColorBrewer") -node.cols <- brewer.pal(max(c(10, partition)),"Pastel1")[partition] +node.cols <- brewer.pal(min(c(9, partition)),"Pastel1")[partition] par(mfrow = c(2, 3)) -plot_directed(multiplex_graph$lunch, main = "lunch", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$work, main = "work", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$facebook, main = "facebook", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$leisure, main = "leisure", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$coauthor, main = "coauthor", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$lunch, main = "lunch", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$work, main = "work", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$facebook, main = "facebook", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$leisure, main = "leisure", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$coauthor, main = "coauthor", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) ``` This can also be run on a list of adjacency matrices giving the same results. @@ -354,13 +354,13 @@ ```{r, warning=FALSE, message=FALSE, fig.align='center', out.width="80%",fig.height = 6, fig.width = 6, fig.retina=1.5} library("graphsim") library("RColorBrewer") -node.cols <- brewer.pal(max(c(10, partition)),"Pastel1")[partition] +node.cols <- brewer.pal(min(c(9, partition)),"Pastel1")[partition] par(mfrow = c(2, 3)) -plot_directed(multiplex_graph$lunch, main = "lunch", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$work, main = "work", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$facebook, main = "facebook", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$leisure, main = "leisure", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$coauthor, main = "coauthor", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$lunch, main = "lunch", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$work, main = "work", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$facebook, main = "facebook", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$leisure, main = "leisure", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$coauthor, main = "coauthor", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) ``` ### Fine-tuning with maximum community size @@ -385,13 +385,13 @@ ```{r, warning=FALSE, message=FALSE, fig.align='center', out.width="80%",fig.height = 6, fig.width = 6, fig.retina=1.5} library("graphsim") library("RColorBrewer") -node.cols <- brewer.pal(max(c(10, partition)),"Pastel1")[partition] +node.cols <- brewer.pal(min(c(9, partition)),"Pastel1")[partition] par(mfrow = c(2, 3)) -plot_directed(multiplex_graph$lunch, main = "lunch", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$work, main = "work", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$facebook, main = "facebook", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$leisure, main = "leisure", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$coauthor, main = "coauthor", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$lunch, main = "lunch", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$work, main = "work", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$facebook, main = "facebook", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$leisure, main = "leisure", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$coauthor, main = "coauthor", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) ``` ### Multiplex cost functions @@ -420,10 +420,10 @@ library("RColorBrewer") node.cols <- brewer.pal(max(c(8, partition)),"Pastel1")[partition] par(mfrow = c(2, 3)) -plot_directed(multiplex_graph$lunch, main = "lunch", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$work, main = "work", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$facebook, main = "facebook", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$leisure, main = "leisure", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) -plot_directed(multiplex_graph$coauthor, main = "coauthor", fill.node = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$lunch, main = "lunch", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[1], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$work, main = "work", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[2], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$facebook, main = "facebook", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[3], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$leisure, main = "leisure", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[4], layout = layout.kamada.kawai) +plot_directed(multiplex_graph$coauthor, main = "coauthor", col.label = node.cols, col.arrow = brewer.pal(5, "Pastel1")[5], layout = layout.kamada.kawai) ```