Besides
BrowserUk suggestion (that's probably the way to go), some simple modifications on logfact (inlining things and eliminating unnecessary temporaries) makes it twice as fast:
sub hypergeom1 {
# There are m "bad" and n "good" balls in an urn.
# Pick N of them. The probability of i or more successful selectio
+ns:
# (m!n!N!(m+n-N)!)/(i!(n-i)!(m+i-N)!(N-i)!(m+n)!)
my ($n, $m, $N, $i) = @_;
my $loghyp1 = logfact1($m) +logfact1($n)+logfact1($N)+logfact1($m+
+$n-$N);
my $loghyp2 = logfact1($i)+logfact1($n-$i)+logfact1($m+$i-$N)+logf
+act1($N-$i)+logfact1($m+$n);
return exp($loghyp1 - $loghyp2);
}
sub logfact1 {
my $x = shift;
my $ser = ( 1.000000000190015
+ 76.18009172947146 / ($x + 2)
- 86.50532032941677 / ($x + 3)
+ 24.01409824083091 / ($x + 4)
- 1.231739572450155 / ($x + 5)
+ 0.12086509738661e-2 / ($x + 6)
- 0.5395239384953e-5 / ($x + 7) );
my $tmp = $x + 6.5;
($x + 1.5) * log($tmp) - $tmp + log(2.5066282746310005 * $ser / ($
+x+1));
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.