### Re^3: Fastest way to calculate hypergeometric distribution probabilities (i.e. BIG factorials)?

by Zaxo (Archbishop)
 on Jun 14, 2005 at 04:51 UTC ( #466381=note: print w/replies, xml ) Need Help??

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)?

Replies are listed 'Best First'.
Re^4: Fastest way to calculate hypergeometric distribution probabilities (i.e. BIG factorials)?
by salva (Abbot) 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

Create A New User
Node Status?
node history
Node Type: note [id://466381]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2020-01-21 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
The worst excuse I have ever heard is:

Results (100 votes). Check out past polls.

Notices?