shapiq.utils.log_binomΒΆ
- shapiq.utils.log_binom(n, k)[source]ΒΆ
Natural logarithm of the binomial coefficient
log(binom(n, k)).Computed via
scipy.special.gammaln()asgammaln(n + 1) - gammaln(k + 1) - gammaln(n - k + 1). This stays finite for largenwherescipy.special.binom()overflows toinf(the central coefficientbinom(n, n/2)exceeds the float64 range already atnof roughly1029). Keeping the binomial in log-space lets the Shapley/SII weights and the sampling probabilities β whose ratios stay well-scaled even when the individual coefficients are astronomically large β be combined without intermediate overflow/underflow.- Parameters:
- Return type:
- Returns:
log(binom(n, k))as a float (scalark) or a numpy array (arrayk).