Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floating Point Precision Issues in 1.1.2 vs. 1.1.3 #24

Closed
yilisg opened this issue Nov 11, 2019 · 2 comments
Closed

Floating Point Precision Issues in 1.1.2 vs. 1.1.3 #24

yilisg opened this issue Nov 11, 2019 · 2 comments
Labels

Comments

@yilisg
Copy link

yilisg commented Nov 11, 2019

Hi Jason,

Thanks for the great package. I've recently upgraded from 1.1.2 to 1.1.3 and it has broken some of my existing code (in another package I've written). After tracking down the issue, it seems that roll_sd is returning 0 if the values and weights are too small. This was not a problem in 1.1.2.

Here's a minimal reproducible example.

library(roll)
getNamespaceVersion("roll") # 1.1.2

set.seed(42)
x <- matrix(runif(100)) / 1000
width <- 10
x_sd_large_wts_112  <- roll_sd(x, width = width, weights = rep(1, width))
x_sd_small_wts_112  <- roll_sd(x, width = width, weights = rep(0.01, width))

all.equal(x_sd_large_wts_112, x_sd_small_wts_112) # TRUE
tail(x_sd_large_wts_112) # some small numbers
tail(x_sd_small_wts_112) # some small numbers

After upgrading to the new release,

detach("package:roll", unload=TRUE)
install.packages("roll")
library(roll)
getNamespaceVersion("roll") # 1.1.3

set.seed(42)
x <- matrix(runif(100)) / 1000
width <- 10
x_sd_large_wts_113  <- roll_sd(x, width = width, weights = rep(1, width))
x_sd_small_wts_113  <- roll_sd(x, width = width, weights = rep(0.01, width))

all.equal(x_sd_large_wts_113, x_sd_small_wts_113) # FALSE
tail(x_sd_large_wts_113) # some small numbers
tail(x_sd_small_wts_113) # all zeros

Thanks for looking into this!

@jasonjfoster
Copy link
Owner

Thanks for the report. I have fixed the issue in the development version:

# devtools::install_github("jjf234/roll")

library(roll)

set.seed(42)
x <- matrix(runif(100)) / 1000
width <- 10
x_sd_large_wts_113  <- roll_sd(x, width = width, weights = rep(1, width))
x_sd_small_wts_113  <- roll_sd(x, width = width, weights = rep(0.01, width))

> all.equal(x_sd_large_wts_113, x_sd_small_wts_113) # some small numbers
[1] TRUE

For reference, I removed some (overly) restrictive conditions that were added in version 1.1.3.

@yilisg
Copy link
Author

yilisg commented Nov 15, 2019

Thanks Jason for the quick reply. I can confirm that the issue is fixed in the dev version. I am closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants