Skip to content

Commit 3cca610

Browse files
committed
Added sample data, updated readme
1 parent f3649bb commit 3cca610

File tree

4 files changed

+118
-3
lines changed

4 files changed

+118
-3
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
# Prob-Dists-GB
22

3-
Summary of the package
3+
Python package to model probability distributions.<br>
4+
Currently supports Gaussian and Binomial Distributions
45

56
# Files
67

78
Explanation of files in the package
89

910
# Installation
1011

11-
Steps to install
12+
```
13+
pip install Prob-Dists-GB
14+
```
15+
You can find the project on PyPi [here](https://pypi.org/project/Prob-Dists-GB/)
1216

1317
# Licence
1418

15-
MIT Licence
19+
[MIT Licence](LICENCE.txt)

numbers.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
1
2+
3
3+
99
4+
100
5+
120
6+
32
7+
330
8+
23
9+
76
10+
44
11+
31

numbers_binomial.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
0
2+
1
3+
1
4+
1
5+
1
6+
1
7+
0
8+
1
9+
0
10+
1
11+
0
12+
1
13+
0

test.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import unittest
2+
3+
from distributions import Gaussian
4+
from distributions import Binomial
5+
6+
class TestGaussianClass(unittest.TestCase):
7+
def setUp(self):
8+
self.gaussian = Gaussian(25, 2)
9+
self.gaussian.read_data_file('numbers.txt')
10+
11+
def test_initialization(self):
12+
self.assertEqual(self.gaussian.mean, 25, 'incorrect mean')
13+
self.assertEqual(self.gaussian.stdev, 2, 'incorrect standard deviation')
14+
15+
def test_readdata(self):
16+
self.assertEqual(self.gaussian.data,\
17+
[1, 3, 99, 100, 120, 32, 330, 23, 76, 44, 31], 'data not read in correctly')
18+
19+
def test_meancalculation(self):
20+
self.assertEqual(self.gaussian.calculate_mean(),\
21+
sum(self.gaussian.data) / float(len(self.gaussian.data)), 'calculated mean not as expected')
22+
23+
def test_stdevcalculation(self):
24+
self.assertEqual(round(self.gaussian.calculate_stdev(), 2), 92.87, 'sample standard deviation incorrect')
25+
self.assertEqual(round(self.gaussian.calculate_stdev(0), 2), 88.55, 'population standard deviation incorrect')
26+
27+
def test_pdf(self):
28+
self.assertEqual(round(self.gaussian.pdf(25), 5), 0.19947,\
29+
'pdf function does not give expected result')
30+
self.gaussian.calculate_mean()
31+
self.gaussian.calculate_stdev()
32+
self.assertEqual(round(self.gaussian.pdf(75), 5), 0.00429,\
33+
'pdf function after calculating mean and stdev does not give expected result')
34+
35+
def test_add(self):
36+
gaussian_one = Gaussian(25, 3)
37+
gaussian_two = Gaussian(30, 4)
38+
gaussian_sum = gaussian_one + gaussian_two
39+
40+
self.assertEqual(gaussian_sum.mean, 55)
41+
self.assertEqual(gaussian_sum.stdev, 5)
42+
43+
class TestBinomialClass(unittest.TestCase):
44+
def setUp(self):
45+
self.binomial = Binomial(0.4, 20)
46+
self.binomial.read_data_file('numbers_binomial.txt')
47+
48+
def test_initialization(self):
49+
self.assertEqual(self.binomial.p, 0.4, 'p value incorrect')
50+
self.assertEqual(self.binomial.n, 20, 'n value incorrect')
51+
52+
def test_readdata(self):
53+
self.assertEqual(self.binomial.data,\
54+
[0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0], 'data not read in correctly')
55+
56+
def test_calculatemean(self):
57+
mean = self.binomial.calculate_mean()
58+
self.assertEqual(mean, 8)
59+
60+
def test_calculatestdev(self):
61+
stdev = self.binomial.calculate_stdev()
62+
self.assertEqual(round(stdev,2), 2.19)
63+
64+
def test_replace_stats_with_data(self):
65+
p, n = self.binomial.replace_stats_with_data()
66+
self.assertEqual(round(p,3), .615)
67+
self.assertEqual(n, 13)
68+
69+
def test_pdf(self):
70+
self.assertEqual(round(self.binomial.pdf(5), 5), 0.07465)
71+
self.assertEqual(round(self.binomial.pdf(3), 5), 0.01235)
72+
73+
self.binomial.replace_stats_with_data()
74+
self.assertEqual(round(self.binomial.pdf(5), 5), 0.05439)
75+
self.assertEqual(round(self.binomial.pdf(3), 5), 0.00472)
76+
77+
def test_add(self):
78+
binomial_one = Binomial(.4, 20)
79+
binomial_two = Binomial(.4, 60)
80+
binomial_sum = binomial_one + binomial_two
81+
82+
self.assertEqual(binomial_sum.p, .4)
83+
self.assertEqual(binomial_sum.n, 80)
84+
85+
86+
if __name__ == '__main__':
87+
unittest.main()

0 commit comments

Comments
 (0)