def test_hypergeom_logpmf(): # symmetries test # f(k,N,K,n) = f(n-k,N,N-K,n) = f(K-k,N,K,N-n) = f(k,N,n,K) k = 5 N = 50 K = 10 n = 5 logpmf1 = hypergeom.logpmf(k, N, K, n) logpmf2 = hypergeom.logpmf(n - k, N, N - K, n) logpmf3 = hypergeom.logpmf(K - k, N, K, N - n) logpmf4 = hypergeom.logpmf(k, N, n, K) assert_almost_equal(logpmf1, logpmf2, decimal=12) assert_almost_equal(logpmf1, logpmf3, decimal=12) assert_almost_equal(logpmf1, logpmf4, decimal=12) # test related distribution # Bernoulli distribution if n = 1 k = 1 N = 10 K = 7 n = 1 hypergeom_logpmf = hypergeom.logpmf(k, N, K, n) bernoulli_logpmf = bernoulli.logpmf(k, K / N) assert_almost_equal(hypergeom_logpmf, bernoulli_logpmf, decimal=12)
def test_hypergeom_logpmf(): # symmetries test # f(k,N,K,n) = f(n-k,N,N-K,n) = f(K-k,N,K,N-n) = f(k,N,n,K) k = 5 N = 50 K = 10 n = 5 logpmf1 = hypergeom.logpmf(k,N,K,n) logpmf2 = hypergeom.logpmf(n-k,N,N-K,n) logpmf3 = hypergeom.logpmf(K-k,N,K,N-n) logpmf4 = hypergeom.logpmf(k,N,n,K) assert_almost_equal(logpmf1, logpmf2, decimal=12) assert_almost_equal(logpmf1, logpmf3, decimal=12) assert_almost_equal(logpmf1, logpmf4, decimal=12) # test related distribution # Bernoulli distribution if n = 1 k = 1 N = 10 K = 7 n = 1 hypergeom_logpmf = hypergeom.logpmf(k,N,K,n) bernoulli_logpmf = bernoulli.logpmf(k,K/N) assert_almost_equal(hypergeom_logpmf, bernoulli_logpmf, decimal=12)
def inside_sum(K): if K == 0: return 1. K_over_N = K/float(N) return sum([ exp(hypergeom.logpmf(k, N, K, m) + m*d_function(k*one_over_m, K_over_N, m_over_N) ) for k in np.arange( max(0,K+m-N), min(m,K)+1 ) ])
def log_pmf(self, x, n, p): logpmf = hypergeom.logpmf(x, n, p) return logpmf