TriangleDistribution#
- class torch_brain.transforms.TriangleDistribution(min_units=20, mode_units=100, max_units=300, tail_right=None, peak=4, M=10, max_attempts=100, seed=None)[source]#
Bases:
objectTriangular distribution with a peak at mode_units, going from min_units to max_units.
The unnormalized density function is defined as:
\[\begin{split}f(x) = \begin{cases} 0 & \text{if } x < \text{min_units} \\ 1 + (\text{peak} - 1) \cdot \frac{x - \text{min_units}}{\text{mode_units} - \text{min_units}} & \text{if } \text{min_units} \leq x \leq \text{mode_units} \\ \text{peak} - (\text{peak} - 1) \cdot \frac{x - \text{mode_units}}{\text{tail_right} - \text{mode_units}} & \text{if } \text{mode_units} \leq x \leq \text{tail_right} \\ 1 & \text{if } \text{tail_right} \leq x \leq \text{max_units}\\ 0 & \text{otherwise} \end{cases}\end{split}\]- Parameters:
min_units (
int) – Minimum number of units to sample. If the population has fewer units than this, all units will be kept.mode_units (
int) – Mode of the distribution.max_units (
int) – Maximum number of units to sample.tail_right (
Optional[int]) – Right tail of the distribution. If None, it is set to max_units.peak (
float) – Height of the peak of the distribution.M (
int) – Normalization constant for the proposal distribution.max_attempts (
int) – Maximum number of attempts to sample from the distribution.seed (
Optional[int]) – Seed for the random number generator.
To sample from the distribution, we use rejection sampling. We sample from a uniform distribution between min_units and max_units and accept the sample with probability \(\frac{f(x)}{M \cdot q(x)}\), where \(q(x)\) is the proposal distribution.