Timeline for Moving average function in C++ for use with R
Current License: CC BY-SA 3.0
11 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Apr 10, 2018 at 15:19 | answer | added | zexot | timeline score: 2 | |
Apr 2, 2018 at 23:01 | comment | added | flodel |
Thanks Joshua. Nonetheless, filter will be orders of magnitude faster than rollapply so the OP's "10,000x slower" comment can't apply to both (and I seriously doubt it applies to filter ).. I wish the accepted answer's timings had included a filter based solution to see where it stands. As one has to weigh-in speed improvements versus the added complexity of writing and maintaining Rcpp code.
|
|
Apr 1, 2018 at 15:04 | comment | added | Joshua Ulrich |
@flodel: stats::filter() converts its input to ts , has multiple sanity checks for the various types of filters it supports, and loops over columns of the mts object before it gets to the C code. That results in a lot of intermediate memory allocations, which (I'm sure you know) can slow things down considerably for larger objects. The speed gains aren't from Rcpp, per-se. They're from omitting all the conversions and checks.
|
|
Mar 26, 2018 at 16:03 | vote | accept | Frostic | ||
Mar 26, 2018 at 2:16 | answer | added | Joseph Wood | timeline score: 7 | |
Mar 24, 2018 at 0:31 | comment | added | flodel |
filter is implemented in C so that's a bit surprising. I was expecting a bit of a slowdown compared to Rcpp but not that much... Rcpp it is, then! I hope you get help with your review.
|
|
Mar 24, 2018 at 0:29 | comment | added | Frostic |
filter , rollapply and most R built-in function are about 10000 slower than this for my 10^7 sized vectors
|
|
Mar 24, 2018 at 0:26 | comment | added | flodel |
Not a Rcpp expert so I can't help with a formal review... But if you were interested in a base R implementation, you could use the filter function. roll_mean <- function(x, w) as.vector(filter(x, w)) / sum(w) will get you almost there. You'll just have to deal with the end parts.
|
|
Mar 23, 2018 at 19:38 | history | edited | 200_success | CC BY-SA 3.0 |
edited tags; edited title
|
Mar 23, 2018 at 18:50 | review | First posts | |||
Mar 23, 2018 at 18:51 | |||||
Mar 23, 2018 at 18:47 | history | asked | Frostic | CC BY-SA 3.0 |