|
17 | 17 | # You should have received a copy of the GNU General Public License |
18 | 18 | # along with diffusr. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
|
| 20 | + |
20 | 21 | #' Graph diffusion using a heat diffusion process on a Laplacian matrix. |
21 | 22 | #' |
22 | | -#' @description An amount of starting heat gets distribution using the Laplacian matrix of a graph. |
23 | | -#' Every iteration (or time interval) \code{t} heat streams from the starting nodes into surrounding nodes. |
| 23 | +#' @description An amount of starting heat gets distribution using the |
| 24 | +#' Laplacian matrix of a graph. Every iteration (or time interval) \code{t} |
| 25 | +#'heat streams from the starting nodes into surrounding nodes. |
24 | 26 | #' |
25 | 27 | #' @export |
26 | 28 | #' @docType methods |
27 | | -#' @rdname laplacian-diffusion-methods |
| 29 | +#' @rdname heat-diffusion-methods |
28 | 30 | #' |
29 | | -#' @param h0 an \code{n}-dimensional numeric non-negative vector of starting temperatures |
30 | | -#' @param graph an (\code{n x n})-dimensional numeric non-negative adjacence matrix representing the graph |
| 31 | +#' @param h0 an \code{n x p}-dimensional numeric non-negative vector/matrix |
| 32 | +#' of starting temperatures |
| 33 | +#' @param graph an (\code{n x n})-dimensional numeric non-negative adjacence |
| 34 | +#' matrix representing the graph |
31 | 35 | #' @param t time point when heat is measured |
32 | 36 | #' @param ... additional parameters |
33 | 37 | #' @return returns the heat on every node as numeric vector |
|
44 | 48 | #' # adjacency matrix (either normalized or not) |
45 | 49 | #' graph <- matrix(abs(rnorm(n*n)), n, n) |
46 | 50 | #' # computation of stationary distribution |
47 | | -#' ht <- laplacian.heat.diffusion(h0, graph) |
| 51 | +#' ht <- heat.diffusion(h0, graph) |
48 | 52 | setGeneric( |
49 | | - "laplacian.heat.diffusion", |
| 53 | + "heat.diffusion", |
50 | 54 | function(h0, graph, t=.5, ...) |
51 | 55 | { |
52 | 56 | standardGeneric("laplacian.heat.diffusion") |
53 | 57 | }, |
54 | 58 | package="diffusr" |
55 | 59 | ) |
56 | 60 |
|
57 | | -#' @rdname laplacian-diffusion-methods |
58 | | -#' @aliases laplacian.heat.diffusion,numeric,matrix-method |
| 61 | +#' @rdname heat-diffusion-methods |
| 62 | +#' @aliases heat.diffusion,numeric,matrix-method |
59 | 63 | setMethod( |
60 | | - "laplacian.heat.diffusion", |
| 64 | + "heat.diffusion", |
61 | 65 | signature = signature(h0="numeric", graph="matrix"), |
62 | 66 | function(h0, graph, t=.5, ...) |
| 67 | + { |
| 68 | + h0 <- as.matrix(h0, ncol=1) |
| 69 | + heat.diffusion(h0, graph, t, ...) |
| 70 | + } |
| 71 | +) |
| 72 | + |
| 73 | +#' @rdname heat-diffusion-methods |
| 74 | +#' @aliases heat.diffusion,matrix,matrix-method |
| 75 | +setMethod( |
| 76 | + "heat.diffusion", |
| 77 | + signature = signature(h0="matrix", graph="matrix"), |
| 78 | + function(h0, graph, t=.5, ...) |
63 | 79 | { |
64 | 80 | stopifnot(length(t) == 1) |
65 | 81 | if (t < 0) stop("pls provide positive t") |
66 | | - .check.vector(h0) |
| 82 | + .check.starting.matrix(h0) |
67 | 83 | .check.graph(graph, h0) |
68 | 84 | if (any(diag(graph) != 0)) |
69 | 85 | { |
70 | 86 | message("setting diag of graph to zero") |
71 | 87 | diag(graph) <- 0 |
72 | 88 | } |
73 | | - invisible(laplacian_diffusion_(h0, |
74 | | - normalize.laplacian(graph), |
75 | | - t)) |
| 89 | + invisible(heat_diffusion_(h0, |
| 90 | + normalize.laplacian(graph), |
| 91 | + t)) |
76 | 92 | } |
77 | 93 | ) |
0 commit comments