Giter VIP home page Giter VIP logo

ghalton's Introduction

Generalized Halton Number Generator

This library allows to generate quasi-random numbers according to the generalized Halton sequence. For more information on Generalized Halton Sequences, their properties, and limits see Braaten and Weller (1979), Faure and Lemieux (2009), and De Rainville et al. (2012) and reference therein.

The library is compatible Python 2 and Python 3.

Install with pip

Simply type in

$ pip install ghalton

Building the Code

To build the code you'll need a working C++ compiler.

$ python setup.py install

Using the Library

The library contains two generators one producing the standard Halton sequence and the other a generalized version of it. The former constructor takes a single argument, which is the dimensionalty of the sequence.

import ghalton
sequencer = ghalton.Halton(5)

The last code will produce a sequence in five dimension. To get the points use

points = sequencer.get(100)

A list of 100 lists will be produced, each sub list will containt 5 points

print(points[0])
# [0.5, 0.3333, 0.2, 0.1429, 0.0909]

The halton sequence produce points in sequence, to reset it call sequencer.reset().

The generalised Halton sequence constructor takes at least one argument, either the dimensionality, or a configuration. When the dimensionality is given, an optional argument can be used to seed for the random permutations created.

import ghalton
sequencer = ghalton.GeneralizedHalton(5, 68)
points = sequencer.get(100)
print(points[0])
# [0.5, 0.6667, 0.4, 0.8571, 0.7273]

A configuration is a series of permutations each of n_i numbers, where n_i is the n_i'th prime number. The dimensionality is infered from the number of sublists given.

import ghalton
perms = ((0, 1),
         (0, 2, 1),
         (0, 4, 2, 3, 1),
         (0, 6, 5, 4, 3, 2, 1),
         (0, 8, 2, 10, 4, 9, 5, 6, 1, 7, 3))
sequencer = ghalton.GeneralizedHalton(perms)
points = sequencer.get(100)
print(points[0])
# [0.5, 0.6667, 0.8, 0.8571, 0.7273]

The configuration presented in De Rainville et al. (2012) is available in the ghalton module. Use the first dim dimensions of the EA_PERMS constant. The maximum dimensionality provided is 100.

import ghalton
dim = 5
sequencer = ghalton.GeneralizedHalton(ghalton.EA_PERMS[:dim])
points = sequencer.get(100)
print(points[0])
# [0.5, 0.6667, 0.8, 0.8571, 0.7273]

The complete API is presented on read the docs.

Building the SWIG wrapper

In the main directory use command

swig -Wall -c++ -python -outdir ghalton src/Halton.i 

Configuration Repository

See the Quasi Random Sequences Repository for more configurations.

References

E. Braaten and G. Weller. An improved low-discrepancy sequence for multidi- mensional quasi-Monte Carlo integration. J. of Comput. Phys., 33(2):249-258, 1979.

F.-M. De Rainville, C. Gagné, O. Teytaud, D. Laurendeau. Evolutionary optimization of low-discrepancy sequences. ACM Trans. Model. Comput. Simul., 22(2):1-25, 2012.

H. Faure and C. Lemieux. Generalized Halton sequences in 2008: A comparative study. ACM Trans. Model. Comput. Simul., 19(4):1-43, 2009.

ghalton's People

Contributors

dmaljovec avatar fmder avatar jpn-- avatar liz2020 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.