Code Monkey home page Code Monkey logo

sobseq's Introduction

Modern fortran implementation of a Sobol sequence

The Sobol sequence is a low-discrepancy sequence that can be used for more efficient (Quasi-)Monte-Carlo integration.

This repository contains a module, mod_sobseq.f90, which can be used to generate points in Sobol series, in a continuous or strided (2**n) manner.

How to use

To generate sobol sequences in many dimensions, direction numbers are needed. A good set of these was made by Joe and Kuo. The direction numbers for the first eight are reproduced here, and more can be found at the link above.

integer, parameter, dimension(1:12)   :: s = (/1,2,3,3,4,4,5,5,5,5,5,5/)
integer, parameter, dimension(1:12)   :: a = (/0,1,1,2,1,4,2,4,7,11,13,14/)
integer, parameter, dimension(5,1:12) :: m = reshape((/1,0,0,0,0, &
					1,3,0,0,0, &
					1,3,1,0,0, &
					1,1,1,0,0, &
					1,1,3,3,0, &
					1,3,5,13,0,&
					1,1,5,5,17,&
					1,1,5,5,5,&
					1,1,7,11,19,&
					1,1,5,1,1,&
					1,1,1,3,11,&
					1,3,5,5,31/), (/5,12/))

The following code snippet contains a small example.

integer, parameter :: n_dim=9
integer, parameter :: n_samples=200
type(sobol_state), dimension(n_dim) :: rng
integer :: i, j
real :: u(n_dim)

! Initialization
do i=1,n_dim
  call rng%initialize(s(i), a(i), m(:,i))
end do

! Generation
do j=1,n_samples
  do i=1,n_dim
    u(i) = rng(i)%next()
  end do

  ! do something with u
end do

Strided operation

The module also contains functions for generating numbers in a strided manner, which is useful for parallel operation. To use this, set n_streams to the 2-logarithm of the number of streams you want (if n_streams is not a power of 2 you might get distribution problems) and use the rng%next_strided() generator.

Authors

License

This work is released under the MIT license. A copy can be found in the file LICENSE in the repository.

sobseq's People

Contributors

beljaak avatar daanvanvugt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sobseq's Issues

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.