1<%@include file="includes/setup.md.rsp"%>
2
3<%@string colname="colMads"%>
4<%@string rowname="rowMads"%>
5<%@meta title="${colname}() and ${rowname}() benchmarks"%>
6<%@meta author="Henrik Bengtsson"%>
7<%@meta date="2014-11-18"%>
8
9<%@include file="${header}"%>
10
11
12# <%@meta name="title"%>
13
14This report benchmark the performance of <%=colname%>() and <%=rowname%>() against alternative methods.
15
16## Alternative methods
17
18* apply() + mad()
19* colMads2() and rowMads2()
20
21where `rowMads2()` and `colMads2()` are:
22
23```r
24<%=withCapture({
25rowMads2 <- function(x, const = 1.4826, na.rm = FALSE) {
26  mu <- rowMedians(x, na.rm = na.rm)
27  x <- abs(x - mu)
28  mad <- rowMedians(x, na.rm = FALSE)
29  const * mad
30}
31
32colMads2 <- function(x, const = 1.4826, na.rm = FALSE) {
33  mu <- colMedians(x, na.rm = na.rm)
34  x <- abs(x - mu)
35  mad <- colMedians(x, na.rm = FALSE)
36  const * mad
37}
38})%>
39```
40
41<%
42rowMads_R <- function(x, na.rm = FALSE) {
43 apply(x, MARGIN = 1L, FUN = mad, na.rm = na.rm)
44}
45
46colMads_R <- function(x, na.rm = FALSE) {
47 apply(x, MARGIN = 2L, FUN = mad, na.rm = na.rm)
48}
49%>
50
51
52<% for (mode in c("integer", "double")) { %>
53
54## Data type "<%=mode%>"
55
56### Data
57```r
58<%=withCapture({
59<%@include file="R/random-matrices.R"%>
60data <- rmatrices(mode = mode)
61})%>
62```
63
64### Results
65
66<% for (dataLabel in names(data)) { %>
67<% mprintf("%s: %s\n", mode, dataLabel)  %>
68#### <%=dataLabel%> <%=mode%> matrix
69
70```r
71<%=withCapture({
72X <- data[[.dataLabel.]]
73gc()
74
75colStats <- microbenchmark(
76 colMads     = colMads(X, na.rm = FALSE),
77 colMads2    = colMads2(X, na.rm = FALSE),
78 "apply+mad" = apply(X, MARGIN = 2L, FUN = mad, na.rm = FALSE),
79 unit = "ms"
80)
81
82X <- t(X)
83gc()
84
85rowStats <- microbenchmark(
86 rowMads     = rowMads(X, na.rm = FALSE),
87 rowMads2    = rowMads2(X, na.rm = FALSE),
88 "apply+mad" = apply(X, MARGIN = 1L, FUN = mad, na.rm = FALSE),
89 unit = "ms"
90)
91})%>
92```
93
94<% crBenchmarkResults(colStats, rowStats, tags=c(mode, dataLabel)) %>
95
96<% } # for (dataLabel ...) %>
97
98<% } # for (mode ...) %>
99
100
101<%@include file="${footer}"%>
102
103
104<%---------------------------------------------------------------------------
105HISTORY:
1062014-11-17
107o Created.
108---------------------------------------------------------------------------%>
109