From c480e7e95f3ae6a1462fcdb3a47f2489a3876143 Mon Sep 17 00:00:00 2001 From: Cameron More <123985185+cameronmore@users.noreply.github.com> Date: Wed, 18 Dec 2024 13:22:59 -0500 Subject: [PATCH] added probability module --- src/statsy/Probability.py | 45 +++++++++++++++++++++++++++++++++++++++ src/statsy/__init__.py | 3 ++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/statsy/Probability.py diff --git a/src/statsy/Probability.py b/src/statsy/Probability.py new file mode 100644 index 0000000..161d24f --- /dev/null +++ b/src/statsy/Probability.py @@ -0,0 +1,45 @@ +from .main import * + +def simple_probability(desired_outcomes:str,total_outcomes:str)->Number: + """ + Returns the probability of a set of outcomes A out of the number of all equally likely outcomes B. \n + """ + return desired_outcomes / total_outcomes + +def joint_probability(a:Number,b:Number)->Number: + """ + Returns the joint probability of A and B where A and B are independent outcomes. \n + Formula: P (A and B) = P (A) X P (B) \n + Also known as conjunctive probability. \n + """ + return a * b + +def bare_joint_probability(a_desired:Number,a_possible:Number,b_desired:Number,b_possible:Number)->Number: + """ + Returns the joint probability of A and B where A and B are independent outcomes and P(A) and P(B) must be calculated. \n + Formula: P (A and B) = P (A) X P (B) \n + Where P(A) and P(B) are not known. \n + """ + return simple_probability(a_desired,a_possible) * simple_probability(b_desired,b_possible) + +def disjunctive_probability(P_of_a:Number,P_of_b:Number,P_of_a_and_b:Optional[Number]=None): + """ + Returns the disjunctive probability of A where A and B are independent outcomes. \n + Formula: P (A or B) = P (A) + P (B) - P (A and B) \n + Where P(A) , P(B), and P(A and B) is known. + """ + jp = joint_probability(P_of_a,P_of_b) + if P_of_a_and_b is not None: + jp = P_of_a_and_b + return P_of_a + P_of_b - jp + +def bare_disjunctive_probability(a_desired:Number,a_possible:Number,b_desired:Number,b_possible:Number)->Number: + """ + Returns the disjunctive probability of A where A and B are independent outcomes. \n + Formula: P (A or B) = P (A) + P (B) - P (A and B) \n + Where P(A) and P(B) are not known. \n + """ + P_of_a = simple_probability(a_desired,a_possible) + P_of_b = simple_probability(b_desired,b_possible) + jp = joint_probability(P_of_a,P_of_b) + return P_of_a + P_of_b - jp diff --git a/src/statsy/__init__.py b/src/statsy/__init__.py index e69964e..da29932 100644 --- a/src/statsy/__init__.py +++ b/src/statsy/__init__.py @@ -7,4 +7,5 @@ from .Conversion import * from .Constants import * from .Logarithms import * -from .Methods import * \ No newline at end of file +from .Methods import * +from .Probability import * \ No newline at end of file