pyQMC
Python Scripts for Lattice Rules
pyQMC is a simple Python library available at this project page containing tools for the evaluation of lattice rules and interlaced polynomial lattice (IPL) rules. Note that these scripts are not optimized, and focus on elucidating the properties of IPL rules. This library does not contain any algorithms for the construction of generating vectors, but is compatible with the generating vectors published on this site.
Introduction
The following files are provided with this library.
File | Description |
---|---|
lattice.py | contains representations of lattices: Lattice , PolynomialLattice classes. |
weights.py | contains weight parametrizations, see below. |
Representation of Weights
Weights are represented as classes with the following members:
Name | Description |
---|---|
name |
human-readable name of the weights |
archivename |
unique string representing the name of the weights, as in the archive |
paramlist |
an ordered Python list of strings representing the parameters |
Instantiating Weight Classes
Weight classes are instantiated with a list of parameters of length at most that of paramlist
,
where the ordering is the same as that in paramlist
.
Available Weights
Weights are implemented in the file weights.py
.
Name | Type | Parameters |
---|---|---|
PROD_tz | product | theta, zeta |
PROD_INV_tz | product | theta, zeta |
SPOD_tz | SPOD | theta, zeta, q |
SPOD_2dstaircase | SPOD | t, q, zeta |
Examples
We give here some example usage of these scripts.
For more, see the bin/
directory of the code archive,
available at the
project page.
Loading lattices
A polynomial lattice can be loaded by passing the name of a file containing the generating vector
and the number of desired dimensions to the constructor of PolynomialLattice
.
from pyQMC.lattice import PolynomialLattice
# name of file containing generating vector
filename = "standard_spod_a2_C0.1_SPOD_TZ_t0.2_z2/SPOD_t2.000e-01_z2.000e+00_m5.json"
# number of dimensions
s = 16
lat = PolynomialLattice(filename, s)
for p in lat:
print p
Quadrature
This example shows how to approximate the integral of a function satisfying derivative bounds required to ensure membership of a weighted space with SPOD weights and decay $\beta_j \sim j^{-\zeta}$. The integrand is given by the following expression (see also [Gantner and Schwab 2014] for detailed experiments involving this function).
from numpy import arange, array, dot, polyfit, log
from pyQMC.lattice import PolynomialLattice, quadrature
# generating vectors (value for m to be inserted with '%m')
filename = "standard_spod_a2_C0.1_SPOD_TZ_t0.2_z2/SPOD_t2.000e-01_z2.000e+00_m%d.json"
# dimension
s = 128
# integrand
fct = lambda y: 1./(1+0.2*dot(y,arange(1,s+1)**(-2.)))
# values for convergence study
mvals = arange(1,7) # increase this to use more points
Q = []
for m in mvals:
lat = PolynomialLattice(filename%m, s)
Q.append(quadrature(lat, fct))
E = abs(array(Q[:-1])-Q[-1]) # errors using last as reference
p = polyfit(log(2**mvals[:-1]), log(E), 1)
print "measured convergence rate:", p[0]