Summary
The Sobol sequence is effective for Monte Carlo integrations that commonly occur in computer graphics. Its utility is improved when it is coupled with Owen's nested uniform scrambling, commonly called Owen Scrambling. We survey existing implementations of Owen Scrambling and present an original method using tabular hashing. Our implementation uses a fixed-size static lookup table of 2KiB, suitable for scrambling any number of dimensions. It offers a good compromise amongst speed, quality and flexibility.
Introduction
The Sobol sequence is commonly used for Monte Carlo integrations in computer graphics. However, in multiple dimensions, the sequence can display structured artifacts. Joe and Kuo created direction vectors to maximize coverage across dimensions. Faure and Tezuka randomized the rank order of values in the sequence. We call this "shuffling."
Owen introduced a randomization which eliminates structured artifacts and actually improves performance when sampling sufficiently smooth signals. It also provides some guaranteed worst-case bounds on convergence. This method is commonly called Owen Scrambling. In brief, it works by probabilistically swapping elementary intervals of samples in each dimension, preserving sample coverage of those intervals. It has been studied extensively.
Implementing Owen Scrambling naively can be expensive because it requires a tree of random bits with a depth equal to the size of the bit-word to be scrambled. Alternative methods to reduce or eliminate the costs of producing scramble trees have been presented. Laine and Karras developed a hash function for shuffling. Burley noted that this can also be used for scrambling. Vegdhal improved upon the hashing function at the core of Burley's implementation. MatouΕ‘ek proposed random digit scrambling and random linear scrambling as alternatives to full Owen Scrambling. In base-2, a static random word is applied as the scramble word in each dimension. Tan and Boyle suggested iterating repeatedly through a fixed-size scramble tree. Friedel and Keller proposed using lazy permutation trees.
Christensen et al and Helmer et al generated samples in bulk, merging randomization with calculating the sequence itself.
Our Method
Here, we propose an implementation of Owen Scrambling that uses tabular hashing as opposed to the hashing methods of Laine and Karras, Burley and Vegdhal. With tabular hashing, the bulk of the entropy is generated during coding and it is stored in static tables. At run-time, tabular data are accessed and potentially aggregated in computationally simple ways to produce good-quality hash results. Overall, tabular hashing can be very fast without sacrificing the quality of the randomization.
In our case, we first we generate a set of fixed-depth scramble trees using existing methodology. In our testing, 16 trees of depth 8 were sufficient. These are created during code implementation, so the tables are static and can be stored in a lookup table with a total size of 2KiB.
When calculating a binary word for scrambling, a user-supplied seed value is used to choose the first random tree. When we reach the leaf of that tree, we use the last few random bits from the traversal to select a new tree. In this way, our pre-generated trees can be chained together to produce binary scramble words of arbitrary length. To create a greater diversity of randomization, we use a simple integer multiplication against the user-provided seed to further randomize the final scrambling word.
We present pseudo-code for our scrambling calculation in Algorithm 1. Complete source code for calculating the Owen Scrambled Sobol sequence with state and without is available here.
Require: static π ππππππππ‘ππππ[16][128], table of 8-bit words
Require: input π πππ, a user-supplied 32-bit random seed
Require: input π€πππ, 32-bit binary value to scramble
1: π₯ ← π πππ × 0π₯6π΄935πΆπ΄5
2: π ← π πππ
3: π€ ← π€πππ
4: πππ‘π ← 32
5: while πππ‘π do
6: πππ‘π ← πππ‘π − 8
7: π ← π ππππππππ‘ππππ[π & 0π₯πΉ][π€ >> 25]
8: π€ ← π€ << 8
9: π₯ ← π₯ ⊕ (π << πππ‘π )
10: end while
11: return π€πππ ⊕ π₯
Scrambling in different dimensions is achieved by incorporating the dimension into the input seed for the algorithm. In its simplest form, the dimension can be the seed value. This is in contrast to the methods of Burley and Vegdhal which requires additional randomization of the input seed value for the best result.
Interestingly, Tan and Boyle’s method can be achieved by changing line 1 to initialize π₯ to zero, and using π πππ on line 7 instead of π to choose the tree. Speed is improved at the expense of quality. We will use this implementation of the Tan and Boyle method later in our testing.
As an optimization, since practical applications involve words of fixed size, the while loop can be unwrapped to avoid jump instructions that could impede pipelined execution on the CPU.
Our reference implementation of the algorithm is available online.
Testing
- Stateful Sobol sequence without Owen Scrambling: 152.4 million samples per second
- Stochastic Sobol sequence: 90.90 M/sec
- Stateful Sobol sequence with Tan & Boyle Owen Scrambling: 67.54 M/sec
- Stateful Sobol sequence with our implementation of Owen Scrambling: 51.28 M/sec
- Stateful Sobol sequence with Burley/Vegdhal Owen Scrambling: 34.34 M/sec
Comments
Post a Comment