Skip to content

Commit

Permalink
Merge pull request #16 from sanjaymjoshi/notebooks
Browse files Browse the repository at this point in the history
Bug fix and notebook update
  • Loading branch information
sanjaymjoshi authored Apr 6, 2024
2 parents d456d4f + 08b2f7c commit b2a425e
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 32 deletions.
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Concepts
This library provides methods to calculate these statistics for infinite and finite
population sizes.

It also includes interactive notebooks that you can access on Google colab:
1. [Reliability and Confidence](https://colab.research.google.com/github/sanjaymjoshi/relistats/blob/main/examples/01_reliability_confidence.ipynb)

Example usage in a python file:

.. code-block:: python
Expand All @@ -41,7 +44,7 @@ Example usage in a python file:
n = 22
a = assurance(n, 0) or 0
print(f"Assurance at {n} good samples: {a*100:.1f}%")
print(f"Assurance at {n} good samples: {a:.1%}%")
References
----------
Expand Down

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 3 additions & 5 deletions relistats/binom_fin.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,21 @@ def reli_fin(n: int, f: int, c: float, m: int) -> tuple:
# This line is never reached in pytest!


def assur_fin(n: int, f: int, m: int, tol=0.001) -> tuple:
def assur_fin(n: int, f: int, m: int) -> tuple:
"""Assurance [0, 1], i.e., confidence = reliability.
Returns tuple of assurance and actual values of reliability
and confidence used for computations.
:param n: number of samples
:type n: int, >=0
:param f: number of failures
:type f: int, >=0
:type f: int, 0 <= f <= n
:param m: remaining samples in population
:type m: int, >= 0
:param tol: accuracy tolerance
:type tol: float, optional
:return: (Assurance, reliability, confidence)
:rtype: tuple
"""
if n <= 0 or f < 0:
if n <= 0 or f < 0 or n < f:
return (None, 0, 0)

# Calculate confidence for each case of remaining failures
Expand Down
5 changes: 5 additions & 0 deletions test/test_binom_fin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def test_conf_fin() -> None:
assert conf_fin(2, 0, 2, -2) == (None, None)
assert conf_fin(2, 0, -2, -2) == (None, None)

assert conf_fin(20, 21, 20, 2) == pytest.approx(
(0.0, 0.425), abs=ABS_TOL_CONFIDENCE
)


def test_reli_fin() -> None:
ABS_TOL_RELIABILITY = 0.001
Expand Down Expand Up @@ -89,3 +93,4 @@ def test_assurance() -> None:

assert assur_fin(2, -2, 2) == (None, 0, 0)
assert assur_fin(-2, 0, 2) == (None, 0, 0)
assert assur_fin(20, 21, 8) == (None, 0, 0)
1 change: 1 addition & 0 deletions test/test_binomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def test_assurance() -> None:
assert assurance(22, 2) == pytest.approx(0.812, abs=0.001)
assert assurance(59, 6) == pytest.approx(0.842, abs=0.001)
assert assurance(59, 10, 0.0001) == pytest.approx(0.7798, abs=0.0001)
assert assurance(20, 21) == pytest.approx(0.0, abs=0.001)

assert assurance(2, -2) is None
assert assurance(-2, 0) is None

0 comments on commit b2a425e

Please sign in to comment.