Re: Sampling from a generic distribution

From: Giuseppe Battistoni <Giuseppe.Battistoni@mi.infn.it>
Date: Tue May 20 2008 - 15:13:33 CEST

Thank you Noemi.
Of course the proposed algorithm can be optimized, depending on fu(x),
otherwise it might be very unefficient in some cases.
In practice you are rejecting
against a straight line parallel to x-axis: y = fumax (for simplicity
let us pretend that fumin=0).

If fu(x) is a steep descending function, you might loose a lot of time
looping inside that algorithm. In that case
if you are able to find another descending function g(x) different from
y=fumax, but at the same time such as y = g(x) > f(x) for any x in the
range of interest, AND that you can easily sample in a direct way, then
it can be much more efficient to reject against g(XIII) than against
fumax (how much convenient depends on the integral of g(x)/fu(x))

Probably it is not easy to explain this by email, but I hope we can meet
at on eof the next courses, so I can explain it better.

If you miss the CERN course, please consider the one in Paris at the end
of September

        Kind regards
                        Giuseppe

On Tue, 20 May 2008, Finetti Noemi wrote:

> Dear Giuseppe,
> thank you very much for your advice, I gave a look at the material of
> the last FLUKA course at Laboratori Nazionali di Legnaro (MCstat.pdf)
> and I implemented in my source subroutine the following simple algorithm
> for sampling from a generic distribution:
> c-----------------
> 5 CONTINUE
> XIII = emin+(emax-emin)*FLRNDM(XIIIDUMMY)
> YFUNC=fu(XIII)
> YIII = fumin+(fumax-fumin)*FLRNDM(YIIIDUMMY)
> IF(YIII.gt.YFUNC) GO TO 5
> kk=kk+1
> SAMPLE = XIII
> c-----------------
> where fu is a generic function declared external, fumax and fumin are
> the maximum and the minimum value of the fuction fu (corresponding to
> energy emax and emin respectively). It seams to work properly!
> Unfortunately I cannot attend the next FLUKA course at Cern, but I hope
> to attend one of the next FLUKA courses.
> Kind regards,
> noemi
>
> Giuseppe Battistoni wrote:
>
> >Dear Noemi,
> >it could be useful for you to study the material of the last
> >FLUKA course (see http://www.fluka.org/course/Legnaro-07/Lectures/)
> >
> >For your last questions please give a look at MCstat.pdf
> >and the last part of UserRoutines.pdf where some useful additional
> >routines of FLUKA are mentioned.
> >
> >P.S.: did you consider the opportunity of attending one of the next
> >FLUKA couuses?
> >
> > Giuseppe
> >
> >
> >
> >
> >
>
>
Received on Tue May 20 15:16:46 2008

This archive was generated by hypermail 2.1.8 : Tue May 20 2008 - 16:00:16 CEST