3838# '
3939# ' @param thresh threshold for breaking the iterative computation of the
4040# ' stationary distribution. If the absolute difference of the distribution at
41- # ' time point $ t-1$ and $t$ is less than \code{thresh}, then the algorithm stops.
42- # ' If \code{thresh} is not reached before \code{niter}, then the algorithm stops
43- # ' as well.
41+ # ' time point \eqn{ t-1} and \eqn{t} is less than \code{thresh}, then the
42+ # ' algorithm stops. If \code{thresh} is not reached before \code{niter}, then
43+ # ' the algorithm stops as well.
4444# '
4545# ' @param niter maximal number of iterations for computation of the
4646# ' Markov chain. If \code{thresh} is not reached, then \code{niter} is used as
6262# ' @return returns a list with the following elements
6363# ' \itemize{
6464# ' \item p.inf the stationary distribution as numeric vector
65- # ' \item transition.matrix the column normalized transition matrix used for the random walk
65+ # ' \item transition.matrix the column normalized transition matrix used for
66+ # ' the random walk
6667# ' }
6768# '
6869# ' @references
6970# ' Tong, H., Faloutsos, C., & Pan, J. Y. (2006),
70- # ' Fast random walk with restart and its applications.\cr \cr
71+ # ' Fast random walk with restart and its applications.
72+ # '
7173# ' Koehler, S., Bauer, S., Horn, D., & Robinson, P. N. (2008),
7274# ' Walking the interactome for prioritization of candidate disease genes.
73- # ' \emph{The American Journal of Human Genetics}\cr \cr
75+ # ' \emph{The American Journal of Human Genetics}
7476# '
7577# ' @export
7678# '
7779# ' @useDynLib diffusr
7880# '
79- # ' @importFrom checkmate assert_number assert_int assert_logical test_numeric assert test_matrix check_numeric
81+ # ' @importFrom checkmate assert_number assert_int assert_logical test_numeric
82+ # ' assert test_matrix check_numeric
8083# ' @importFrom Rcpp sourceCpp
8184# '
8285# ' @examples
9093# ' pt <- random.walk(p0, graph)
9194# '
9295random.walk <- function (p0 , graph , r = 0.5 , niter = 1e4 , thresh = 1e-4 ,
93- do.analytical = FALSE , correct.for.hubs = FALSE ,
94- ergodic.tolerance = FALSE , return .pt.only = FALSE ) {
96+ do.analytical = FALSE , correct.for.hubs = FALSE ,
97+ ergodic.tolerance = FALSE , return .pt.only = FALSE ) {
9598 # # Check the fucking inputs
96- assert_number(r , lower = 0 , upper = 1 , na.ok = FALSE , finite = TRUE , null.ok = FALSE )
99+ assert_number(r , lower = 0 , upper = 1 , na.ok = FALSE , finite = TRUE ,
100+ null.ok = FALSE )
97101 assert_int(niter , lower = 2 , na.ok = FALSE , coerce = TRUE , null.ok = FALSE )
98- assert_number(thresh , lower = 0 , na.ok = FALSE , finite = TRUE , null.ok = FALSE )
99- assert_logical(do.analytical , len = 1 , any.missing = FALSE , all.missing = FALSE , null.ok = FALSE )
100- assert_logical(correct.for.hubs , len = 1 , any.missing = FALSE , all.missing = FALSE , null.ok = FALSE )
102+ assert_number(thresh , lower = 0 , na.ok = FALSE , finite = TRUE ,
103+ null.ok = FALSE )
104+ assert_logical(do.analytical , len = 1 , any.missing = FALSE ,
105+ all.missing = FALSE , null.ok = FALSE )
106+ assert_logical(correct.for.hubs , len = 1 , any.missing = FALSE ,
107+ all.missing = FALSE , null.ok = FALSE )
101108
102109 # graph must be either matrix or dgCMatrix
103110 n_elements <- nrow(graph )
104111 if (is.dgCMatrix(graph )) {
105112 assert_dgCMatrix(graph )
106113 sparse <- TRUE
114+ # TODO: sparse matrix
107115 } else {
108116 assert(
109- test_matrix(graph , mode = ' numeric' , nrows = n_elements , ncols = n_elements , min.rows = 3 , any.missing = FALSE , all.missing = FALSE , null.ok = FALSE ),
117+ test_matrix(graph , mode = " numeric" , min.rows = 3 , nrows = n_elements ,
118+ ncols = n_elements , any.missing = FALSE , all.missing = FALSE ,
119+ null.ok = FALSE ),
110120 any(graph > = 0 ),
111- combine = ' and'
121+ combine = " and"
112122 )
113123 sparse <- FALSE
114124 }
115125
116126 # convert p0 if p0 is vector
117- if (test_numeric(p0 , lower = 0 , len = n_elements , finite = TRUE , any.missing = FALSE , all.missing = FALSE , null.ok = FALSE )) {
127+ if (test_numeric(p0 , lower = 0 , len = n_elements , finite = TRUE ,
128+ any.missing = FALSE , all.missing = FALSE , null.ok = FALSE )) {
118129 p0 <- as.matrix(p0 )
119130 } else {
120131 assert(
121- test_matrix(p0 , mode = ' numeric' , nrows = n_elements , any.missing = FALSE , all.missing = FALSE , null.ok = FALSE ),
132+ test_matrix(p0 , mode = " numeric" , nrows = n_elements , any.missing = FALSE ,
133+ all.missing = FALSE , null.ok = FALSE ),
122134 any(p0 > = 0 ),
123- combine = ' and'
135+ combine = " and"
124136 )
125137 }
126138
@@ -136,11 +148,9 @@ random.walk <- function(p0, graph, r = 0.5, niter = 1e4, thresh = 1e-4,
136148 }
137149
138150 l <- mrwr_(normalize.stochastic(p0 ),
139- stoch.graph , r , thresh , niter , do.analytical )
151+ stoch.graph , r , thresh , niter , do.analytical )
140152 if (! return .pt.only ) {
141- l <- list (
142- p.inf = l ,
143- transition.matrix = stoch.graph )
153+ l <- list (p.inf = l , transition.matrix = stoch.graph )
144154 }
145155
146156 return (l )
0 commit comments