Skip to content

Commit d819973

Browse files
author
dirmeier
committed
Removed redundant R code
1 parent c6484f6 commit d819973

16 files changed

+152
-268
lines changed

DESCRIPTION

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
Package: diffusr
22
Type: Package
33
Title: Network Diffusion Algorithms
4-
Version: 0.1.1
5-
Authors@R: person("Simon", "Dirmeier", email = "simon.dirmeier@gmx.de", role = c("aut", "cre"))
4+
Version: 0.1.2
5+
Authors@R: person("Simon", "Dirmeier",
6+
email = "simon.dirmeier@gmx.de",
7+
role = c("aut", "cre"))
68
Maintainer: Simon Dirmeier <simon.dirmeier@gmx.de>
7-
Description: Implementation of network diffusion algorithms such as insulated
8-
heat propagation or Markov random walks. Network diffusion algorithms generally
9+
Description: Implementation of network diffusion algorithms such as
10+
heat diffusrion or Markov random walks. Network diffusion algorithms generally
911
spread information in the form of node weights along the edges of a graph to other nodes.
1012
These weights can for example be interpreted as temperature, an initial amount
1113
of water, the activation of neurons in the brain, or the location of a random

R/RcppExports.R

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
22
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
33

4-
insulated_heat_diffusion_ <- function(v0, W, b) {
5-
.Call('diffusr_insulated_heat_diffusion_', PACKAGE = 'diffusr', v0, W, b)
6-
}
7-
8-
laplacian_diffusion_ <- function(v0, W, t) {
9-
.Call('diffusr_laplacian_diffusion_', PACKAGE = 'diffusr', v0, W, t)
4+
heat_diffusion_ <- function(v0, W, t) {
5+
.Call('_diffusr_heat_diffusion_', PACKAGE = 'diffusr', v0, W, t)
106
}
117

128
stoch_col_norm_ <- function(W) {
13-
.Call('diffusr_stoch_col_norm_', PACKAGE = 'diffusr', W)
9+
.Call('_diffusr_stoch_col_norm_', PACKAGE = 'diffusr', W)
1410
}
1511

1612
laplacian_ <- function(W) {
17-
.Call('diffusr_laplacian_', PACKAGE = 'diffusr', W)
13+
.Call('_diffusr_laplacian_', PACKAGE = 'diffusr', W)
1814
}
1915

20-
mrwr_ <- function(p0, W, r) {
21-
.Call('diffusr_mrwr_', PACKAGE = 'diffusr', p0, W, r)
16+
mrwr_ <- function(p0, W, r, thresh, niter, do_analytical) {
17+
.Call('_diffusr_mrwr_', PACKAGE = 'diffusr', p0, W, r, thresh, niter, do_analytical)
2218
}
2319

2420
neighbors_ <- function(node_idxs, W, k) {
25-
.Call('diffusr_neighbors_', PACKAGE = 'diffusr', node_idxs, W, k)
21+
.Call('_diffusr_neighbors_', PACKAGE = 'diffusr', node_idxs, W, k)
2622
}
2723

2824
# Register entry points for exported C++ functions
2925
methods::setLoadAction(function(ns) {
30-
.Call('diffusr_RcppExport_registerCCallable', PACKAGE = 'diffusr')
26+
.Call('_diffusr_RcppExport_registerCCallable', PACKAGE = 'diffusr')
3127
})

R/diffusr-package.R

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# You should have received a copy of the GNU General Public License
1818
# along with diffusr. If not, see <http://www.gnu.org/licenses/>.
1919

20+
2021
#' diffusr
2122
#'
2223
#' Network diffusion algorithms in R.

R/laplacian_heat_diffusion.R renamed to R/heat_diffusion.R

+30-14
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@
1717
# You should have received a copy of the GNU General Public License
1818
# along with diffusr. If not, see <http://www.gnu.org/licenses/>.
1919

20+
2021
#' Graph diffusion using a heat diffusion process on a Laplacian matrix.
2122
#'
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.
2426
#'
2527
#' @export
2628
#' @docType methods
27-
#' @rdname laplacian-diffusion-methods
29+
#' @rdname heat-diffusion-methods
2830
#'
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
3135
#' @param t time point when heat is measured
3236
#' @param ... additional parameters
3337
#' @return returns the heat on every node as numeric vector
@@ -44,34 +48,46 @@
4448
#' # adjacency matrix (either normalized or not)
4549
#' graph <- matrix(abs(rnorm(n*n)), n, n)
4650
#' # computation of stationary distribution
47-
#' ht <- laplacian.heat.diffusion(h0, graph)
51+
#' ht <- heat.diffusion(h0, graph)
4852
setGeneric(
49-
"laplacian.heat.diffusion",
53+
"heat.diffusion",
5054
function(h0, graph, t=.5, ...)
5155
{
5256
standardGeneric("laplacian.heat.diffusion")
5357
},
5458
package="diffusr"
5559
)
5660

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
5963
setMethod(
60-
"laplacian.heat.diffusion",
64+
"heat.diffusion",
6165
signature = signature(h0="numeric", graph="matrix"),
6266
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, ...)
6379
{
6480
stopifnot(length(t) == 1)
6581
if (t < 0) stop("pls provide positive t")
66-
.check.vector(h0)
82+
.check.starting.matrix(h0)
6783
.check.graph(graph, h0)
6884
if (any(diag(graph) != 0))
6985
{
7086
message("setting diag of graph to zero")
7187
diag(graph) <- 0
7288
}
73-
invisible(laplacian_diffusion_(h0,
74-
normalize.laplacian(graph),
75-
t))
89+
invisible(heat_diffusion_(h0,
90+
normalize.laplacian(graph),
91+
t))
7692
}
7793
)

R/insulated_heat_process.R

-79
This file was deleted.

R/mat_util.R

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# You should have received a copy of the GNU General Public License
1818
# along with diffusr. If not, see <http://www.gnu.org/licenses/>.
1919

20+
2021
#' Create a stochastically normalized matrix/vector
2122
#'
2223
#' @export
@@ -40,8 +41,6 @@ normalize.stochastic.numeric <- function(obj, ...)
4041
stop('please provide an object with only non-negative values!')
4142
if (is.matrix(obj))
4243
{
43-
if (nrow(obj) != ncol(obj))
44-
stop('please provide a square matrix!')
4544
if (!all(.equals.double(colSums(obj), 1, .001)))
4645
{
4746
message("normalizing column vectors!")

R/mrw.R

+27-8
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,25 @@
1717
# You should have received a copy of the GNU General Public License
1818
# along with diffusr. If not, see <http://www.gnu.org/licenses/>.
1919

20+
2021
#' Graph diffusion using a Markov random walk
2122
#'
22-
#' @description A Markov Random Walk takes an inital distribution \code{p0} and calculates the stationary distribution of that.
23-
#' The diffusion process is regulated by a restart probability \code{r} which controls how often the MRW jumps back to the initial values.
23+
#' @description A Markov Random Walk takes an inital distribution \code{p0}
24+
#' and calculates the stationary distribution of that.
25+
#' The diffusion process is regulated by a restart probability \code{r} which
26+
#' controls how often the MRW jumps back to the initial values.
2427
#'
2528
#' @export
2629
#' @docType methods
2730
#' @rdname random-walk-methods
2831
#'
29-
#' @param p0 an \code{n}-dimensional numeric non-negative vector representing the starting distribution of the Markov chain (does not need to sum to one)
30-
#' @param graph an (\code{n x n})-dimensional numeric non-negative adjacence matrix representing the graph
31-
#' @param r a scalar between (0, 1). restart probability if a Markov random walk with restart is desired
32+
#' @param p0 an \code{n x p}-dimensional numeric non-negative vector/matrix
33+
#' representing the starting distribution of the Markov chain
34+
#' (does not need to sum to one).
35+
#' @param graph an (\code{n x n})-dimensional numeric non-negative adjacence
36+
#' matrix representing the graph
37+
#' @param r a scalar between (0, 1). restart probability if a Markov random
38+
#' walk with restart is desired
3239
#' @param ... additional parameters
3340
#' @return returns the stationary distribution as numeric vector
3441
#'
@@ -57,17 +64,28 @@ setGeneric(
5764
package="diffusr"
5865
)
5966

60-
6167
#' @rdname random-walk-methods
6268
#' @aliases random.walk,numeric,matrix-method
6369
setMethod(
6470
"random.walk",
6571
signature = signature(p0="numeric", graph="matrix"),
6672
function(p0, graph, r=.5, ...)
73+
{
74+
p0 <- as.matrix(p0, ncol=1)
75+
random.walk(p0, graph, r, ...)
76+
}
77+
)
78+
79+
#' @rdname random-walk-methods
80+
#' @aliases random.walk,matrix,matrix-method
81+
setMethod(
82+
"random.walk",
83+
signature = signature(p0="matrix", graph="matrix"),
84+
function(p0, graph, r=.5, ...)
6785
{
6886
stopifnot(length(r) == 1)
6987
.check.restart(r)
70-
.check.vector(p0)
88+
.check.starting.matrix(p0)
7189
.check.graph(graph, p0)
7290
if (any(diag(graph) != 0))
7391
{
@@ -79,6 +97,7 @@ setMethod(
7997
stop("the provided graph has more than one component. It is likely not ergodic.")
8098
invisible(mrwr_(normalize.stochastic(p0),
8199
stoch.graph,
82-
r))
100+
r)
101+
)
83102
}
84103
)

R/util.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@
5555
}
5656

5757
#' @noRd
58-
.check.vector <- function(v)
58+
.check.starting.matrix <- function(v)
5959
{
6060
name <- deparse(substitute(v))
6161
if (any(v < 0))
6262
stop(paste(name, "can only contain non-negative values!"))
63-
if (!is.vector(v))
64-
stop(paste("vectorial", name, "required"))
63+
if (!is.matrix(v))
64+
stop(paste("matrix-shaped", name, "required"))
6565
}

R/zzz.R

-24
This file was deleted.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ Basically that is all you have to know.
3232

3333
## Author
3434

35-
* Simon Dirmeier <a href="mailto:mail@simon-dirmeier.net">mail@simon-dirmeier.net</a>
35+
* Simon Dirmeier <a href="simon.dirmeier@gmx.de">simon.dirmeier@gmx.de</a>

VERSIONS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ For news and versioning have a look at `inst/NEWS`.
55

66
### Author
77

8-
* Simon Dirmeier <a href="mailto:mail@simon-dirmeier.net">mail@simon-dirmeier.net</a>
8+
* Simon Dirmeier <a href="simon.dirmeier@gmx.de">simon.dirmeier@gmx.de</a>

inst/NEWS

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Versions
22
========
33

4+
### v0.1.2
5+
6+
* Removes `insulated.heat.diffusion`
7+
* Adds matrix inputs for most methods
8+
49
### v0.1.1
510

611
* Updated exported function names to make registering possible
@@ -24,7 +29,7 @@ Versions
2429
* Config, Readme, Travis
2530
* Lintr
2631
* Codecov
27-
* Initial submission to CRAN
32+
* Initial submission to CRAN
2833

2934
### Author
3035

0 commit comments

Comments
 (0)