Index chosen with probability proportional to a weight.
More...
#include <distributions.hpp>
|
| | discrete (std::span< const double > weights) |
| | Build from weights.
|
| |
| | discrete (std::initializer_list< double > weights) |
| | Build from a list of weights.
|
| |
| std::size_t | operator() (rng &r) const |
| | Draw an index.
|
| |
| std::size_t | size () const noexcept |
| | Number of weights.
|
| |
| double | total () const noexcept |
| | Sum of the weights.
|
| |
| double | probability (std::size_t i) const |
| | Probability of an index.
|
| |
Index chosen with probability proportional to a weight.
Keeps the cumulative sums of the weights (added left to right). A draw is the first index whose cumulative sum exceeds uniform01(r) * total, so a zero weight is never chosen. Consumes one value.
std::size_t i = eye_colour(r);
Index chosen with probability proportional to a weight.
Definition at line 256 of file distributions.hpp.
◆ discrete() [1/2]
| dasmig::core::discrete::discrete |
( |
std::span< const double > |
weights | ) |
|
|
inlineexplicit |
Build from weights.
- Parameters
-
| weights | Non-negative, finite weights, at least one positive. |
- Exceptions
-
| std::invalid_argument | If the weights are empty, a weight is negative or not finite, or they sum to 0 or overflow. |
Definition at line 263 of file distributions.hpp.
◆ discrete() [2/2]
| dasmig::core::discrete::discrete |
( |
std::initializer_list< double > |
weights | ) |
|
|
inline |
Build from a list of weights.
- Parameters
-
| weights | Non-negative, finite weights, at least one positive. |
- Exceptions
-
| std::invalid_argument | As the span constructor. |
Definition at line 293 of file distributions.hpp.
◆ operator()()
| std::size_t dasmig::core::discrete::operator() |
( |
rng & |
r | ) |
const |
|
inline |
Draw an index.
- Parameters
-
- Returns
- An index in [0, size()) with a positive weight.
Definition at line 301 of file distributions.hpp.
◆ probability()
| double dasmig::core::discrete::probability |
( |
std::size_t |
i | ) |
const |
|
inline |
◆ size()
| std::size_t dasmig::core::discrete::size |
( |
| ) |
const |
|
inlinenoexcept |
◆ total()
| double dasmig::core::discrete::total |
( |
| ) |
const |
|
inlinenoexcept |
The documentation for this class was generated from the following file: