Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by salva (Canon)
on Jun 14, 2005 at 08:15 UTC ( #466422=note: print w/replies, xml ) Need Help??


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

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.
  • Comment on Re^4: Fastest way to calculate hypergeometric distribution probabilities (i.e. BIG factorials)?
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://466422]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2021-05-13 14:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (135 votes). Check out past polls.

    Notices?