plans.stochastic.sampling#
Random sampling and rescaling of samples.
Functions
|
Normalize array between min and max values |
|
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_valueandmax_value.- Parameters:
array (float or
numpy.ndarray) – Input array or floatmin_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\) andscale\(\theta\), followed bynormalize().The sample minimum becomes
n_minand the sample maximum becomesn_max, so the result is a gamma-shaped sample, not a gamma sample with thatscale. A missing bound defaults to the sample’s own extreme. When both bounds are given,scalehas 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.Generatoror None) – Random generator. If None, uses the global numpy random state.
- Returns:
Sampled array
- Return type:
numpy.ndarray