Skip to content

Commit

Permalink
Set random state in umap-learn method; #5194
Browse files Browse the repository at this point in the history
  • Loading branch information
timoast committed Oct 22, 2021
1 parent 9740698 commit 025b4c0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions R/dimensional_reduction.R
Original file line number Diff line number Diff line change
Expand Up @@ -1265,18 +1265,23 @@ RunUMAP.default <- function(
if (!py_module_available(module = 'umap')) {
stop("Cannot find UMAP, please install through pip (e.g. pip install umap-learn).")
}
if (!py_module_available(module = 'sklearn')) {
stop("Cannot find sklearn, please install through pip (e.g. pip install scikit-learn).")
}
if (!is.null(x = seed.use)) {
py_set_seed(seed = seed.use)
}
if (typeof(x = n.epochs) == "double") {
n.epochs <- as.integer(x = n.epochs)
}
umap_import <- import(module = "umap", delay_load = TRUE)
sklearn <- import("sklearn", delay_load = TRUE)
if (densmap &&
numeric_version(x = umap_import$pkg_resources$get_distribution("umap-learn")$version) <
numeric_version(x = "0.5.0")) {
stop("densmap is only supported by versions >= 0.5.0 of umap-learn. Upgrade umap-learn (e.g. pip install --upgrade umap-learn).")
}
random.state <- sklearn$utils$check_random_state(seed = as.integer(x = seed.use))
umap.args <- list(
n_neighbors = as.integer(x = n.neighbors),
n_components = as.integer(x = n.components),
Expand All @@ -1289,6 +1294,7 @@ RunUMAP.default <- function(
local_connectivity = local.connectivity,
repulsion_strength = repulsion.strength,
negative_sample_rate = negative.sample.rate,
random_state = random.state,
a = a,
b = b,
metric_kwds = metric.kwds,
Expand Down

0 comments on commit 025b4c0

Please sign in to comment.