-
Notifications
You must be signed in to change notification settings - Fork 18
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
Showing
4 changed files
with
118 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
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) |
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,11 @@ | ||
1 | ||
3 | ||
99 | ||
100 | ||
120 | ||
32 | ||
330 | ||
23 | ||
76 | ||
44 | ||
31 |
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,13 @@ | ||
0 | ||
1 | ||
1 | ||
1 | ||
1 | ||
1 | ||
0 | ||
1 | ||
0 | ||
1 | ||
0 | ||
1 | ||
0 |
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,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() |