20
20
# ' When estimate is TRUE, only the error matrix is returned.
21
21
# ' @param nnlm_args arguments passed to NNLM functions
22
22
# ' @param nnlm_na_perc NA frequency when the cross-validation is performed.
23
+ # ' @param tss perform total sum scaling to the matrix
23
24
# ' @importFrom NMF nmf nmfEstimateRank
24
25
# ' @export
25
26
NMF <- function (stana , species , rank = 3 , target = " KO" , seed = 53 , method = " snmf/r" ,
26
27
deleteZeroDepth = FALSE , beta = 0.01 , estimate = FALSE , estimate_range = 1 : 6 , nnlm_flag = FALSE ,
27
- nnlm_args = list (), nnlm_na_perc = 0.3 ) {
28
+ nnlm_args = list (), nnlm_na_perc = 0.3 , tss = FALSE ) {
28
29
29
30
# # References for the missing value handling in NMF:
30
31
# # https://github.com/scikit-learn/scikit-learn/pull/8474
@@ -51,20 +52,24 @@ NMF <- function(stana, species, rank=3, target="KO", seed=53, method="snmf/r",
51
52
nnlm_flag <- TRUE
52
53
}
53
54
}
55
+ if (tss ) {
56
+ cat_subtle(" # Performing TSS\n " )
57
+ mat <- apply(mat , 2 , function (x ) x / sum(x ))
58
+ }
54
59
cat_subtle(" # Original features: " , dim(mat )[1 ], " \n " , sep = " " )
55
60
cat_subtle(" # Original samples: " , dim(mat )[2 ], " \n " , sep = " " )
56
61
if (! nnlm_flag ) {
57
62
mat <- mat [apply(mat , 1 , function (x ) sum(x )!= 0 ),]
58
63
mat <- mat [,apply(mat , 2 , function (x ) sum(x )!= 0 )]
59
64
60
- cat_subtle(" # Filtered features:" , dim(mat )[1 ], " \n " , sep = " " )
61
- cat_subtle(" # Filtered samples:" , dim(mat )[2 ], " \n " , sep = " " )
65
+ cat_subtle(" # Filtered features: " , dim(mat )[1 ], " \n " , sep = " " )
66
+ cat_subtle(" # Filtered samples: " , dim(mat )[2 ], " \n " , sep = " " )
62
67
}
63
68
64
69
# # Test multiple ranks
65
70
if (estimate ) {
66
71
if (nnlm_flag ) {
67
- cat_subtle(" # NNLM flag enabled, the cross-validation error matrix only will be returned.\n " )
72
+ cat_subtle(" # NNLM flag enabled, the error matrix only will be returned.\n " )
68
73
# # Following the vignette procedures in NNLM
69
74
# # Comparing the MSE and randomly assigned missing values
70
75
A <- as.matrix(mat )
0 commit comments