simplex — Uniform sampling on the unit simplex

This module provides functions to sample from the unit simplex.

diversipy.simplex.sample(dimension, n_points=1)

Draw random samples from the unit simplex in R^d.

Parameters:
  • dimension (int) – number of variables.
  • n_points (int, optional) – number of points to sample, by default 1
Returns:

Random samples from the unit simplex

Return type:

numpy array

diversipy.simplex.grid(dimension, levels=2)

Construct a regular grid on the unit simplex in R^d.

Parameters:
  • dimension (int) – Number of variables.
  • levels (int) – Number of levels between 0 and 1 for each variable.
Returns:

Regularily spaced grid points on the unit simplex.

Return type:

ndarray of shape (n_points, n_dim)

References

Nijenhuis and Wilf, Combinatorial Algorithms, Chapter 5, Academic Press, 1978.

Examples

>>> simplex.grid(3, 3)
array([
    [0. , 0. , 1. ],
    [0. , 0.5, 0.5],
    [0. , 1. , 0. ],
    [0.5, 0. , 0.5],
    [0.5, 0.5, 0. ],
    [1. , 0. , 0. ]
])