random
cornucopia.random
Sampler
Base class for random samplers, with a bunch of helpers. This class is for developers of new Sampler classes only.
Fixed
Bases: Sampler
Fixed value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
number or sequence[number]
|
|
required |
Uniform
Bases: Sampler
Continuous uniform sampler
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min |
float or sequence[float]
|
Lower bound (inclusive) |
0
|
max |
float or sequence[float]
|
Upper bound (inclusive or exclusive, depending on rounding) |
1
|
RandInt
Bases: Sampler
Discrete uniform sampler
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min |
float or sequence[float]
|
Lower bound (inclusive) |
0
|
max |
float or sequence[float]
|
Upper bound (inclusive) |
required |
RandKFrom
Bases: Sampler
Discrete uniform sampler
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
range |
sequence
|
Values from which to sample |
required |
k |
int
|
Number of values to sample. Sample random number if None. |
None
|
replacement |
bool
|
Whether to sample with replacement |
False
|
Normal
Bases: Sampler
Gaussian sampler
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu |
float or sequence[float]
|
Mean |
0
|
sigma |
float or sequence[float]
|
Standard deviation |
1
|
LogNormal
Bases: Sampler
LogNormal sampler
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu |
float or sequence[float]
|
Mean of the log |
0
|
sigma |
float or sequence[float]
|
Standard deviation of the log |
1
|
TransformedSampler
CombinedSamplers
make_range
If any of the inputs is a Sampler, return the Sampler.
Else, build a (lower, upper) range.
Examples
# full range
make_range(x, y) -> (x, y)
make_range(x, y, offset=1) -> (1+x, 1+y)
# symmetric range
make_range(x) -> (-x, x)
make_range(x, offset=1) -> (1-x, 1+x)
# upper bound
make_range(0, x) -> (0, x)
make_range(x, min=0) -> (0, x)
# lower bound
make_range(x, 1) -> (x, 1)
make_range(x, max=1) -> (x, 1)