Comments (3)
Sure, here you go:
# init xts
start <- as.POSIXct("2000-01-01 00:10", tz = "UTC")
datetimes <- seq(start, by = "10 min", length.out = 1440)
set.seed(42)
values <- rnorm(1440, mean = 18, sd = 0.2) |> round(1)
xts <- xts::xts(values, order.by = datetimes)
# source code
download.file("https://raw.githubusercontent.com/dleutnant/m181/master/src/m181_criteria_core.cpp",
"m181_criteria_core.cpp")
Rcpp::sourceCpp("m181_criteria_core.cpp")
# benchmark
mbm <- microbenchmark::microbenchmark("zoo::rollapply(..., FUN = 'sd')" = zoo::rollapply(xts, width = 3, FUN = "sd", align = "right", fill = NA),
"RcppRoll::roll_sd()" = RcppRoll::roll_sd(xts, n = 3, na.rm = TRUE, align = "right", fill = NA),
"roll::roll_sd()" = roll::roll_sd(xts, width = 3),
"m181::.run_sd()" = .run_sd(xts, 3),
times = 1000)
ggplot2::autoplot(mbm)
mbm
#> Unit: microseconds
#> expr min lq mean median
#> zoo::rollapply(..., FUN = 'sd') 46643.301 50739.552 54175.61539 52776.351
#> RcppRoll::roll_sd() 348.001 376.201 463.11189 391.301
#> roll::roll_sd() 66.601 73.802 118.33781 107.551
#> m181::.run_sd() 21.001 22.701 41.93832 26.401
#> uq max neval
#> 56414.8510 113090.201 1000
#> 412.7505 9413.201 1000
#> 115.6510 16506.401 1000
#> 32.1010 13083.401 1000
Of course this is not 100 % representative since the classes returned differ, but the numeric part seems to be the same:
roll_zoo <- zoo::rollapply(xts, width = 3, FUN = "sd", align = "right", fill = NA)
class(roll_zoo)
#> [1] "xts" "zoo"
as.numeric(roll_zoo) |> head(10)
#> [1] NA NA 0.20000000 0.11547005 0.00000000 0.05773503
#> [7] 0.15275252 0.17320508 0.20816660 0.23094011
roll_rcpproll <- RcppRoll::roll_sd(xts, n = 3, na.rm = TRUE, align = "right", fill = NA)
class(roll_rcpproll)
#> [1] "matrix" "array"
as.numeric(roll_rcpproll) |> head(10)
#> [1] NA NA 0.20000000 0.11547005 0.00000000 0.05773503
#> [7] 0.15275252 0.17320508 0.20816660 0.23094011
roll_roll <- roll::roll_sd(xts, width = 3)
class(roll_roll)
#> [1] "xts" "zoo"
as.numeric(roll_roll) |> head(10)
#> [1] NA NA 0.20000000 0.11547005 0.00000000 0.05773503
#> [7] 0.15275252 0.17320508 0.20816660 0.23094011
roll_m181 <- .run_sd(xts, 3)
class(roll_m181)
#> [1] "numeric"
as.numeric(roll_m181) |> head(10)
#> [1] NA NA 0.20000000 0.11547005 0.00000000 0.05773503
#> [7] 0.15275252 0.17320508 0.20816660 0.23094011
from m181.
Cool - thank you! May I ask you to provide the code of your analysis?
from m181.
Thanks!
from m181.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from m181.