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.pconst]/1, class piecewise_constant_distribution, just before the member declaration
explicit piecewise_constant_distribution(const param_type& parm);
insert:
template<typename Func> piecewise_constant_distribution(size_t nf, RealType xmin, RealType xmax, Func fw);
Between p.4 and p.5 insert a new sequence of paragraphs nominated below as [p5_1], [p5_2], [p5_3], and [p5_4] as part of the new member description:
template<typename Func> piecewise_constant_distribution(size_t nf, RealType xmin, RealType xmax, Func fw);[p5_1] Complexity: Exactly nf invocations of fw.
[p5_2] Requires:
- fw shall be callable with one argument of type RealType, and shall return values of a type convertible to double;
- For all sample values xk defined below, fw(xk) shall return a weight value wk that is non-negative, non-NaN, and non-infinity;
- The following relations shall hold: xmin < xmax, and 0 < S = w0+. . .+wn-1.
[p5_3] Effects:
If nf == 0,
- sets deltax = xmax - xmin, and
- lets the sequence w have length n = 1 and consist of the single value w0 = 1, and
- lets the sequence b have length n+1 with b0 = xmin and b1 = xmax
Otherwise,
- sets n = nf, deltax = (xmax - xmin)/n, xcent = xmin + 0.5 * deltax, and
lets the sequences w and b have length n and n+1, resp. and
for each k = 0, . . . ,n-1, calculates: dxk = k * deltax bk = xmin + dxk xk = xcent + dxk wk = fw(xk),and
- sets bn = xmax
Constructs a piecewise_constant_distribution object with the above computed sequence b as the interval boundaries and with the probability densities:
ρk = wk/(S * deltax) for k = 0, . . . , n-1.
[p5_4] [Note: In this context, the subintervals [bk, bk+1) are commonly known as the bins of a histogram. -- end note]
Concept version of the proposed resolution
In [rand.dist.samp.pconst]/1, class piecewise_constant_distribution, just before the member declaration
explicit piecewise_constant_distribution(const param_type& parm);
insert:
template<Callable<auto, RealType> Func> requires Convertible<Func::result_type, double> piecewise_constant_distribution(size_t nf, RealType xmin, RealType xmax, Func fw);
Between p.4 and p.5 insert a new sequence of paragraphs nominated below as [p5_1], [p5_2], [p5_3], and [p5_4] as part of the new member description:
template<Callable<auto, RealType> Func> requires Convertible<Func::result_type, double> piecewise_constant_distribution(size_t nf, RealType xmin, RealType xmax, Func fw);[p5_1] Complexity: Exactly nf invocations of fw.
[p5_2] Requires:
- For all sample values xk defined below, fw(xk) shall return a weight value wk that is non-negative, non-NaN, and non-infinity;
- The following relations shall hold: xmin < xmax, and 0 < S = w0+. . .+wn-1.
[p5_3] Effects:
If nf == 0,
- sets deltax = xmax - xmin, and
- lets the sequence w have length n = 1 and consist of the single value w0 = 1, and
- lets the sequence b have length n+1 with b0 = xmin and b1 = xmax
Otherwise,
- sets n = nf, deltax = (xmax - xmin)/n, xcent = xmin + 0.5 * deltax, and
lets the sequences w and b have length n and n+1, resp. and
for each k = 0, . . . ,n-1, calculates: dxk = k * deltax bk = xmin + dxk xk = xcent + dxk wk = fw(xk),and
- sets bn = xmax
Constructs a piecewise_constant_distribution object with the above computed sequence b as the interval boundaries and with the probability densities:
ρk = wk/(S * deltax) for k = 0, . . . , n-1.
[p5_4] [Note: In this context, the subintervals [bk, bk+1) are commonly known as the bins of a histogram. -- end note]
[ Pre San Francisco, Daniel provided wording. ]
The here proposed changes of the WP refer to the current state of N2691. For reasons explained in 793, the author decided to propose a function argument that is provided by value. The issue proposes a c'tor signature, that does not take advantage of the full flexibility of piecewise_constant_distribution, because it restricts on a constant bin width, but the use-case seems to be popular enough to justify it's introduction.
[ Sophia Antipolis: ]
Marc: uses variable width of bins and weight for each bin. This is not giving enough flexibility to control both variables.
Add a library issue to provide an constructor taking an initializer_list<double> and _Fn for piecewise_constant_distribution.
Daniel to draft wording.
piecewise_constant_distribution should have a constructor like:
template<class _Fn> piecewise_constant_distribution(size_t _Count, _Ty _Low, _Ty _High, _Fn& _Func);
(Makes it easier to fill a histogram with function values over a range. The two (reference 793) make a sensible replacement for general_pdf_distribution.)
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: + msg3799 |
2010-10-21 18:28:33 | admin | set | messages: + msg3798 |
2010-10-21 18:28:33 | admin | set | messages: + msg3797 |
2010-10-21 18:28:33 | admin | set | messages: + msg3796 |
2008-02-09 00:00:00 | admin | create |