cornucopia.random
Sampler
Bases: ABC
Base class for random samplers, with a bunch of helpers.
Note
Samplers can be combined with determinstic values or between themselves using arithmetic operators:
P + X -> ShiftedSampler(P, X)
P - X -> ShiftedSampler(P, -X)
P * X -> MultipliedSampler(P, X)
P / X -> DividedSampler(P, X)
X / P -> DividedSampler(X, P)
P ** X -> PoweredSampler(P, X)
X ** P -> ExponentSampler(X, P)
P + Q -> SumOfSamplers(P, Q)
P - Q -> DifferenceOfSamplers(P, Q)
P * Q -> ProductOfSamplers(P, Q)
P / Q -> RatioOfSamplers(P, Q)
P ** Q -> PowerOfSamplers(P, Q)
min(P, Q, ...) -> MinimumOfSamplers(P, Q, ...)
max(P, Q, ...) -> MaximumOfSamplers(P, Q, ...)
sum(P, Q, ...) -> SumOfSamplers(P, Q, ...)
exp(P) -> ExponentiatedSampler(P)
log(P) -> LogarithmOfSampler(P)
Attributes:
| Name | Type | Description |
|---|---|---|
theta |
dict
|
Parameters of the sampler |
make
classmethod
Build a sampler from another sample, or from parameters.
__call__
abstractmethod
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int or list[int]
|
Number of values to sample
|
None
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
dtype |
dtype
|
Data type of the returned tensor. By default, inferred from
the sampler parameters. Only used if |
device |
device
|
Device of the returned tensor. By default, inferred from
the sampler parameters. Only used if |
Returns:
| Name | Type | Description |
|---|---|---|
sample |
number or list[number] or tensor
|
|
Fixed
Uniform
Bases: Sampler
Continuous uniform sampler.
Attributes:
| Name | Type | Description |
|---|---|---|
min |
float or sequence[float], default=0
|
Lower bound (inclusive) |
max |
float or sequence[float], default=1
|
Upper bound (inclusive or exclusive, depending on rounding) |
RandInt
RandKFrom
Bases: Sampler
Discrete uniform sampler
Attributes:
| Name | Type | Description |
|---|---|---|
range |
sequence
|
Values from which to sample |
k |
int, default=None
|
Number of values to sample. Sample random number if None. |
replacement |
bool, default=False
|
Whether to sample with replacement |
Normal
Bases: Sampler
Gaussian sampler.
Attributes:
| Name | Type | Description |
|---|---|---|
mu |
float or sequence[float], default=0
|
Mean |
sigma |
float or sequence[float], default=1
|
Standard deviation |
LogNormal
Bases: Sampler
LogNormal sampler
Attributes:
| Name | Type | Description |
|---|---|---|
mu |
float or sequence[float], default=0
|
Mean of the log |
sigma |
float or sequence[float], default=1
|
Standard deviation of the log |
UniformSphere
TransformedSampler
CombinedSamplers
MultipliedSampler
DividedSampler
DividingSampler
ShiftedSampler
ReverseShiftedSampler
PoweredSampler
ExponentSampler
ProductOfSamplers
RatioOfSamplers
DifferenceOfSamplers
MinimumOfSamplers
MaximumOfSamplers
AverageOfSamplers
ExponentiatedSampler
LogarithmOfSampler
PowerOfSamplers
Bases: CombinedSamplers
Raise samples from one sampler to the power of samples from another sampler.
make_range
If any of the inputs is a Sampler, return the Sampler.
Else, build a {lower|upper} range.