Created on 2008-02-09.00:00:00 last changed 171 months ago
Rationale:
Addressed by N2836 "Wording Tweaks for Concept-enabled Random Number Generation in C++0X".
Proposed resolution:
Non-concept version of the proposed resolution
In [rand.dist.samp.discrete]/1, class discrete_distribution, just before the member declaration
explicit discrete_distribution(const param_type& parm);
insert:
template<typename Func> discrete_distribution(result_type nf, double xmin, double xmax, Func fw);
Between p.4 and p.5 insert a series of new paragraphs as part of the new member description::
template<typename Func> discrete_distribution(result_type nf, double xmin, double xmax, Func fw);Complexity: Exactly nf invocations of fw.
Requires:
- fw shall be callable with one argument of type double, and shall return values of a type convertible to double;
- If nf > 0, the relation xmin < xmax shall hold, and for all sample values xk, fw(xk) shall return a weight value wk that is non-negative, non-NaN, and non-infinity;
- The following relations shall hold: nf ≥ 0, and 0 < S = w0+. . .+wn-1.
Effects:
- If nf == 0, sets n = 1 and lets the sequence w have length n = 1 and consist of the single value w0 = 1.
Otherwise, sets n = nf, deltax = (xmax - xmin)/n and xcent = xmin + 0.5 * deltax.
For each k = 0, . . . ,n-1, calculates:
xk = xcent + k * deltax wk = fw(xk)
Constructs a discrete_distribution object with probabilities:
pk = wk/S for k = 0, . . . , n-1.
Concept version of the proposed resolution
In [rand.dist.samp.discrete]/1, class discrete_distribution, just before the member declaration
explicit discrete_distribution(const param_type& parm);
insert:
template<Callable<auto, double> Func> requires Convertible<Func::result_type, double> discrete_distribution(result_type nf, double xmin, double xmax, Func fw);
Between p.4 and p.5 insert a series of new paragraphs as part of the new member description::
template<Callable<auto, double> Func> requires Convertible<Func::result_type, double> discrete_distribution(result_type nf, double xmin, double xmax, Func fw);Complexity: Exactly nf invocations of fw.
Requires:
- If nf > 0, the relation xmin < xmax shall hold, and for all sample values xk, fw(xk) shall return a weight value wk that is non-negative, non-NaN, and non-infinity;
- The following relations shall hold: nf ≥ 0, and 0 < S = w0+. . .+wn-1.
Effects:
- If nf == 0, sets n = 1 and lets the sequence w have length n = 1 and consist of the single value w0 = 1.
Otherwise, sets n = nf, deltax = (xmax - xmin)/n and xcent = xmin + 0.5 * deltax.
For each k = 0, . . . ,n-1, calculates: xk = xcent + k * deltax wk = fw(xk)Constructs a discrete_distribution object with probabilities:
pk = wk/S for k = 0, . . . , n-1.
[ Pre San Francisco, Daniel provided wording: ]
The here proposed changes of the WP refer to the current state of N2691. During the Sophia Antipolis meeting two different proposals came up regarding the functor argument type, either by value or by rvalue-reference. For consistence with existing conventions (state-free algorithms and the general_pdf_distribution c'tor signature) the author decided to propose a function argument that is provided by value. If severe concerns exists that stateful functions would be of dominant relevance, it should be possible to replace the two occurrences of Func by Func&& in this proposal as part of an editorial process.
[ Sophia Antipolis: ]
Bill is not requesting this.
Marc Paterno: _Fn cannot return negative values at the points where the function is sampled. It is sampled in the middle of each bin. _Fn cannot return 0 everywhere it is sampled.
Jens: lambda expressions are rvalues
Add a library issue to provide an initializer_list<double> constructor for discrete_distribution.
Marc Paterno: dislikes reference for _Fn parameter. Make it pass-by-value (to use lambda), use std::ref to wrap giant-state function objects.
Daniel: See random_shuffle, pass-by-rvalue-reference.
Daniel to draft wording.
[ Bellevue: ]
How do you specify the function so that it does not return negative values? If you do it is a bad construction. This requirement is already there. Where in each bin does one evaluate the function? In the middle. Need to revisit tomorrow.
discrete_distribution should have a constructor like:
template<class _Fn> discrete_distribution(result_type _Count, double _Low, double _High, _Fn& _Func);
(Makes it easier to fill a histogram with function values over a range.)
History | |||
---|---|---|---|
Date | User | Action | Args |
2010-12-05 14:14:49 | admin | set | status: nad editorial -> resolved |
2010-10-21 18:28:33 | admin | set | messages: + msg3794 |
2010-10-21 18:28:33 | admin | set | messages: + msg3793 |
2010-10-21 18:28:33 | admin | set | messages: + msg3792 |
2010-10-21 18:28:33 | admin | set | messages: + msg3791 |
2010-10-21 18:28:33 | admin | set | messages: + msg3790 |
2008-02-09 00:00:00 | admin | create |