Coder Social home page Coder Social logo

Winner Winner Chicken Dinner 🎉 about m181 HOT 3 OPEN

dimfalk avatar dimfalk commented on August 17, 2024
Winner Winner Chicken Dinner 🎉

from m181.

Comments (3)

dimfalk avatar dimfalk commented on August 17, 2024 1

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.

dleutnant avatar dleutnant commented on August 17, 2024

Cool - thank you! May I ask you to provide the code of your analysis?

from m181.

dleutnant avatar dleutnant commented on August 17, 2024

Thanks!

from m181.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.