2025-01-12 00:52:51 +08:00

77 lines
1.3 KiB
Plaintext

<%@include file="includes/setup.md.rsp"%>
<%@string fcnname="logSumExp"%>
<% fcnname <- "<%@string name="fcnname"%>" %>
<%@meta title="${fcnname}() benchmarks"%>
<%@meta author="Henrik Bengtsson"%>
<%@meta date="2014-11-01"%>
<%@include file="${header}"%>
# <%@meta name="title"%>
This report benchmark the performance of <%=fcnname%>() against alternative methods.
## Alternative methods
* logSumExp_R()
where
```r
<%=withCapture({
logSumExp_R <- function(lx, ...) {
iMax <- which.max(lx)
log1p(sum(exp(lx[-iMax] - lx[iMax]))) + lx[iMax]
} # logSumExp_R()
})%>
```
## Data
```r
<%=withCapture({
<%@include file="R/random-vectors.R"%>
data <- rvectors(mode = "double")
data <- data[1:4]
})%>
```
## Results
<% for (ii in seq_along(data)) { %>
<%
dataLabel <- names(data)[ii]
message(dataLabel)
x <- data[[dataLabel]]
gc()
%>
### <%=dataLabel%> vector
```r
<%=withCapture({
x <- data[[.dataLabel.]]
gc()
stats <- microbenchmark(
"logSumExp" = logSumExp(x),
"logSumExp_R" = logSumExp_R(x),
unit = "ms"
)
})%>
```
<% benchmarkResults(stats, tags=dataLabel) %>
<% } # for (ii ...) %>
<%@include file="${footer}"%>
<%---------------------------------------------------------------------------
HISTORY:
2014-11-01
o Created.
---------------------------------------------------------------------------%>