forked from scipy/scipy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request scipy#6946 from evgenyzhurko/hypergeom-betaln
ENH: hypergeom.logpmf in terms of betaln
- Loading branch information
Showing
2 changed files
with
38 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from __future__ import division, print_function, absolute_import | ||
|
||
from scipy.stats import hypergeom, bernoulli | ||
import numpy as np | ||
from numpy.testing import assert_almost_equal, run_module_suite | ||
|
||
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) | ||
|
||
|
||
if __name__ == "__main__": | ||
run_module_suite() |