knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
The dtt provides discrete trigonometric transforms, but unfortunately the implementation is rather slow.
Following the suggestion of
Stackoverflow
tsrecipes includes a faster discrete cosine transform based off of
stats::fft
and stats::mvfft
that are included in R.
library(dtt) library(tsrecipes) library(tidyverse)
ts <- prices$ts[[1]] dct_dtt <- dtt::dct bench_ts <- bench::mark( fdct(ts), dct_dtt(ts) ) bench_ts %>% select(expression, min, median, mem_alloc)
dct_so_apply <- function(l) { l %>% simplify2array() %>% t() %>% apply(1, fdct) %>% t() } dct_so_mv <- function(l) { l %>% simplify2array() %>% mvfdct() %>% t() } dct_dtt_apply <- function(l) { l %>% simplify2array() %>% t() %>% apply(1, dtt::dct) %>% t() } dct_dtt_mv <- function(l) { l %>% simplify2array() %>% t() %>% dct() } ts_list <- prices$ts bench_tsdb <- bench::mark( dct_dtt_apply(ts_list), dct_dtt_mv(ts_list), dct_so_apply(ts_list), dct_so_mv(ts_list) ) bench_tsdb %>% select(expression, min, median, mem_alloc)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.