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
bug

Comments

@yilisg
Copy link

@yilisg 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!

@jjf234
Copy link
Owner

@jjf234 jjf234 commented Nov 15, 2019

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 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.

@yilisg yilisg closed this Nov 15, 2019
@jjf234 jjf234 added the bug label Nov 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.