зеркало из https://github.com/microsoft/wpa.git
Merge pull request #222 from microsoft/fix/make-louvain-deterministic
Bugfix: make Louvain implementation in `network_p2p()` deterministic (#221)
This commit is contained in:
Коммит
2a6bd724f2
|
@ -60,8 +60,10 @@
|
|||
#' of the edges (only for 'ggraph' mode). Defaults to 1.
|
||||
#' @param res Resolution parameter to be passed to `leiden::leiden()`. Defaults
|
||||
#' to 0.5.
|
||||
#' @param seed Seed for the random number generator passed to `leiden::leiden()`
|
||||
#' to ensure consistency. Only applicable when `display` is set to `"leiden"`.
|
||||
#' @param seed Seed for the random number generator passed to either
|
||||
#' `set.seed()` when the Louvain algorithm is used, or `leiden::leiden()` when
|
||||
#' the Leiden algorithm is used, to ensure consistency. Only applicable when
|
||||
#' `display` is set to `"louvain"` or `"leiden"`.
|
||||
#' @param algorithm String to specify the node placement algorithm to be used.
|
||||
#' Defaults to `"mds"` for the deterministic multi-dimensional scaling of
|
||||
#' nodes. See
|
||||
|
@ -241,24 +243,26 @@ network_p2p <- function(data,
|
|||
|
||||
} else if(display == "louvain"){
|
||||
|
||||
## Convert to undirected
|
||||
g_ud <- igraph::as.undirected(g_raw)
|
||||
set.seed(seed = seed)
|
||||
|
||||
## Return a numeric vector of partitions / clusters / modules
|
||||
## Set a low resolution parameter to have fewer groups
|
||||
## weights = NULL means that if the graph as a `weight` edge attribute, this
|
||||
## will be used by default.
|
||||
lc <- igraph::cluster_louvain(g_ud, weights = NULL)
|
||||
## Convert to undirected
|
||||
g_ud <- igraph::as.undirected(g_raw)
|
||||
|
||||
## Add cluster
|
||||
g <-
|
||||
g_ud %>%
|
||||
# Add louvain partitions to graph object
|
||||
igraph::set_vertex_attr("cluster", value = as.character(igraph::membership(lc))) %>% # Return membership - diff from Leiden
|
||||
igraph::simplify()
|
||||
## Return a numeric vector of partitions / clusters / modules
|
||||
## Set a low resolution parameter to have fewer groups
|
||||
## weights = NULL means that if the graph as a `weight` edge attribute, this
|
||||
## will be used by default.
|
||||
lc <- igraph::cluster_louvain(g_ud, weights = NULL)
|
||||
|
||||
## Name of vertex attribute
|
||||
v_attr <- "cluster"
|
||||
## Add cluster
|
||||
g <-
|
||||
g_ud %>%
|
||||
# Add louvain partitions to graph object
|
||||
igraph::set_vertex_attr("cluster", value = as.character(igraph::membership(lc))) %>% # Return membership - diff from Leiden
|
||||
igraph::simplify()
|
||||
|
||||
## Name of vertex attribute
|
||||
v_attr <- "cluster"
|
||||
|
||||
} else if(display == "leiden"){
|
||||
|
||||
|
|
|
@ -44,8 +44,10 @@ of the nodes. Defaults to 0.7.}
|
|||
\item{res}{Resolution parameter to be passed to \code{leiden::leiden()}. Defaults
|
||||
to 0.5.}
|
||||
|
||||
\item{seed}{Seed for the random number generator passed to \code{leiden::leiden()}
|
||||
to ensure consistency. Only applicable when \code{display} is set to \code{"leiden"}.}
|
||||
\item{seed}{Seed for the random number generator passed to either
|
||||
\code{set.seed()} when the Louvain algorithm is used, or \code{leiden::leiden()} when
|
||||
the Leiden algorithm is used, to ensure consistency. Only applicable when
|
||||
\code{display} is set to \code{"louvain"} or \code{"leiden"}.}
|
||||
|
||||
\item{desc_hrvar}{Character vector of length 3 containing the HR attributes
|
||||
to use when returning the \code{"describe"} output. See \code{network_describe()}.}
|
||||
|
|
|
@ -86,8 +86,10 @@ of the edges (only for 'ggraph' mode). Defaults to 1.}
|
|||
\item{res}{Resolution parameter to be passed to \code{leiden::leiden()}. Defaults
|
||||
to 0.5.}
|
||||
|
||||
\item{seed}{Seed for the random number generator passed to \code{leiden::leiden()}
|
||||
to ensure consistency. Only applicable when \code{display} is set to \code{"leiden"}.}
|
||||
\item{seed}{Seed for the random number generator passed to either
|
||||
\code{set.seed()} when the Louvain algorithm is used, or \code{leiden::leiden()} when
|
||||
the Leiden algorithm is used, to ensure consistency. Only applicable when
|
||||
\code{display} is set to \code{"louvain"} or \code{"leiden"}.}
|
||||
|
||||
\item{algorithm}{String to specify the node placement algorithm to be used.
|
||||
Defaults to \code{"mds"} for the deterministic multi-dimensional scaling of
|
||||
|
|
Загрузка…
Ссылка в новой задаче