6'''Sobol sampling. The original Python implementation was based on sobol.cc.
9http://web.maths.unsw.edu.au/%7Efkuo/sobol/index.html
11And the following explanations:
12http://web.maths.unsw.edu.au/~fkuo/sobol/joe-kuo-notes.pdf
14-----------------------------------------------------------------------------
17Email: <f.kuo@unsw.edu.au>
18School of Mathematics and Statistics
19University of New South Wales
20Sydney NSW 2052, Australia
22Last updated: 21 October 2008
24You may incorporate this source code into your own program
26 1) acknowledge the copyright owner in your program and publication
27 2) notify the copyright owner by email
28 3) offer feedback regarding your experience with different direction numbers
30-----------------------------------------------------------------------------
31Licence pertaining to sobol.cc and the accompanying sets of direction numbers
32-----------------------------------------------------------------------------
33Copyright (c) 2008, Frances Y. Kuo and Stephen Joe
36Redistribution and use in source and binary forms, with or without
37modification, are permitted provided that the following conditions are met:
39 * Redistributions of source code must retain the above copyright
40 notice, this list of conditions and the following disclaimer.
42 * Redistributions in binary form must reproduce the above copyright
43 notice, this list of conditions and the following disclaimer in the
44 documentation and/or other materials provided with the distribution.
46 * Neither the names of the copyright holders nor the names of the
47 University of New South Wales and the University of Waikato
48 and its contributors may be used to endorse or promote products derived
49 from this software without specific prior written permission.
51THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
52EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
53WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
54DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
55DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
56(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
57LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
58ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
60SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61-----------------------------------------------------------------------------
63from __future__
import print_function
64from __future__
import absolute_import
65from __future__
import unicode_literals
66from __future__
import division
69from operator
import index
70from scipy.stats
import norm, qmc
71from ._directions
import DIRECTIONS_D6_21201
73__all__ = [
'gen_sobol_vectors',
'gen_sobol_randn']
82def gen_sobol_vectors(num, dim):
83 """Return the requested number of Sobol points, skipping the origin.
85 SciPy generates the unscrambled 32-bit Joe–Kuo sequence. Requests
86 for zero points return an empty array with the requested width.
88 :param num: Number of points, from zero through 2**32 - 1.
89 :param dim: Number of coordinates, from one through 21,201.
90 :returns: Floating-point array of shape (num, dim).
91 :raises ValueError: If the requested count or dimension is outside
96 if not 0 <= num < 2**32:
97 raise ValueError(
"The sample count must be between 0 and 2**32 - 1.")
98 if not 1 <= dim <= len(DIRECTIONS_D6_21201) + 1:
99 raise ValueError(f
"The Sobol dimension must be between 1 and {len(DIRECTIONS_D6_21201) + 1}.")
101 return np.empty((0, dim))
102 sampler = qmc.Sobol(dim, scramble=
False, bits=32)
106 return sampler.random(num)
109def gen_sobol_randn(num):
110 """Transform one-dimensional Sobol points into quasi-normal samples.
112 Applying the inverse standard-normal CDF to the origin-free
113 sequence gives finite samples with no random generator state.
115 return norm.ppf(gen_sobol_vectors(num, 1)[:, 0])