Skip to content

Commit

Permalink
fixing issue with k_min
Browse files Browse the repository at this point in the history
  • Loading branch information
zdebruine committed Feb 28, 2024
1 parent 9901661 commit e8b9eff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 4 additions & 0 deletions R/RunNMF.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ RunNMF.Seurat <- function(object,
nmf_model <- ard_nmf(
A = A,
k_init = k,
k_max = 1e4,
k_min = 2,
n_replicates = reps,
tol = tol,
maxit = maxit,
Expand Down Expand Up @@ -286,6 +288,8 @@ RunNMF.SingleCellExperiment <- function(object,
nmf_model <- ard_nmf(
A = A,
k_init = k,
k_max = 1e4,
k_min = 2,
n_replicates = reps,
tol = tol,
maxit = maxit,
Expand Down
7 changes: 2 additions & 5 deletions R/ard_nmf.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ ard_nmf <- function(A, k_init = 2, k_max = 100, k_min = 2, n_replicates = 1, tol
warning("'test_density' should not be greater than 0.2 or less than 0.01, as a general rule of thumb")
}

if (is.null(k_init) || is.na(k_init) || k_init < k_min) k_init <- k_min

if (k_min < 2) stop("k_min cannot be less than 2")

if (k_init < k_min) stop("k_init cannot be less than k_min")

if (k_init > k_max) stop("k_init cannot be greater than k_max")

if ("list" %in% class(A)) {
# check that number of rows is identical
if (var(sapply(A, nrow)) != 0) {
Expand Down Expand Up @@ -94,7 +92,6 @@ ard_nmf <- function(A, k_init = 2, k_max = 100, k_min = 2, n_replicates = 1, tol
test_seed <- abs(.Random.seed[[3]])
df <- data.frame("k" = integer(), "rep" = integer(), "test_error" = double(), "iter" = integer(), "tol" = double(), "overfit_score" = double())
class(df) <- c("cross_validate_nmf_data", "data.frame")
if (is.null(k_init) || is.na(k_init) || k_init < k_min) k_init <- k_min
for (curr_rep in 1:n_replicates) {
if (verbose >= 1 && n_replicates > 1) cat("\nREPLICATE ", curr_rep, "/", n_replicates, "\n")

Expand Down

0 comments on commit e8b9eff

Please sign in to comment.