This module provides an implementation of rank-1 lattice rules. Lattice rules generate "quasi-random" sequences of points in
d dimensions which are equally distributed over the
d-dimensional unit cube [0,1]d.
To initialize a rank-1 lattice rule
d dimensions, use
using LatticeRules my_lattice = LatticeRule(d)
returns the first point of the lattice, and
kth point of the lattice.
gives an approximation for the integral of
N lattice points.
Providing your own generating vector
z is possible with
my_other_lattice = LatticeRule(z, d, n)
n is the maximum number of points in the lattice.
In practice, it is more useful to have a shifted rank-1 lattice rule
my_shifted_lattice = ShiftedLatticeRule(d)
to obtain an error estimate in the same way as in the Monte Carlo method.
An existing lattice rule can be turned into a randomly shifted lattice rule using
my_other_shifted_lattice = ShiftedLatticeRule(my_lattice)
shift = rand(ndims(my_lattice)) my_final_shifted_lattice = ShiftedLatticeRule(my_lattice, shift)
optionally providing the random shift vector
More extensive documentation can be found here.
A classic toy example to illustrate the Monte Carlo method is to approximate the value of π by throwing random darts on a square board. Suppose we draw a circle on the board with a diameter equal to the length of one side of the square. Then, the ratio of the area of the circle to the area of the square is π/4. If we now repeatedly throw darts at random on the board, the ratio of the number of darts that landed inside the circle and the total number of darts, multiplied by 4, is an approximation to π.
First, generate a lattice rule in two dimensions.
using LatticeRules, Statistics my_lattice = LatticeRule(2)
inside_circle checks if a dart is inside the circle:
inside_circle(x) = x*x + x*x < 1
Our approximation for the value of π is
Q = 4 * mean(inside_circle.(collect(my_lattice)))
Q = 3.1416015625.
- The "Magic Point Shop" of QMC point generators and generating vectors by D. Nuyens
- Lattice rule generating vectors by F. Y. Kuo.