Title: | Space-Filling Random and Quasi-Random Sequences |
---|---|
Description: | Generates random and quasi-random space-filling sequences. Supports the following sequences: 'Halton', 'Sobol', 'Owen'-scrambled 'Sobol', 'Owen'-scrambled 'Sobol' with errors distributed as blue noise, progressive jittered, progressive multi-jittered ('PMJ'), 'PMJ' with blue noise, 'PMJ02', and 'PMJ02' with blue noise. Includes a 'C++' 'API'. Methods derived from "Constructing Sobol sequences with better two-dimensional projections" (2012) <doi:10.1137/070709359> S. Joe and F. Y. Kuo, "Progressive Multi-Jittered Sample Sequences" (2018) <https://graphics.pixar.com/library/ProgressiveMultiJitteredSampling/paper.pdf> Christensen, P., Kensler, A. and Kilpatrick, C., and "A Low-Discrepancy Sampler that Distributes Monte Carlo Errors as a Blue Noise in Screen Space" (2019) E. Heitz, B. Laurent, O. Victor, C. David and I. Jean-Claude, <doi:10.1145/3306307.3328191>. |
Authors: | Tyler Morgan-Wall [aut, cph, cre] , Andrew Helmer [ctb, cph], Leonhard Grünschloß [ctb, cph], Eric Heitz [ctb, cph] |
Maintainer: | Tyler Morgan-Wall <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.3 |
Built: | 2024-10-31 16:32:28 UTC |
Source: | https://github.com/tylermorganwall/spacefillr |
Generate a set of values from a Faure Halton set.
generate_halton_faure_set(n, dim)
generate_halton_faure_set(n, dim)
n |
The number of values (per dimension) to extract. |
dim |
The number of dimensions of the sequence. |
An 'n' x 'dim' matrix listing all the
#Generate a 2D sample: points2d = generate_halton_random_set(n=1000, dim=2) plot(points2d) #Extract a separate pair of dimensions points2d = generate_halton_random_set(n=1000, dim=10) plot(points2d[,5:6]) #Integrate the value of pi by counting the number of randomly generated points that fall #within the unit circle. pointset = matrix(generate_halton_faure_set(10000,dim=2),ncol=2) pi_estimate = 4*sum(pointset[,1] * pointset[,1] + pointset[,2] * pointset[,2] < 1)/10000 pi_estimate
#Generate a 2D sample: points2d = generate_halton_random_set(n=1000, dim=2) plot(points2d) #Extract a separate pair of dimensions points2d = generate_halton_random_set(n=1000, dim=10) plot(points2d[,5:6]) #Integrate the value of pi by counting the number of randomly generated points that fall #within the unit circle. pointset = matrix(generate_halton_faure_set(10000,dim=2),ncol=2) pi_estimate = 4*sum(pointset[,1] * pointset[,1] + pointset[,2] * pointset[,2] < 1)/10000 pi_estimate
Generate a single value from a seeded Halton set, initialized with a Faure sequence.
Note: This is much slower than generating the entire set ahead of time.
generate_halton_faure_single(i, dim)
generate_halton_faure_single(i, dim)
i |
The element of the sequence to extract. |
dim |
The dimension of the sequence to extract. |
A single numeric value representing the 'i'th element in the 'dim' dimension.
#Generate a 3D sample: point3d = c(generate_halton_faure_single(10, dim = 1), generate_halton_faure_single(10, dim = 2), generate_halton_faure_single(10, dim = 3)) point3d
#Generate a 3D sample: point3d = c(generate_halton_faure_single(10, dim = 1), generate_halton_faure_single(10, dim = 2), generate_halton_faure_single(10, dim = 3)) point3d
Generate a set of values from a seeded Halton set.
generate_halton_random_set(n, dim, seed = 0)
generate_halton_random_set(n, dim, seed = 0)
n |
The number of values (per dimension) to extract. |
dim |
The number of dimensions of the sequence. |
seed |
Default '0'. The random seed. |
An 'n' x 'dim' matrix listing all the
#Generate a 2D sample: points2d = generate_halton_random_set(n=1000, dim=2) plot(points2d) #Change the seed and extract a separate pair of dimensions points2d = generate_halton_random_set(n=1000, dim=10,seed=2) plot(points2d[,5:6]) #Integrate the value of pi by counting the number of randomly generated points that fall #within the unit circle. pointset = matrix(generate_halton_random_set(10000,dim=2),ncol=2) pi_estimate = 4*sum(pointset[,1] * pointset[,1] + pointset[,2] * pointset[,2] < 1)/10000 pi_estimate
#Generate a 2D sample: points2d = generate_halton_random_set(n=1000, dim=2) plot(points2d) #Change the seed and extract a separate pair of dimensions points2d = generate_halton_random_set(n=1000, dim=10,seed=2) plot(points2d[,5:6]) #Integrate the value of pi by counting the number of randomly generated points that fall #within the unit circle. pointset = matrix(generate_halton_random_set(10000,dim=2),ncol=2) pi_estimate = 4*sum(pointset[,1] * pointset[,1] + pointset[,2] * pointset[,2] < 1)/10000 pi_estimate
Generate a single value from a seeded Halton set.
Note: This is much slower than generating the entire set ahead of time.
generate_halton_random_single(i, dim, seed = 0)
generate_halton_random_single(i, dim, seed = 0)
i |
The element of the sequence to extract. |
dim |
The dimension of the sequence to extract. |
seed |
Default '0'. The random seed. |
A single numeric value representing the 'i'th element in the 'dim' dimension.
#Generate a 3D sample: point3d = c(generate_halton_random_single(10, dim = 1), generate_halton_random_single(10, dim = 2), generate_halton_random_single(10, dim = 3)) point3d #Change the random seed: #'#Generate a 3D sample point3d_2 = c(generate_halton_random_single(10, dim = 1, seed = 10), generate_halton_random_single(10, dim = 2, seed = 10), generate_halton_random_single(10, dim = 3, seed = 10)) point3d_2
#Generate a 3D sample: point3d = c(generate_halton_random_single(10, dim = 1), generate_halton_random_single(10, dim = 2), generate_halton_random_single(10, dim = 3)) point3d #Change the random seed: #'#Generate a 3D sample point3d_2 = c(generate_halton_random_single(10, dim = 1, seed = 10), generate_halton_random_single(10, dim = 2, seed = 10), generate_halton_random_single(10, dim = 3, seed = 10)) point3d_2
Generate a set of values from a Progressive Jittered set.
generate_pj_set(n, seed = 0)
generate_pj_set(n, seed = 0)
n |
The number of 2D values to extract. |
seed |
Default '0'. The random seed. |
An 'n' x '2' matrix with all the calculated values from the set.
#Generate a 2D sample: points2d = generate_pj_set(n=1000) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a longer sequence of values from that set points2d = generate_pj_set(n=1500) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a new set by changing the seed points2d = generate_pj_set(n=1500,seed=10) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #'#Integrate the value of pi by counting the number of randomly generated points that fall #within the unit circle. pointset = generate_pj_set(10000) pi_estimate = 4*sum(pointset[,1] * pointset[,1] + pointset[,2] * pointset[,2] < 1)/10000 pi_estimate
#Generate a 2D sample: points2d = generate_pj_set(n=1000) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a longer sequence of values from that set points2d = generate_pj_set(n=1500) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a new set by changing the seed points2d = generate_pj_set(n=1500,seed=10) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #'#Integrate the value of pi by counting the number of randomly generated points that fall #within the unit circle. pointset = generate_pj_set(10000) pi_estimate = 4*sum(pointset[,1] * pointset[,1] + pointset[,2] * pointset[,2] < 1)/10000 pi_estimate
Generate a set of values from a Progressive Multi-Jittered set.
generate_pmj_set(n, seed = 0)
generate_pmj_set(n, seed = 0)
n |
The number of 2D values to extract. |
seed |
Default '0'. The random seed. |
An 'n' x '2' matrix with all the calculated values from the set.
#Generate a 2D sample: points2d = generate_pmj_set(n=1000) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a longer sequence of values from that set points2d = generate_pmj_set(n=1500) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a new set by changing the seed points2d = generate_pmj_set(n=1500,seed=10) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Integrate the value of pi by counting the number of randomly generated points that fall #within the unit circle. pointset = generate_pj_set(10000) pi_estimate = 4*sum(pointset[,1] * pointset[,1] + pointset[,2] * pointset[,2] < 1)/10000 pi_estimate
#Generate a 2D sample: points2d = generate_pmj_set(n=1000) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a longer sequence of values from that set points2d = generate_pmj_set(n=1500) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a new set by changing the seed points2d = generate_pmj_set(n=1500,seed=10) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Integrate the value of pi by counting the number of randomly generated points that fall #within the unit circle. pointset = generate_pj_set(10000) pi_estimate = 4*sum(pointset[,1] * pointset[,1] + pointset[,2] * pointset[,2] < 1)/10000 pi_estimate
Generate a set of values from a Progressive Multi-Jittered (0, 2) set.
generate_pmj02_set(n, seed = 0)
generate_pmj02_set(n, seed = 0)
n |
The number of 2D values to extract. |
seed |
Default '0'. The random seed. |
An 'n' x '2' matrix with all the calculated values from the set.
#Generate a 2D sample: points2d = generate_pmj02_set(n=1000) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a longer sequence of values from that set points2d = generate_pmj02_set(n=1500) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a new set by changing the seed points2d = generate_pmj02_set(n=1500,seed=10) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #'#Integrate the value of pi by counting the number of randomly generated points that fall #within the unit circle. pointset = generate_pmj02_set(10000) pi_estimate = 4*sum(pointset[,1] * pointset[,1] + pointset[,2] * pointset[,2] < 1)/10000 pi_estimate
#Generate a 2D sample: points2d = generate_pmj02_set(n=1000) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a longer sequence of values from that set points2d = generate_pmj02_set(n=1500) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a new set by changing the seed points2d = generate_pmj02_set(n=1500,seed=10) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #'#Integrate the value of pi by counting the number of randomly generated points that fall #within the unit circle. pointset = generate_pmj02_set(10000) pi_estimate = 4*sum(pointset[,1] * pointset[,1] + pointset[,2] * pointset[,2] < 1)/10000 pi_estimate
Generate a set of values from a Progressive Multi-Jittered (0, 2) (with blue noise) set.
generate_pmj02bn_set(n, seed = 0)
generate_pmj02bn_set(n, seed = 0)
n |
The number of 2D values to extract. |
seed |
Default '0'. The random seed. |
An 'n' x '2' matrix with all the calculated values from the set.
#Generate a 2D sample: points2d = generate_pmj02bn_set(n=1000) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a longer sequence of values from that set points2d = generate_pmj02bn_set(n=1500) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a new set by changing the seed points2d = generate_pmj02bn_set(n=1500,seed=10) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Integrate the value of pi by counting the number of randomly generated points that fall #within the unit circle. pointset = generate_pmj02bn_set(10000) pi_estimate = 4*sum(pointset[,1] * pointset[,1] + pointset[,2] * pointset[,2] < 1)/10000 pi_estimate
#Generate a 2D sample: points2d = generate_pmj02bn_set(n=1000) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a longer sequence of values from that set points2d = generate_pmj02bn_set(n=1500) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a new set by changing the seed points2d = generate_pmj02bn_set(n=1500,seed=10) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Integrate the value of pi by counting the number of randomly generated points that fall #within the unit circle. pointset = generate_pmj02bn_set(10000) pi_estimate = 4*sum(pointset[,1] * pointset[,1] + pointset[,2] * pointset[,2] < 1)/10000 pi_estimate
Generate a set of values from a Progressive Multi-Jittered (with blue noise) set.
generate_pmjbn_set(n, seed = 0)
generate_pmjbn_set(n, seed = 0)
n |
The number of 2D values to extract. |
seed |
Default '0'. The random seed. |
An 'n' x '2' matrix with all the calculated values from the set.
#Generate a 2D sample: points2d = generate_pmjbn_set(n=1000) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a longer sequence of values from that set points2d = generate_pmjbn_set(n=1500) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a new set by changing the seed points2d = generate_pmjbn_set(n=1500,seed=10) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Integrate the value of pi by counting the number of randomly generated points that fall #within the unit circle. pointset = generate_pmjbn_set(10000) pi_estimate = 4*sum(pointset[,1] * pointset[,1] + pointset[,2] * pointset[,2] < 1)/10000 pi_estimate
#Generate a 2D sample: points2d = generate_pmjbn_set(n=1000) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a longer sequence of values from that set points2d = generate_pmjbn_set(n=1500) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a new set by changing the seed points2d = generate_pmjbn_set(n=1500,seed=10) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Integrate the value of pi by counting the number of randomly generated points that fall #within the unit circle. pointset = generate_pmjbn_set(10000) pi_estimate = 4*sum(pointset[,1] * pointset[,1] + pointset[,2] * pointset[,2] < 1)/10000 pi_estimate
Generate a set of values from an Owen-scrambled Sobol set.
generate_sobol_owen_set(n, dim, seed = 0)
generate_sobol_owen_set(n, dim, seed = 0)
n |
The number of values (per dimension) to extract. |
dim |
The number of dimensions of the sequence. |
seed |
Default '0'. The random seed. |
An 'n' x 'dim' matrix with all the calculated values from the set.
#Generate a 2D sample: points2d = generate_sobol_owen_set(n=1000, dim = 2) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a longer sequence of values from that set points2d = generate_sobol_owen_set(n=1500, dim = 2) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #'#Integrate the value of pi by counting the number of randomly generated points that fall #within the unit circle. pointset = matrix(generate_sobol_owen_set(10000,dim=2),ncol=2) pi_estimate = 4*sum(pointset[,1] * pointset[,1] + pointset[,2] * pointset[,2] < 1)/10000 pi_estimate
#Generate a 2D sample: points2d = generate_sobol_owen_set(n=1000, dim = 2) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a longer sequence of values from that set points2d = generate_sobol_owen_set(n=1500, dim = 2) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #'#Integrate the value of pi by counting the number of randomly generated points that fall #within the unit circle. pointset = matrix(generate_sobol_owen_set(10000,dim=2),ncol=2) pi_estimate = 4*sum(pointset[,1] * pointset[,1] + pointset[,2] * pointset[,2] < 1)/10000 pi_estimate
Generate a set of values from a Sobol set.
Note: the Sobol sequences provided by spacefillr are different than those provided by randtoolbox, as spacefillr's Sobol sequences have better 2D projections (see "Constructing Sobol sequences with better two-dimensional projections" (2012) <doi:10.1137/070709359> S. Joe and F. Y. Kuo).
generate_sobol_set(n, dim, seed = 0)
generate_sobol_set(n, dim, seed = 0)
n |
The number of values (per dimension) to extract. |
dim |
The number of dimensions of the sequence. |
seed |
Default '0'. The random seed. |
A single numeric value representing the 'i'th element in the 'dim' dimension.
#Generate a 2D sample: points2d = generate_sobol_set(n=1000, dim = 2) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a longer sequence of values from that set points2d = generate_sobol_set(n=1500, dim = 2) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #'#Integrate the value of pi by counting the number of randomly generated points that fall #within the unit circle. pointset = matrix(generate_sobol_set(10000,dim=2),ncol=2) pi_estimate = 4*sum(pointset[,1] * pointset[,1] + pointset[,2] * pointset[,2] < 1)/10000 pi_estimate
#Generate a 2D sample: points2d = generate_sobol_set(n=1000, dim = 2) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #Generate a longer sequence of values from that set points2d = generate_sobol_set(n=1500, dim = 2) plot(points2d, xlim=c(0,1),ylim=c(0,1)) #'#Integrate the value of pi by counting the number of randomly generated points that fall #within the unit circle. pointset = matrix(generate_sobol_set(10000,dim=2),ncol=2) pi_estimate = 4*sum(pointset[,1] * pointset[,1] + pointset[,2] * pointset[,2] < 1)/10000 pi_estimate