softSVD: penalized SVD

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/softSVD.R

Description

SVD with sparsity, non-negative and weight constrants

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
softSVD(
  x,
  nf = 1,
  kv = Inf,
  ku = Inf,
  wv = 1,
  wu = 1,
  pos = FALSE,
  maxiter = 50,
  tol = sqrt(.Machine$double.eps),
  verbose = FALSE
)

Arguments

x

the matrix to be decomposed

nf

the number of components want to computed

kv

the number of nonzero coefficients for the right regularized sigular vectors

ku

the number of nonzero coefficients for the left regularized sigular vectors

wv

the weight for columns of x

wu

the weight for rows of of x

pos

Logical value, if only retain non-negative values in the

maxiter

the maximum number of iteration

tol

the tolerance of error

verbose

print progress of calulation

Details

The algorithm use a generalized version of NIPALS algorithm to allow sparsity, force non-negative values on both left and rigth singular vectors. In addition, different weghted could be introduced, the columns/rows with bigger weights are more likely to be selected.

Value

the same as svd, list of three components, d, u, v

Author(s)

Chen Meng

See Also

svd

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#' a random matrix
x <- matrix(rnorm(50), 5, 10)
ss <- svd(x)
ss2 <- softSVD(x, nf = 5)
ss$d
ss2$d
all.equal(abs(ss$u), abs(ss2$u))
all.equal(abs(ss$v), abs(ss2$v))

#' NCI60 data
library(mogsa)
data("NCI60_4arrays")
#
d <- as.matrix(NCI60_4arrays$agilent)

###' compare with svd
ss <- svd(d, nu = 5, nv = 5)
ss2 <- softSVD(d, nf = 5)
ss$d
ss2$d
all.equal(abs(ss$u), abs(ss2$u))
all.equal(abs(ss$v), abs(ss2$v))

#' normalize the data
dt <- scale(t(d), scale = FALSE)
pp <- softSVD(x = dt, nf = 5, kv = 30, ku = 6, maxiter = 100)
barplot(pp$u[, 1], col = as.factor(substr(colnames(d), 1, 2)))
barplot(pp$v[, 1])

#' change sparsity
dt <- scale(t(d), scale = FALSE)
pp <- softSVD(x = dt, nf = 5, kv = 30, ku = 9, maxiter = 1000, pos = TRUE)
i <- 2
barplot(pp$u[, i], col = as.factor(substr(colnames(d), 1, 2)), las=2, names.arg = rownames(dt))
barplot(pp$v[, i])

#' change sparsity
pp <- softSVD(x = dt, nf = 5, kv = Inf, ku = 9, maxiter = 1000, pos = TRUE)
i <- 1
barplot(pp$u[, i], col = as.factor(substr(colnames(d), 1, 2)), las=2, names.arg = rownames(dt))
barplot(pp$v[, i])

#' change sparsity
pp <- softSVD(x = dt, nf = 5, kv = 30, ku = Inf, maxiter = 1000, pos = FALSE)
i <- 1
barplot(pp$u[, i], col = as.factor(substr(colnames(d), 1, 2)), las=2, names.arg = rownames(dt))
barplot(pp$v[, i])

#' use weight
w <- rowSums(d - min(d))
w <- w + max(w) #' prefer to select high intensity genes

pw <- softSVD(x = dt, nf = 6, kv = 30, ku = Inf, wv = w, maxiter = 1000, pos = FALSE, verbose = TRUE)
i <- 6
barplot(pw$u[, i], col = as.factor(substr(colnames(d), 1, 2)), las=2, names.arg = rownames(dt))
barplot(pw$v[, i])


i1 <- apply(pp$v, 1, function(x) any(x!=0))
i2 <- apply(pw$v, 1, function(x) any(x!=0))
plot(pw$u[, 1], pp$u[, 1])
layout(matrix(1:2, 1, 2))
hist(d[i1 & !i2, ], main = "No weight")
hist(d[i2 & !i1, ], main = "Weight")

mengchen18/mogsa documentation built on June 7, 2020, 6:05 p.m.