def binomial_factorial(self):
r"""
Implementation of the binomial coefficient computation. Not meant for actual computation
as the other methods available are more efficient.
Parameters
----------
n : int
Number of possibilities
k : int
number of unordered outcomes
Returns
-------
float
The binomial coefficient
Notes
-----
The binomial coefficient equation (in compact form) is defined as:
.. math::
\binom{n}{k} = \frac{n!}{k!(n-k)!} \qquad 0 \leq k \leq n
References
----------
Binomial coefficient. (2017, April 17). In Wikipedia, The Free Encyclopedia.
From https://en.wikipedia.org/w/index.php?title=Binomial_coefficient&oldid=775905810
Press, W., Teukolsky, S., Vetterling, W., & Flannery, B. (2007). Numerical recipes (3rd ed.).
Cambridge: Cambridge University Press.
Weisstein, Eric W. "Binomial Coefficient." From MathWorld--A Wolfram Web Resource.
http://mathworld.wolfram.com/BinomialCoefficient.html
"""
nk = np.minimum(self.n, self.n - self.k)
if nk >= 100:
with localcontext() as ctx:
ctx.prec = 50
bico = Decimal(factorial(self.n)) / (Decimal(factorial(self.k)) * Decimal(factorial(nk)))
else:
bico = float(factorial(self.n)) / float(factorial(self.k) * factorial(nk))
return bico
评论列表
文章目录