-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathalgorithms-pe-KINOMO.R
45 lines (34 loc) · 1.13 KB
/
algorithms-pe-KINOMO.R
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
#' @include registry-algorithms.R
NULL
peKINOMO.objective <- function(fit, x, alpha, beta, ...)
{
w <- .basis(fit)
1/2 * sum( (x - fitted(fit))^2 )
+ alpha * ( crossprod(w) - sum(w^2) )
+ beta * sum(.coef(fit))
}
KINOMO_update.peKINOMO <- function(i, x, data, alpha, beta, ...){
# retrieve each factor
w <- .basis(data); h <- .coef(data);
# At the first iteration initialise matrix M
if( TRUE || i == 1 ){
r <- ncol(w)
M <- matrix(1, nrow=r, ncol=r) - diag(1, r)
#staticVar('M', M, init=TRUE)
}
#else M <- staticVar('M')
#precision threshold for numerical stability
eps <- 10^-9
# H_{i+1} = H_i ( W_i^T %*% V ) / ( W_i^T %*% W_i %*% H_i + beta)
h <- h * crossprod(w, x) / ( crossprod(w) %*% h + beta)
# W_{i+1} = W_i ( V %*% H_i^T ) / ( W_i %*% H_i %*% H_i^T + alpha W_i %*% M )
w <- w * tcrossprod(x, h) / ( w %*% tcrossprod(h) + alpha * w %*% M )
#return the modified data
.basis(data) <- w; .coef(data) <- h;
data
}
# register PE-KINOMO
KINOMOAlgorithm.peKINOMO <- setKINOMOMethod('pe-KINOMO', objective = peKINOMO.objective
, model='KINOMOstd'
, Update= KINOMO_update.peKINOMO
, Stop='stationary')