berkay-yalin / promethium

Library for calculating statistical distributions, written in pure Python with zero dependencies.
https://pypi.org/project/promethium/
GNU General Public License v3.0
4 stars 3 forks source link

Lower and Upper Bounds for Cumulative Probability Functions #1

Open stanislaw-marc opened 1 year ago

stanislaw-marc commented 1 year ago

Currently, the cumulative probability functions only have the upper bound as a parameter (k in both cases), and use 0 for the lower bound.

https://github.com/berkay-yalin/python-probabilities/blob/c9c9e55a444bec83d71221a26fa5fe181d8c669f/python_probabilities/distributions_binomial.py#L21-L22

https://github.com/berkay-yalin/python-probabilities/blob/c9c9e55a444bec83d71221a26fa5fe181d8c669f/python_probabilities/distributions_poisson.py#L21-L22

This approach works well when calculating probabilities below a certain number (e.g., P(X≤7)), but becomes more complicated when trying to calculate a range of values (e.g., P(4≤X≤7)).

In this case, to calculate it using the currently available functions we would have to calculate the following P(X≤7) - P(X≤3). For example, if we were using a binomial distribution of X ~ B(11, 0.33), we would calculate P(4≤X≤7) like this:

from python_probabilities import *
print(Bcd(7,11,0.33) - Bcd(3,11,0.33))

Which gives us an output of 0.5096391069522413707200.

Therefore, I suggest adding an optional lower parameter to the cumulative probability functions, which would default to 0 if not passed into the function. This would make it easier to calculate the probability of a range of values without the need to subtract two probabilities. Additionally, this would increase the efficiency of the algorithm, as it would avoid the need for the functions to iterate twice through the same probabilities.

Cillian2113 commented 1 year ago

Great job buddy