QuasiMonteCarlo.jl: Quasi-Monte Carlo (QMC) Samples Made Easy
QuasiMonteCarlo.jl is a lightweight package for generating Quasi-Monte Carlo (QMC) samples using various different methods.
Installation
To install QuasiMonteCarlo.jl, use the Julia package manager:
using Pkg
Pkg.add("QuasiMonteCarlo")
Example
using QuasiMonteCarlo, Distributions
lb = [0.1,-0.5]
ub = [1.0,20.0]
n = 5
d = 2
s = QuasiMonteCarlo.sample(n,lb,ub,GridSample([0.1,0.5]))
s = QuasiMonteCarlo.sample(n,lb,ub,UniformSample())
s = QuasiMonteCarlo.sample(n,lb,ub,SobolSample())
s = QuasiMonteCarlo.sample(n,lb,ub,LatinHypercubeSample())
s = QuasiMonteCarlo.sample(n,lb,ub,LatticeRuleSample())
s = QuasiMonteCarlo.sample(n,lb,ub,LowDiscrepancySample([10,3]))
The output s
is a matrix, so one can use things like @uview
from UnsafeArrays.jl for a stack-allocated view of the i
th point:
using UnsafeArrays
@uview s[:,i]
Adding a new sampling method
Adding a new sampling method is a two-step process:
- Add a new SamplingAlgorithm type.
- Overload the sample function with the new type.
All sampling methods are expected to return a matrix with dimension d
by n
, where d
is the dimension of the sample space and n
is the number of samples.
Example
struct NewAmazingSamplingAlgorithm{OPTIONAL} <: SamplingAlgorithm end
function sample(n,lb,ub,::NewAmazingSamplingAlgorithm)
if lb isa Number
...
return x
else
...
return reduce(hcat, x)
end
end
Contributing
- Please refer to the SciML ColPrac: Contributor's Guide on Collaborative Practices for Community Packages for guidance on PRs, issues, and other matters relating to contributing to SciML.
- There are a few community forums:
- the #diffeq-bridged channel in the Julia Slack
- JuliaDiffEq on Gitter
- on the Julia Discourse forums
- see also SciML Community page