in reply to Re^2: Fastest way to calculate hypergeometric distribution probabilities (i.e. BIG factorials)?
in thread Fastest way to calculate hypergeometric distribution probabilities (i.e. BIG factorials)?

Good idea, but no cigar.

$ perl -MMath::Gsl::Sf=:Gamma -e'print gamma(300)' gsl: gamma.c:1111: ERROR: overflow Default GSL error handler invoked. Aborted (core dumped) $
The GSL doesn't handle large numbers.

There's also a math error to correct: gamma($n) == factorial($n - 1)

After Compline,
Zaxo

  • Comment on Re^3: Fastest way to calculate hypergeometric distribution probabilities (i.e. BIG factorials)?
  • Select or Download Code

Replies are listed 'Best First'.
Re^4: Fastest way to calculate hypergeometric distribution probabilities (i.e. BIG factorials)?
by salva (Canon) on Jun 14, 2005 at 08:15 UTC
    if your calculations over the factorial numbers are only multiplications and divisions (as I think they are), you can operate over their log values instead, transforming multiplications and divisions to additions and substractions respectively. i.e.:
    log ($n! / ($r! * ($n-$r)!) = Sum(log(1)..log($n)) - Sum(log(1)..log($r)) - Sum(log(1)..log($n-$r))
    and as your operations will only involve a small number of integers, you can cache log($n) and log($n!) to speed up the calculations.
Re^4: Fastest way to calculate hypergeometric distribution probabilities (i.e. BIG factorials)?
by mrborisguy (Hermit) on Jun 14, 2005 at 13:05 UTC

    Really... all along I thought gamma was equal to the factorial. That's new to me, thanks!

        -Bryan