From 6030965310d3784162aff53ffd2e91933971eb8e Mon Sep 17 00:00:00 2001 From: Dylan Robertson <31269647+RobotRage@users.noreply.github.com> Date: Mon, 27 Apr 2020 10:19:21 +1000 Subject: [PATCH 1/2] feat: created bayes_theorem.cpp --- probability/bayes_theorem.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 probability/bayes_theorem.cpp diff --git a/probability/bayes_theorem.cpp b/probability/bayes_theorem.cpp new file mode 100644 index 000000000..44bac77ba --- /dev/null +++ b/probability/bayes_theorem.cpp @@ -0,0 +1,34 @@ +#include + +// bayes' theorem > https://en.wikipedia.org/wiki/Bayes%27_theorem + +// bayes' theorem allows one to find P(A|B) given P(B|A) +// or P(B|A) given P(A|B) and P(A) and P(B) + +// note P(A|B) is read 'The probability of A given that the event B has occured' + +// returns P(A|B) + +double bayes_AgivenB(double BgivenA, double A, double B) { + return (BgivenA * A) / B; +} + +// returns P(B|A) + +double bayes_BgivenA(double AgivenB, double A, double B) { + return (AgivenB * B) / A; +} + +int main() { + double A = 0.01; + double B = 0.1; + double BgivenA = 0.9; + + double AgivenB = bayes_AgivenB(BgivenA, A, B); + + + std::cout << "A given B = " << AgivenB << std::endl; + std::cout << "B given A = " << bayes_BgivenA(AgivenB, A, B) << std::endl; + + return 0; +} From b691536ea93fe5ec8eac3d95d7433693c892884b Mon Sep 17 00:00:00 2001 From: Dylan Robertson <31269647+RobotRage@users.noreply.github.com> Date: Mon, 27 Apr 2020 17:31:44 +1000 Subject: [PATCH 2/2] spacing Co-Authored-By: Christian Clauss --- probability/bayes_theorem.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/probability/bayes_theorem.cpp b/probability/bayes_theorem.cpp index 44bac77ba..d30be6c9a 100644 --- a/probability/bayes_theorem.cpp +++ b/probability/bayes_theorem.cpp @@ -23,12 +23,8 @@ int main() { double A = 0.01; double B = 0.1; double BgivenA = 0.9; - double AgivenB = bayes_AgivenB(BgivenA, A, B); - - std::cout << "A given B = " << AgivenB << std::endl; std::cout << "B given A = " << bayes_BgivenA(AgivenB, A, B) << std::endl; - return 0; }