From b9511111eb7fc11f42bee8eab72d9b934ab71978 Mon Sep 17 00:00:00 2001 From: noriakis <31095487+noriakis@users.noreply.github.com> Date: Tue, 22 Oct 2024 18:25:18 +0900 Subject: [PATCH] scaler --- R/utils.R | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/R/utils.R b/R/utils.R index f16ba1f..dba3b08 100644 --- a/R/utils.R +++ b/R/utils.R @@ -33,6 +33,27 @@ setGroup <- function(stana, cl) { } + +#' @noRd +scaler.NNLM <- function(nmf, target="coef") { + if (target=="basis") { + scaledW <- apply(nmf$W, 2, function(x) x / sum(x)) + Sii <- apply(nmf$W, 2, function(x) sum(x)) + scaledH <- apply(nmf$H, 2, function(x) { + x * Sii + }) + list("W"=scaledW, "H"=scaledH) + } else { + scaledH <- apply(nmf$H, 1, function(x) x / sum(x)) %>% t() + Sii <- apply(nmf$H, 1, function(x) sum(x)) + scaledW <- apply(nmf$W, 1, function(x) { + x * Sii + }) %>% t() + list("W"=scaledW, "H"=scaledH) + } + +} + #' returnGenes #' return corresponding genes queried by SNV position #' @param stana stana object