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

Implementation of scrambled Van der Corput sequence differs from the referenced paper #14193

Closed
treverhines opened this issue Jun 6, 2021 · 5 comments · Fixed by #14449
Closed
Milestone

Comments

@treverhines
Copy link
Contributor

I noticed a potential issue with the function scipy.stats._qmc.van_der_corput. That function is based on Algorithm 1 in this paper:

https://arxiv.org/pdf/1706.02808.pdf

However, there is a difference between the scipy implementation and the algorithm from that paper. In Algorithm 1, the last line in the while loop is res <- (res - dig) / b, but the scipy implementation is effectively doing res <- (res - pdig) / b, using the variable names from Algorithm 1. This difference does amount to different output sequences.

Since dig is res mod b, the line res <- (res - dig) /b is just integer division. The scipy implementation can then be made consistent with the referenced algorithm by changing this line:

quotient = (quotient - remainder) / base

to

quotient //= base

I am currently working on cythonizing van_der_corput (see the discussion here: #13474), so I can also make the change in that PR (which I will probably make today).

@tupui
Copy link
Member

tupui commented Jun 7, 2021

Thanks for reporting. But not sure this would work for the scrambled case as there is a permutation happening on the remainder.

FYI, a good way to check that you did not break anything is to look at the convergence plots in stats' tutorial.

@treverhines
Copy link
Contributor Author

treverhines commented Jun 7, 2021

Sorry for not being more clear. I am saying that the algorithm in Owen 2017 (which is for the scrambled case) is subtracting the unpermuted remainder in the last line of the while loop, but the current implementation is subtracting the permuted remainder.

Thanks for pointing out the convergence plots. I will check that out.

@tupui
Copy link
Member

tupui commented Jun 7, 2021

Oh ok no my bad I did not click the reference you pointed out. I did this with Art. I will dig up my emails and see if we talked about that

@tupui
Copy link
Member

tupui commented Jul 20, 2021

@treverhines just checking in 😃 Did you get some time here?

Looking a bit more at what you said. I think you are right even if it seems to not have a huge impact. I have quickly redone the convergence plots following what I did back then (https://gist.github.com/tupui/ee6e685219c06c429338569e7ee7ff2a) and we have the right convergence rate. Although I would need to get both versions on the same curve to be sure. Anyway, thanks again for the finding.

@tupui
Copy link
Member

tupui commented Jul 20, 2021

I did the plots and there is basically no change. So feel free to do it in the same PR as it would be closer to the published algorithm 😃

Just showing one the results using my script here https://gist.github.com/tupui/ee6e685219c06c429338569e7ee7ff2a
Screenshot 2021-07-20 at 19 51 04

@tupui tupui linked a pull request Jul 22, 2021 that will close this issue
@tylerjereddy tylerjereddy added this to the 1.8.0 milestone Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants