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

Enable low-discrepancy (quasi-random) numbers in addition to pseudorandom numbers #141

Closed
KronosTheLate opened this issue Apr 16, 2024 · 2 comments

Comments

@KronosTheLate
Copy link

It has recently come to my attention that low-discrepancy sequences could be used in monte-carlo simulations for faster convergence. The benefit is that you require fewer points before the points truly represent the probability distribution. I quickly thought that this faster convergence should definitively be made use of in this package.

Suggestion: I would love the ability to chose a different samples via some option like set_sampler!(:sobol) (defaulting to set_sampler!(:prng). This would make it so that all current code could be used without modification. It also makes sense to make it a global setting, as I guess users would want to use the same sampler in all cases for a given script.

Alternatively, one could of course set a sampler as one constructs the particles (Particles(100, Uniform(0,2), :prng)), but that does not compose well with the nice unicode plus-minus constructor, which to me feels like incentivising users to not use non-default samplers, as it does not allow the same nice syntax. But if the global setting is a bad idea for some reason, this would be much better than nothing.

Below is some (python) code and a reference that I used personally, which might help to get started:

#From https://www.youtube.com/watch?v=DbFJdjpTPok
from scipy import stats
from scipy.stats import qmc

def sobol(m, d=1):
    sampler = qmc.Sobol(d, scramble=True)
    #return sampler.random_base2(m)  #! This would ensure balance properties
    return sampler.random(m)

def soboln(m):
    return stats.norm.ppf(sobol(m))

def sobol_balanced(m, d=1):
    sampler = qmc.Sobol(d, scramble=True)
    return sampler.random_base2(m)

def soboln_balanced(m):
    return stats.norm.ppf(sobol_balanced(m))
@baggepinnen
Copy link
Owner

@KronosTheLate
Copy link
Author

Oh, that is really nice! My bad then. I guess I just assumed that is this package did this, it would be advertised more and at an earlier place in the documentation/readme. But I can hardly complain when there is a dedicated page explaining both how the samples are drawn, and the benefits ^_^

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

No branches or pull requests

2 participants