lemke.randomstart#

Functions

maptotriangle(vec)

Map a point on the unit triangle (3D) to 2D coordinates in a triangle with corners at (0, 0), (1, 0), (0.5, sqrt(3)/2).

plot_simplex([numpoints, accuracy, ...])

Generate a simplex sampling plot.

randInSimplex(n[, naive])

Generate a random n-tuple uniformly distributed on the unit simplex.

renormalize(x)

Rescale a list of numbers so that it sums to one.

roundArray(x[, accuracy])

Round an array of probabilities x to multiples of 1 / accuracy that still sum to 1.

validate_accuracy(accuracy)

Check that accuracy is an integer between 1 and MAX_ACCURACY.

lemke.randomstart.maptotriangle(vec)[source]#

Map a point on the unit triangle (3D) to 2D coordinates in a triangle with corners at (0, 0), (1, 0), (0.5, sqrt(3)/2).

lemke.randomstart.plot_simplex(numpoints=200, accuracy=20, higherdim=3, naiveplot=False)[source]#

Generate a simplex sampling plot.

Samples numpoints random points from the simplex of dimension higherdim and projects them onto a 2D triangle (if higherdim is greater than 3, only the middle 3 components of each point are used, renormalized to sum to 1). Plots the raw sampled points in green and their rounded approximations in red.

Parameters:
  • numpoints (int) – Number of points to plot. Default is 200.

  • accuracy (int) – Denominator for rounding: each point’s coordinates are rounded to multiples of 1/accuracy that sum to 1 (see roundArray). Default is 20. Must be between 1 and MAX_ACCURACY (10,000,000).

  • higherdim (int) – Dimension from which the middle 3 components will be sampled. Default is 3. Must be between 3 and 10.

  • naiveplot (bool) – Sample naively by normalizing random uniforms (biased toward center). Default is False.

Raises:
  • TypeError – If accuracy or higherdim is not an integer.

  • ValueError – If accuracy or higherdim is out of range.

lemke.randomstart.randInSimplex(n, naive=False)[source]#

Generate a random n-tuple uniformly distributed on the unit simplex.

lemke.randomstart.renormalize(x)[source]#

Rescale a list of numbers so that it sums to one.

lemke.randomstart.roundArray(x, accuracy=10000)[source]#

Round an array of probabilities x to multiples of 1 / accuracy that still sum to 1.

Entries are not necessarily rounded to the nearest multiple, since the rounded values must sum to 1. The probabilities are multiplied by accuracy, then rounded down to their integer parts, which will be the numerators, augmented by 1 in order of decreasing size of the remainders (which are less than 1) until they sum to accuracy.

Example: accuracy=10, x=[0.18, .35, .47] becomes [2/10, 3/10, 5/10].

lemke.randomstart.validate_accuracy(accuracy)[source]#

Check that accuracy is an integer between 1 and MAX_ACCURACY.