N-simplex random vectors generators¶
Contains 2 functions to generate random vectors in the \(n\)-simplex
runif_simplex : Uniformly distributed vectors in n-simplex,
random_simplex : Dirichlet generator of vectors in n-simplex with permutations (for antithetic variance reduction applications).
Note, a Flat Dirichlet generator (i.e., all alpha Dirichlet coefficients set to \(1\)) is equivalent to an uniformly distributed n-simplex vector generators.
- azapy.Util.randomgen.random_simplex(rng, simplex_dim, size=1, antithetic=False, dirichlet_alpha=None)¶
Returns random vectors in the n-simplex (based on Dirichlet generator) sum_{k=1}^n x_k = 1 for x_k >= 0
- Parameters:
- rngnumpy.random.mtrand.RandomState
Random number generator (e.g. as returned by numpy.random.RandomState(42)).
- simplex_dimpositive int
Simplex dimension.
- sizepositive int, optional
Sample size. The default is 1.
- antitheticBoolean, optional
If it is set to True, then all the vector permutation will be added to the sample. The actual size of the sample will be size * factorial(simplex_dim). The default is False.
- dirichlet_alphalist, optional
Dirichlet alpha coefficients. The length of the list must be equal to simplex_dim. If it is None, then uniform distributed random vectors are generated (equivalent to dirichlet_alpha = [1] * simple_dim). The default is None.
- Returns:
- numpy.array
A sample of size size of random vectors of length simplex_dim.
- azapy.Util.randomgen.runif_simplex(rng, simplex_dim, size=1)¶
Returns uniformly distributed random vectors in the n-simplex sum_{k=1}^n x_k = 1 for x_k >= 0
- Parameters:
- rngnumpy.random.mtrand.RandomState
Random number generator (e.g. as returned by numpy.random.RandomState(42)).
- simplex_dimpositive int
Simplex dimension.
- sizepositive int, optional
Sample size. The default is 1.
- Returns:
- numpy.array
A sample of size size of random vectors of length simplex_dim.
Examples of generating random vectors in a simplex¶
# Examples of how to call random simplex functions
import numpy as np
import azapy as az
# Build a random numbers generator
rng = np.random.RandomState(42)
# Uniform random vectors (10) in a 5-simplex
simplex_dim = 5
size = 10
sq = az.runif_simplex(rng, simplex_dim, size)
# Dirichlet distributed random vectors (10) in a 5-simplex
simplex_dim = 5
alpha = [0.5] * simplex_dim
size = 10
sq = az.random_simplex(rng, simplex_dim, size=10, dirichlet_alpha=alpha)
print(sq)
# Same as above but with antithetic permutations
# The effective size of the sample is size * factorial(simplex_dim)
# in this example 10 * 5! = 1200
simplex_dim = 5
alpha = [0.5] * simplex_dim
size = 10
sq = az.random_simplex(rng, simplex_dim, size=10,
antithetic=True, dirichlet_alpha=alpha)
print(sq)
# Flat Dirichlet distributed random vectors (10) in a 5-simplex
# equivalent with the uniform distributed vectors in a simplex
simplex_dim = 5
alpha = [1] * simplex_dim
size = 10
sq = az.random_simplex(rng, simplex_dim, size=10,
antithetic=True, dirichlet_alpha=alpha)
print(sq)
# Uniform distributed random vectors (10) in a 5-simplex
# equivalent with Flat Dirichlet
simplex_dim = 5
size = 10
sq = az.random_simplex(rng, simplex_dim, size=10, antithetic=True)
print(sq)