tmp/tmp7pap463v/{from.md → to.md}
RENAMED
|
@@ -1,19 +1,16 @@
|
|
| 1 |
##### Class template `discrete_distribution` <a id="rand.dist.samp.discrete">[[rand.dist.samp.discrete]]</a>
|
| 2 |
|
| 3 |
A `discrete_distribution` random number distribution produces random
|
| 4 |
integers i, 0 ≤ i < n, distributed according to the discrete probability
|
| 5 |
-
function $$
|
| 6 |
-
P(i\,|\,p_0,\ldots,p_{n-1})
|
| 7 |
-
= p_i
|
| 8 |
-
\; \mbox{.}$$
|
| 9 |
|
| 10 |
Unless specified otherwise, the distribution parameters are calculated
|
| 11 |
-
as:
|
| 12 |
-
|
| 13 |
-
non-
|
| 14 |
-
0 < S =
|
| 15 |
|
| 16 |
``` cpp
|
| 17 |
template<class IntType = int>
|
| 18 |
class discrete_distribution {
|
| 19 |
public:
|
|
@@ -59,15 +56,18 @@ p₀ = 1.
|
|
| 59 |
``` cpp
|
| 60 |
template<class InputIterator>
|
| 61 |
discrete_distribution(InputIterator firstW, InputIterator lastW);
|
| 62 |
```
|
| 63 |
|
| 64 |
-
*
|
| 65 |
-
|
| 66 |
-
`
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
*Effects:* Constructs a `discrete_distribution` object with
|
| 71 |
probabilities given by the formula above.
|
| 72 |
|
| 73 |
``` cpp
|
|
@@ -79,22 +79,22 @@ discrete_distribution(initializer_list<double> wl);
|
|
| 79 |
``` cpp
|
| 80 |
template<class UnaryOperation>
|
| 81 |
discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw);
|
| 82 |
```
|
| 83 |
|
| 84 |
-
*
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
|
| 90 |
*Effects:* Constructs a `discrete_distribution` object with
|
| 91 |
probabilities given by the formula above, using the following values: If
|
| 92 |
`nw` = 0, let w₀ = 1. Otherwise, let wₖ = `fw`(`xmin` + k ⋅ δ + δ / 2)
|
| 93 |
for k = 0, …, n - 1.
|
| 94 |
|
| 95 |
-
*Complexity:* The number of invocations of `fw`
|
| 96 |
|
| 97 |
``` cpp
|
| 98 |
vector<double> probabilities() const;
|
| 99 |
```
|
| 100 |
|
|
|
|
| 1 |
##### Class template `discrete_distribution` <a id="rand.dist.samp.discrete">[[rand.dist.samp.discrete]]</a>
|
| 2 |
|
| 3 |
A `discrete_distribution` random number distribution produces random
|
| 4 |
integers i, 0 ≤ i < n, distributed according to the discrete probability
|
| 5 |
+
function $$P(i \,|\, p_0, \dotsc, p_{n-1}) = p_i \text{ .}$$
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
Unless specified otherwise, the distribution parameters are calculated
|
| 8 |
+
as: pₖ = {wₖ / S} for k = 0, …, n - 1, in which the values wₖ, commonly
|
| 9 |
+
known as the *weights* , shall be non-negative, non-NaN, and
|
| 10 |
+
non-infinity. Moreover, the following relation shall hold:
|
| 11 |
+
$0 < S = w_0 + \dotsb + w_{n - 1}$.
|
| 12 |
|
| 13 |
``` cpp
|
| 14 |
template<class IntType = int>
|
| 15 |
class discrete_distribution {
|
| 16 |
public:
|
|
|
|
| 56 |
``` cpp
|
| 57 |
template<class InputIterator>
|
| 58 |
discrete_distribution(InputIterator firstW, InputIterator lastW);
|
| 59 |
```
|
| 60 |
|
| 61 |
+
*Mandates:*
|
| 62 |
+
`is_convertible_v<iterator_traits<InputIterator>::value_type, double>`
|
| 63 |
+
is `true`.
|
| 64 |
+
|
| 65 |
+
*Preconditions:* `InputIterator` meets the *Cpp17InputIterator*
|
| 66 |
+
requirements [[input.iterators]]. If `firstW == lastW`, let n = 1 and
|
| 67 |
+
w₀ = 1. Otherwise, [`firstW`, `lastW`) forms a sequence w of length
|
| 68 |
+
n > 0.
|
| 69 |
|
| 70 |
*Effects:* Constructs a `discrete_distribution` object with
|
| 71 |
probabilities given by the formula above.
|
| 72 |
|
| 73 |
``` cpp
|
|
|
|
| 79 |
``` cpp
|
| 80 |
template<class UnaryOperation>
|
| 81 |
discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw);
|
| 82 |
```
|
| 83 |
|
| 84 |
+
*Mandates:* `is_invocable_r_v<double, UnaryOperation&, double>` is
|
| 85 |
+
`true`.
|
| 86 |
+
|
| 87 |
+
*Preconditions:* If `nw` = 0, let n = 1, otherwise let n = `nw`. The
|
| 88 |
+
relation 0 < δ = (`xmax` - `xmin`) / n holds.
|
| 89 |
|
| 90 |
*Effects:* Constructs a `discrete_distribution` object with
|
| 91 |
probabilities given by the formula above, using the following values: If
|
| 92 |
`nw` = 0, let w₀ = 1. Otherwise, let wₖ = `fw`(`xmin` + k ⋅ δ + δ / 2)
|
| 93 |
for k = 0, …, n - 1.
|
| 94 |
|
| 95 |
+
*Complexity:* The number of invocations of `fw` does not exceed n.
|
| 96 |
|
| 97 |
``` cpp
|
| 98 |
vector<double> probabilities() const;
|
| 99 |
```
|
| 100 |
|