Skip to content

Commit

Permalink
add target_weight argument
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt committed Jan 10, 2024
1 parent ee5183f commit 3f8ebf1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion R/umap.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#' one of `"spectral"`, `"normlaplacian"`, `"random"`, `"lvrandom"`,
#' `"laplacian"`, `"pca"`, `"spca"`, `"agspectral"`, or a matrix of initial
#' coordinates. See [uwot::umap()] for more details. Default to `"spectral"`.
#' @param target_weight Weighting factor between data topology and target
#' topology. A value of 0.0 weights entirely on data, a value of 1.0 weights
#' entirely on target. The default of 0.5 balances the weighting equally
#' between data and target.
#' @param learn_rate Positive number of the learning rate for the optimization
#' process.
#' @param outcome A call to `vars` to specify which variable is used as the
Expand Down Expand Up @@ -110,6 +114,7 @@ step_umap <-
learn_rate = 1,
epochs = NULL,
initial = "spectral",
target_weight = 0.5,
options = list(verbose = FALSE, n_threads = 1),
seed = sample(10^5, 2),
prefix = "UMAP",
Expand Down Expand Up @@ -149,6 +154,7 @@ step_umap <-
learn_rate = learn_rate,
epochs = epochs,
initial = initial,
target_weight = target_weight,
options = options,
seed = seed,
prefix = prefix,
Expand All @@ -163,7 +169,7 @@ step_umap <-

step_umap_new <-
function(terms, role, trained, outcome, neighbors, num_comp, min_dist, metric,
learn_rate, epochs, initial, options, seed, prefix,
learn_rate, epochs, initial, target_weight, options, seed, prefix,
keep_original_cols, retain, object, skip, id) {
step(
subclass = "umap",
Expand All @@ -178,6 +184,7 @@ step_umap_new <-
learn_rate = learn_rate,
epochs = epochs,
initial = initial,
target_weight = target_weight,
options = options,
seed = seed,
prefix = prefix,
Expand Down Expand Up @@ -205,6 +212,7 @@ umap_fit_call <- function(obj, y = NULL) {
cl$learning_rate <- obj$learn_rate
cl$min_dist <- obj$min_dist
cl$metric <- obj$metric
cl$target_weight <- obj$target_weight
if (length(obj$options) > 0) {
cl <- rlang::call_modify(cl, !!!obj$options)
}
Expand Down Expand Up @@ -246,6 +254,7 @@ prep.step_umap <- function(x, training, info = NULL, ...) {
learn_rate = x$learn_rate,
epochs = x$epochs,
initial = x$initial,
target_weight = x$target_weight,
options = x$options,
seed = x$seed,
prefix = x$prefix,
Expand Down
6 changes: 6 additions & 0 deletions man/step_umap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3f8ebf1

Please sign in to comment.