From Jason Turner

[rand.dist.samp.discrete]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp7pap463v/{from.md → to.md} +19 -19
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: $p_k = {w_k / S} \; \mbox{ for } k = 0, \ldots, n\!-\!1$ , in which
12
- the values wₖ, commonly known as the *weights* , shall be non-negative,
13
- non-NaN, and non-infinity. Moreover, the following relation shall hold:
14
- 0 < S = w₀ + + wₙ₋₁.
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
- *Requires:* `InputIterator` shall satisfy the requirements of an input
65
- iterator ([[input.iterators]]). Moreover,
66
- `iterator_traits<InputIterator>::value_type` shall denote a type that is
67
- convertible to `double`. If `firstW == lastW`, let n = 1 and w₀ = 1.
68
- Otherwise, [`firstW`, `lastW`) shall form a sequence w of length n > 0.
 
 
 
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
- *Requires:* Each instance of type `UnaryOperation` shall be a function
85
- object ([[function.objects]]) whose return type shall be convertible to
86
- `double`. Moreover, `double` shall be convertible to the type of
87
- `UnaryOperation`’s sole parameter. If `nw` = 0, let n = 1, otherwise let
88
- n = `nw`. The relation 0 < δ = (`xmax` - `xmin`) / n shall hold.
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` shall not exceed n.
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