/usr/local/lib64/python3.6/site-packages/torch/__pycache__
Edit: /usr/local/lib64/python3.6/site-packages/torch/__pycache__/quasirandom.cpython-36.pyc (6739B)
3
EgA @ s( d dl Z d dlmZ G dd deZdS ) N)Optionalc @ s e Zd ZdZdZdZdddZddejfe e
ej ejejd d
dZ
dejfe e
ej ejejdd
dZdd Zdd Zdd Zdd ZdS )SobolEnginea
The :class:`torch.quasirandom.SobolEngine` is an engine for generating
(scrambled) Sobol sequences. Sobol sequences are an example of low
discrepancy quasi-random sequences.
This implementation of an engine for Sobol sequences is capable of
sampling sequences up to a maximum dimension of 21201. It uses direction
numbers from https://web.maths.unsw.edu.au/~fkuo/sobol/ obtained using the
search criterion D(6) up to the dimension 21201. This is the recommended
choice by the authors.
References:
- Art B. Owen. Scrambling Sobol and Niederreiter-Xing points.
Journal of Complexity, 14(4):466-489, December 1998.
- I. M. Sobol. The distribution of points in a cube and the accurate
evaluation of integrals.
Zh. Vychisl. Mat. i Mat. Phys., 7:784-802, 1967.
Args:
dimension (Int): The dimensionality of the sequence to be drawn
scramble (bool, optional): Setting this to ``True`` will produce
scrambled Sobol sequences. Scrambling is
capable of producing better Sobol
sequences. Default: ``False``.
seed (Int, optional): This is the seed for the scrambling. The seed
of the random number generator is set to this,
if specified. Otherwise, it uses a random seed.
Default: ``None``
Examples::
>>> soboleng = torch.quasirandom.SobolEngine(dimension=5)
>>> soboleng.draw(3)
tensor([[0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
[0.5000, 0.5000, 0.5000, 0.5000, 0.5000],
[0.7500, 0.2500, 0.2500, 0.2500, 0.7500]])
iR FNc C s || j ks|dk r$td| j d|| _|| _|| _tjd}tj|| j|tj d| _
tj| j
| j | jstj| j|tj d| _n| j
| jjtjd| _| jd| j jdd | _d| _d S )
N z9Supported range of dimensionality for SobolEngine is [1, ]cpu)devicedtype)Z
memory_format r )MAXDIM
ValueErrorseedscramble dimensiontorchr ZzerosMAXBITlong
sobolstateZ_sobol_engine_initialize_state_shift _scramblecloneZcontiguous_formatquasiZreshape_first_point
num_generated)selfr r r r r =/usr/local/lib64/python3.6/site-packages/torch/quasirandom.py__init__/ s
zSobolEngine.__init__r )noutr returnc C s | j dkr^|dkr | jj|}qtj| j|d | j| j| j |d\}| _tj| j|fdd}n(tj| j|| j| j| j d |d\}| _| j |7 _ |dk r|j |j
| |S |S )at
Function to draw a sequence of :attr:`n` points from a Sobol sequence.
Note that the samples are dependent on the previous samples. The size
of the result is :math:`(n, dimension)`.
Args:
n (Int, optional): The length of sequence of points to draw.
Default: 1
out (Tensor, optional): The output tensor
dtype (:class:`torch.dtype`, optional): the desired data type of the
returned tensor.
Default: ``torch.float32``
r r )r r
)ZdimN)r r Ztor Z_sobol_engine_drawr r r catZ
resize_as_copy_)r r r r resultr r r drawF s
$$zSobolEngine.draw)mr r r! c C sF d| }| j | }||d @ dks6tdj| j ||| j|||dS )aR
Function to draw a sequence of :attr:`2**m` points from a Sobol sequence.
Note that the samples are dependent on the previous samples. The size
of the result is :math:`(2**m, dimension)`.
Args:
m (Int): The (base2) exponent of the number of points to draw.
out (Tensor, optional): The output tensor
dtype (:class:`torch.dtype`, optional): the desired data type of the
returned tensor.
Default: ``torch.float32``
r
r r zThe balance properties of Sobol' points require n to be a power of 2. {0} points have been previously generated, then: n={0}+2**{1}={2}. If you still want to do this, please use 'SobolEngine.draw()' instead.)r r r )r r
formatr&