-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathKINOMOstd-class.R
89 lines (70 loc) · 2.14 KB
/
KINOMOstd-class.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#' @include KINOMO-class.R
NULL
#'
setClass('KINOMOstd'
, representation(
W = 'matrix' # basis matrix
, H = 'matrix' # mixture coefficients matrix
, bterms = 'data.frame' # fixed basis terms: nrow(bterms) = nrow(x)
, ibterms = 'integer' # index of the fixed basis terms
, cterms = 'data.frame' # fixed coef terms: ncol(cterms) = ncol(x)
, icterms = 'integer' # index of the fixed coefficient terms
)
, prototype = prototype(
W = matrix(as.numeric(NA), 0, 0),
H = matrix(as.numeric(NA), 0, 0)
)
, validity = function(object){
# dimension compatibility: W and H must be compatible for matrix multiplication
if( ncol(object@W) != nrow(object@H) ){
return(paste('Dimensions of W and H are not compatible [ncol(W)=', ncol(object@W) , '!= nrow(H)=', nrow(object@H), ']'))
}
# give a warning if the dimensions look strange: rank greater than the number of samples
if( !is.empty.KINOMO(object) && ncol(object@H) && ncol(object@W) > ncol(object@H) ){
warning(paste('Dimensions of W and H look strange [ncol(W)=', ncol(object@W) , '> ncol(H)=', ncol(object@H), ']'))
}
# everything went fine: return TRUE
return(TRUE)
}
, contains = 'KINOMO'
)
#'
setMethod('.basis', 'KINOMOstd',
function(object){
object@W
}
)
#' Set the basis matrix in standard KINOMO models
#'
#' This function sets slot \code{W} of \code{object}.
setReplaceMethod('.basis', signature(object='KINOMOstd', value='matrix'),
function(object, value){
object@W <- value
object
}
)
#' Get the mixture coefficient matrix in standard KINOMO models
#'
#' This function returns slot \code{H} of \code{object}.
setMethod('.coef', 'KINOMOstd',
function(object){
object@H
}
)
#' Set the mixture coefficient matrix in standard KINOMO models
#'
#' This function sets slot \code{H} of \code{object}.
setReplaceMethod('.coef', signature(object='KINOMOstd', value='matrix'),
function(object, value){
object@H <- value
object
}
)
#'
setMethod('fitted', signature(object='KINOMOstd'),
function(object, W, H, ...){
if( missing(W) ) W <- object@W
if( missing(H) ) H <- object@H
return(W %*% H)
}
)