From 2fbedfeb07627eb5116aa1ffb1f51e208afbbae2 Mon Sep 17 00:00:00 2001 From: Vhizux Date: Fri, 23 Oct 2020 14:45:47 +0200 Subject: [PATCH] added conditional probability generator --- mathgenerator/funcs/__init__.py | 1 + mathgenerator/funcs/conitionalProbability.py | 25 ++++++++++++++++++++ test.py | 10 ++++---- 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 mathgenerator/funcs/conitionalProbability.py diff --git a/mathgenerator/funcs/__init__.py b/mathgenerator/funcs/__init__.py index c48f9d8..b565e30 100644 --- a/mathgenerator/funcs/__init__.py +++ b/mathgenerator/funcs/__init__.py @@ -105,3 +105,4 @@ from .power_of_powers import * from .quotient_of_power_same_base import * from .quotient_of_power_same_power import * from .complex_quadratic import * +from .conitionalProbability import * diff --git a/mathgenerator/funcs/conitionalProbability.py b/mathgenerator/funcs/conitionalProbability.py new file mode 100644 index 0000000..b7182b6 --- /dev/null +++ b/mathgenerator/funcs/conitionalProbability.py @@ -0,0 +1,25 @@ +from .__init__ import * + +def conditionalProbFunc(): + P_disease= round(2.*random.random(), 2) + true_positive= round(random.random()+float(random.randint(90,99)), 2) + true_negative= round(random.random()+float(random.randint(90,99)), 2) + + def BayesFormula(P_disease, true_positive, true_negative): + P_notDisease= 100.-P_disease + false_positive= 100.-true_negative + false_negative= 100.-false_positive + P_plus= (P_disease)*(true_positive)+(P_notDisease)*(false_positive) + P_disease_plus=( (true_positive)*(100*P_disease) )/P_plus + + return P_disease_plus + + problem= "Someone tested positive for a nasty disease which only {0:.2f}% of population have. " \ + "Test sensitivity (true positive) is equal to SN= {1:.2f}% whereas test specificity (true negative) SP= {2:.2f}%. " \ + "What is the probability that this guy really has that disease?".format(P_disease, true_positive, true_negative ) + + answer=str(round(BayesFormula(P_disease, true_positive, true_negative), 2))+"%" + + return problem, answer + +conditionalProb= Generator("Conditional Probability", 101, "P(A|+)=", "c", conditionalProbFunc) \ No newline at end of file diff --git a/test.py b/test.py index 8f1bf49..ee450c0 100644 --- a/test.py +++ b/test.py @@ -2,12 +2,12 @@ from mathgenerator import mathgen # test your generators here -print(mathgen.addition()) +# print(mathgen.addition()) # prints each generator in genList -list = mathgen.getGenList() -for item in list: - print(item[2]) +# list = mathgen.getGenList() +# for item in list: +# print(item[2]) # print(mathgen.getGenList()) -print(mathgen.genById(100)) +print(mathgen.genById(101))