Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ LinkingTo:
RcppEigen
Imports:
matrixStats,
lbfgsb3c,
dplyr,
rBeta2009,
reshape2,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ importFrom(dplyr,across)
importFrom(dplyr,everything)
importFrom(dplyr,group_by)
importFrom(dplyr,summarise)
importFrom(lbfgsb3c,lbfgsb3)
importFrom(matrixStats,rowVars)
importFrom(parallel,detectCores)
importFrom(pcaMethods,prep)
Expand Down
2 changes: 1 addition & 1 deletion R/DICEPRO.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#'
#' result <- DICEPRO(reference = data_simulation$reference,
#' bulk = data_simulation$bulk,
#' methodDeconv = "CSx",
#' methodDeconv = "DCQ",
#' W_prime = 0,
#' bulkName = "Bulk_Sample",
#' refName = "Reference_Data",
Expand Down
12 changes: 6 additions & 6 deletions R/NMF_optim.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
#' @param lambda_ Regularization parameter (optional, defaults to 10). It is a scalar.
#' @param gamma_par Penalty factor for the sum of cell type proportions (optional, defaults to 100). It is a scalar.
#' @param N_unknownCT Number of unknown cell types to model (optional, defaults to 1). It is a scalar.
#' @param con A list of control parameters for the optimization process passed to `optim` (optional).
#' - `fnscale`: Scaling factor for the objective function (optional, defaults to 1).
#' @param con A list of control parameters for the optimization process passed to `lbfgs3c` (optional).
#' - `maxit`: Maximum number of iterations (optional, defaults to 5000).
#' - `tmax`: Maximum number of function evaluations (optional, defaults to 50).
#'
#' @return A list containing:
#' - `w`: The optimized matrix W, a vector of length N_gene.
Expand All @@ -30,11 +28,12 @@
#'
#' @importFrom stats optim
#' @importFrom stats sd
#' @importFrom lbfgsb3c lbfgsb3
#'
#' @export

nmf_lbfgsb <- function(r_dataset, W_prime = 0, p_prime = 0, lambda_ = 10, gamma_par = 100,
N_unknownCT = 1, con = list(fnscale = 1, maxit = 3e3, tmax = 30)) {
N_unknownCT = 1, con = list(maxit = 3e3)) {
B <- as.matrix(r_dataset$B)
p_cb <- r_dataset$P_cb
W_cb <- r_dataset$W_cb
Expand Down Expand Up @@ -83,7 +82,7 @@ nmf_lbfgsb <- function(r_dataset, W_prime = 0, p_prime = 0, lambda_ = 10, gamma_
return(grad)
}

result <- try(optim(par = theta, fn = obj_fun, gr = grad_obj_fun,
result <- try(lbfgsb3c::lbfgsb3c(par = theta, fn = obj_fun, gr = grad_obj_fun,
lower = c(rep(0, length(theta) - 1), 1e-6),
upper = c(rep(Inf, N_gene * N_cellsType), rep(1, N_sample * N_cellsType), Inf),
control = con, method = "L-BFGS-B"), silent=TRUE)
Expand Down Expand Up @@ -120,7 +119,8 @@ nmf_lbfgsb <- function(r_dataset, W_prime = 0, p_prime = 0, lambda_ = 10, gamma_
frobNorm = obj_term1_opt, constNorm = obj_term2_opt, c1 = obj_term3_opt, c2 = obj_term4_opt,
objectiveValue = obj_term1_opt+obj_term2_opt, penalty = obj_term3_opt + obj_term4_opt,
cvrge = result$convergence,
constraint = abs(1 - constraints))
constraint = abs(1 - constraints),
iternum <- result$counts[1])
return(results)
}
}
9 changes: 9 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
reticulate::py_require("scikit-learn")
reticulate::py_require("scipy")
reticulate::py_require("pandas")
reticulate::py_require("deflate")
reticulate::py_require("rpy2")
reticulate::py_require("matplotlib")
reticulate::py_require("lightgbm")
reticulate::py_require("seaborn")
reticulate::py_require("hyperopt")
reticulate::py_require("reservoirpy")

# rpy2_import <- try(reticulate::import("rpy2"), silent = TRUE)
# if(inherits(rpy2_import, "try-error")){
# stop("Python module `rpy2` is missing. ",
# "Try installing it by running the following R command in the console:\n",
# "reticulate::py_install('rpy2')")
# }

}
2 changes: 1 addition & 1 deletion man/DICEPRO.Rd

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

6 changes: 2 additions & 4 deletions man/nmf_lbfgsb.Rd

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