
On Tue, Jun 5, 2012 at 9:51 AM, sguazt <marco.guazzone@gmail.com> wrote:
On Tue, Jun 5, 2012 at 7:57 AM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Thanks Steven!
[cut]
The algorithm generates a table that looks like this:
std::vector<std::pair<double, int> > table = { { 0.3, 1 }, { 0.5, 2 }, { 1.0, 0 } };
Then the generation algorithm is
double x = uniform_01<>(engine); int result = uniform_int<>(0, 2)(engine); if (x < table[result].first) return result; else return table[result].second;
Sorry, I didn't have enough background knowledge on this topic.
My error was to relate the U(0,1) x number to a CDF value. Anyway I performed a Monte-Carlo simulation and the results (the empirical PDF) match with the original PDF.
Since I still don't understand how event weights are preserved and I don't find a way to get the Walker's paper http://dx.doi.org/10.1145/355744.355749 could you point me to some reference or URL so that I can get acquainted with Walker's method?
Got it! I found Walker's method in Knuth "The Art of Computer Programming, Vol 2". Thank you -- Marco