plans.stochastic.sampling#

Random sampling and rescaling of samples.

Functions

normalize(array[, min_value, max_value])

Normalize array between min and max values

sample_gamma(size[, shape, scale, ...])

Draw a gamma sample, then rescale it so its own extremes sit on the bounds.

plans.stochastic.sampling.normalize(array, min_value=0, max_value=100)[source]#

Normalize array between min and max values

\[y = y_{\min} + \frac{(x - x_{\min}) (y_{\max} - y_{\min})}{x_{\max} - x_{\min}}\]

Here \(y_{\min}\) and \(y_{\max}\) are min_value and max_value.

Parameters:
  • array (float or numpy.ndarray) – Input array or float

  • min_value (float) – minimum vale

  • max_value (float) – maximum value

Returns:

Output array or float

Return type:

numpy.ndarray

plans.stochastic.sampling.sample_gamma(size, shape=3, scale=1, shape_mode=None, n_min=None, n_max=None, rng=None)[source]#

Draw a gamma sample, then rescale it so its own extremes sit on the bounds.

The draw is \(x \sim \mathrm{Gamma}(k, \theta)\), with shape \(k\) and scale \(\theta\), followed by normalize().

The sample minimum becomes n_min and the sample maximum becomes n_max, so the result is a gamma-shaped sample, not a gamma sample with that scale. A missing bound defaults to the sample’s own extreme. When both bounds are given, scale has no effect because the rescaling cancels it.

Parameters:
  • size (int) – Sample size

  • shape (float) – Shape parameter

  • scale (float) – Scale parameter

  • shape_mode (str or None) – Shape mode (overwrites shape value). See GAMMA_SHAPES.

  • n_min (float or None) – Normalization lower value

  • n_max (float or None) – Normalization upper value

  • rng (numpy.random.Generator or None) – Random generator. If None, uses the global numpy random state.

Returns:

Sampled array

Return type:

numpy.ndarray