Example #1
0
    void DiscreteInverter<RNG,B>::resetProbabilityMap( const PairIter & begin,
                                                     const PairIter & end ) {
      /** Integral of P(v):  Int[P(v), {v, 0, inf}]. */
      double IntP_total = 0.0;
      /** The integral of P(v):  { Int[P(v),{v,0,v'}], v' }. */
      std::vector< std::pair<double,double> > IntP;

      for ( PairIter i = begin; i != end; ++i ) {
        if ( i->second <= 0.0 )
          /* we skip anthing that has zero probabilty. */
          continue;

        IntP_total += i->second;
        IntP.push_back( std::make_pair( IntP_total, i->first ) );
      }

      /* normalize the integral and store the probability map. */
      using detail::MultiplyFirst;
      std::for_each(IntP.begin(), IntP.end(), MultiplyFirst(1./IntP_total));
      prob_map = std::map<double,double>(IntP.begin(), IntP.end());
    }