-
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.
- Loading branch information
1 parent
5f6ba99
commit 3f8e033
Showing
2 changed files
with
35 additions
and
3 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,30 @@ | ||
import pytest | ||
from scipy import stats | ||
from fit_discrete import read_file, distributions, fit_distribution, guess_bounds | ||
|
||
|
||
@pytest.mark.parametrize("key, expected", [('discrete uniform', 6.591673732008659), | ||
('beta binomial', 6.068425588244196), | ||
('zipfian', 7.86098064513523)]) | ||
def test_results(key, expected): | ||
data = read_file('test_data.txt') | ||
bounds = guess_bounds(data) | ||
|
||
res = fit_distribution(data, distributions[key], bounds[key]) | ||
assert res.success | ||
assert pytest.approx(expected, res.nllf()) | ||
|
||
|
||
def test_bounds(): | ||
data = stats.randint.rvs(low=0, high=10, size=100) | ||
bounds = guess_bounds(data) | ||
|
||
res = fit_distribution(data, stats.randint, bounds['discrete uniform']) | ||
assert res.success | ||
|
||
res = fit_distribution(data, stats.betabinom, bounds['beta binomial']) | ||
assert res.success | ||
|
||
res = fit_distribution(data, stats.zipf, bounds['zipfian']) | ||
assert res.success | ||
|