A Julia package for rank-1 lattice rules
Author PieterjanRobbe
2 Stars
Updated Last
2 Years Ago
Started In
May 2020


Documentation Build Status Coverage
Stable Dev Build Status Build Status Build Status Coverage Coverage

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 lattice_rule in d dimensions, use

using LatticeRules
my_lattice = LatticeRule(d)


getpoint(my_lattice, 0)



returns the first point of the lattice, and


returns the kth point of the lattice.

For a d-dimensional function f,


gives an approximation for the integral of f using N lattice points.

Providing your own generating vector z is possible with

my_other_lattice = LatticeRule(z, d, n)

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

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)

The function inside_circle checks if a dart is inside the circle:

inside_circle(x) = x[1]*x[1] + x[2]*x[2] < 1

Our approximation for the value of π is

Q = 4 * mean(inside_circle.(collect(my_lattice)))

with Q = 3.1416015625.

See also

Required Packages

No packages found.