Skip to content

Commit

Permalink
Added sample data, updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
hot9cups committed Oct 24, 2020
1 parent f3649bb commit 3cca610
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 3 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# Prob-Dists-GB

Summary of the package
Python package to model probability distributions.<br>
Currently supports Gaussian and Binomial Distributions

# Files

Explanation of files in the package

# Installation

Steps to install
```
pip install Prob-Dists-GB
```
You can find the project on PyPi [here](https://pypi.org/project/Prob-Dists-GB/)

# Licence

MIT Licence
[MIT Licence](LICENCE.txt)
11 changes: 11 additions & 0 deletions numbers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1
3
99
100
120
32
330
23
76
44
31
13 changes: 13 additions & 0 deletions numbers_binomial.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
0
1
1
1
1
1
0
1
0
1
0
1
0
87 changes: 87 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import unittest

from distributions import Gaussian
from distributions import Binomial

class TestGaussianClass(unittest.TestCase):
def setUp(self):
self.gaussian = Gaussian(25, 2)
self.gaussian.read_data_file('numbers.txt')

def test_initialization(self):
self.assertEqual(self.gaussian.mean, 25, 'incorrect mean')
self.assertEqual(self.gaussian.stdev, 2, 'incorrect standard deviation')

def test_readdata(self):
self.assertEqual(self.gaussian.data,\
[1, 3, 99, 100, 120, 32, 330, 23, 76, 44, 31], 'data not read in correctly')

def test_meancalculation(self):
self.assertEqual(self.gaussian.calculate_mean(),\
sum(self.gaussian.data) / float(len(self.gaussian.data)), 'calculated mean not as expected')

def test_stdevcalculation(self):
self.assertEqual(round(self.gaussian.calculate_stdev(), 2), 92.87, 'sample standard deviation incorrect')
self.assertEqual(round(self.gaussian.calculate_stdev(0), 2), 88.55, 'population standard deviation incorrect')

def test_pdf(self):
self.assertEqual(round(self.gaussian.pdf(25), 5), 0.19947,\
'pdf function does not give expected result')
self.gaussian.calculate_mean()
self.gaussian.calculate_stdev()
self.assertEqual(round(self.gaussian.pdf(75), 5), 0.00429,\
'pdf function after calculating mean and stdev does not give expected result')

def test_add(self):
gaussian_one = Gaussian(25, 3)
gaussian_two = Gaussian(30, 4)
gaussian_sum = gaussian_one + gaussian_two

self.assertEqual(gaussian_sum.mean, 55)
self.assertEqual(gaussian_sum.stdev, 5)

class TestBinomialClass(unittest.TestCase):
def setUp(self):
self.binomial = Binomial(0.4, 20)
self.binomial.read_data_file('numbers_binomial.txt')

def test_initialization(self):
self.assertEqual(self.binomial.p, 0.4, 'p value incorrect')
self.assertEqual(self.binomial.n, 20, 'n value incorrect')

def test_readdata(self):
self.assertEqual(self.binomial.data,\
[0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0], 'data not read in correctly')

def test_calculatemean(self):
mean = self.binomial.calculate_mean()
self.assertEqual(mean, 8)

def test_calculatestdev(self):
stdev = self.binomial.calculate_stdev()
self.assertEqual(round(stdev,2), 2.19)

def test_replace_stats_with_data(self):
p, n = self.binomial.replace_stats_with_data()
self.assertEqual(round(p,3), .615)
self.assertEqual(n, 13)

def test_pdf(self):
self.assertEqual(round(self.binomial.pdf(5), 5), 0.07465)
self.assertEqual(round(self.binomial.pdf(3), 5), 0.01235)

self.binomial.replace_stats_with_data()
self.assertEqual(round(self.binomial.pdf(5), 5), 0.05439)
self.assertEqual(round(self.binomial.pdf(3), 5), 0.00472)

def test_add(self):
binomial_one = Binomial(.4, 20)
binomial_two = Binomial(.4, 60)
binomial_sum = binomial_one + binomial_two

self.assertEqual(binomial_sum.p, .4)
self.assertEqual(binomial_sum.n, 80)


if __name__ == '__main__':
unittest.main()

0 comments on commit 3cca610

Please sign in to comment.