Skip to content

Commit

Permalink
Add image
Browse files Browse the repository at this point in the history
  • Loading branch information
elena-pascal committed Sep 22, 2022
1 parent 19104db commit 45322dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions fit_discrete.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Tool to fit discrete distributions to a set of data

# This version fits the discrete uniform, beta binomal and Zipfian distributions
# Usage:
# >>> fit_discrete.py test_data.txt

import numpy as np
from scipy import stats
Expand Down Expand Up @@ -54,10 +56,10 @@ def fit_distribution(sample_data: np.array, distribution: stats.rv_discrete, bou
def guess_bounds(sample_data: np.array):
low = min(sample_data)
high = max(sample_data)
rough_bounds = {'uniform': {'low': low, 'high': high+1, 'loc': (low-1, high)},
'betabinom': {'n': high-low, 'a': (0, high*10), 'b': (0, high*10), 'loc': (low-1, high)},
'zipf': {'a': (-1, high*10), 'loc': (low-1, high)}
}
rough_bounds = {'discrete uniform': {'low': low, 'high': high+1, 'loc': (low-1, high)},
'beta binomial': {'n': high-low, 'a': (0, high*10), 'b': (0, high*10), 'loc': (low-1, high)},
'zipfian': {'a': (-1, high*10), 'loc': (low-1, high)}
}
return rough_bounds


Expand All @@ -70,11 +72,14 @@ def set_plot(rows: int = 2, cols: int = 2):

if __name__ == '__main__':
data = read_file('test_data.txt')

axs = set_plot()

show_data(data, ax=axs[0], title='Input data')

distributions = {'uniform': stats.randint, 'betabinom': stats.betabinom, 'zipf': stats.zipf}
distributions = {'discrete uniform': stats.randint,
'beta binomial': stats.betabinom,
'zipfian': stats.zipf}
bounds = guess_bounds(data)

for i, (key, dist) in enumerate(distributions.items()):
Expand Down
Binary file added fits.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 45322dd

Please sign in to comment.