Re: [Boost-bugs] [Boost C++ Libraries] #920: Proposed extension to random library

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #920: Proposed extension to random library
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-02-09 01:11:41


#920: Proposed extension to random library
-------------------------------+--------------------------------------------
  Reporter: nobody | Owner: no-maintainer
      Type: Feature Requests | Status: new
 Milestone: | Component: random
   Version: None | Severity: Showstopper
Resolution: None | Keywords:
-------------------------------+--------------------------------------------
Changes (by marshall):

  * owner: jmaurer => no-maintainer
  * status: assigned => new
  * severity: => Showstopper

Old description:

> {{{
> I suggest adding the following utility function to
> the random library (with perhaps a name change):
>
> // PURPOSE: Sample from a set of N values given the
> // sequence p[1], p[1] + p[2], p[1] + p[2] + p[3], ...
> // of cumulative probabilities.
> //
> // REQUIRE:
> // - Type Incrementer supports the pre-increment
> // operation and equality comparison. Typically,
> // Incrementer will be an integral type or a
> // forward iterator.
> // - Pre-incrementing i some finite number of times
> // -- say, N -- makes it equal to iend.
> // - cumprob_it "points" at a nondecreasing sequence
> // of at least N nonnegative numbers, with the N-th
> // value in the sequence being equal to 1.0.
> //
> // RETURNS:
> // A random value in the interval [i, iend), with
> // cumprob_it defining the sequence of cumulative
> // probabilities.
>
> template <typename InputIterator,
> typename Incrementer,
> class UniformRandomNumberGenerator>
> Incrementer
> rand(Incrementer i, Incrementer iend,
> InputIterator cumprob_it,
> UniformRandomNumberGenerator & rng)
> {
> typedef
> std::iterator_traits<InputIterator>::value_type
> number_t;
> uniform_01<UniformRandomNumberGenerator, number_t>
> urng(rng);
> number_t p = urng();
> for ( ; p >= *cumprob_it; ++cumprob_t) {
> ++i;
> assert(!(i == iend));
> }
> return i;
> }
>
> -- Kevin S. Van Horn (Kevin_VanHorn_at_[hidden])
> }}}

New description:

 {{{
 I suggest adding the following utility function to
 the random library (with perhaps a name change):

 // PURPOSE: Sample from a set of N values given the
 // sequence p[1], p[1] + p[2], p[1] + p[2] + p[3], ...
 // of cumulative probabilities.
 //
 // REQUIRE:
 // - Type Incrementer supports the pre-increment
 // operation and equality comparison. Typically,
 // Incrementer will be an integral type or a
 // forward iterator.
 // - Pre-incrementing i some finite number of times
 // -- say, N -- makes it equal to iend.
 // - cumprob_it "points" at a nondecreasing sequence
 // of at least N nonnegative numbers, with the N-th
 // value in the sequence being equal to 1.0.
 //
 // RETURNS:
 // A random value in the interval [i, iend), with
 // cumprob_it defining the sequence of cumulative
 // probabilities.

 template <typename InputIterator,
           typename Incrementer,
           class UniformRandomNumberGenerator>
 Incrementer
 rand(Incrementer i, Incrementer iend,
      InputIterator cumprob_it,
      UniformRandomNumberGenerator & rng)
 {
   typedef
     std::iterator_traits<InputIterator>::value_type
     number_t;
   uniform_01<UniformRandomNumberGenerator, number_t>
     urng(rng);
   number_t p = urng();
   for ( ; p >= *cumprob_it; ++cumprob_t) {
     ++i;
     assert(!(i == iend));
   }
   return i;
 }

 -- Kevin S. Van Horn (Kevin_VanHorn_at_[hidden])
 }}}

--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/920#comment:2>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.


This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:57 UTC