Algorithms_in_C++  1.0.0
Set of algorithms implemented in C++.
bayes_theorem.cpp File Reference

Bayes' theorem More...

#include <iostream>
Include dependency graph for bayes_theorem.cpp:

Functions

double bayes_AgivenB (double BgivenA, double A, double B)
 
double bayes_BgivenA (double AgivenB, double A, double B)
 
int main ()
 

Detailed Description

Bayes' 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 that \(P(A|B)\) is read 'The probability of A given that the event B has occured'.

Function Documentation

◆ bayes_AgivenB()

double bayes_AgivenB ( double  BgivenA,
double  A,
double  B 
)

returns P(A|B)

14  {
15  return (BgivenA * A) / B;
16 }

◆ bayes_BgivenA()

double bayes_BgivenA ( double  AgivenB,
double  A,
double  B 
)

returns P(B|A)

20  {
21  return (AgivenB * B) / A;
22 }

◆ main()

int main ( void  )

Main function

26  {
27  double A = 0.01;
28  double B = 0.1;
29  double BgivenA = 0.9;
30  double AgivenB = bayes_AgivenB(BgivenA, A, B);
31  std::cout << "A given B = " << AgivenB << std::endl;
32  std::cout << "B given A = " << bayes_BgivenA(AgivenB, A, B) << std::endl;
33  return 0;
34 }
Here is the call graph for this function:
std::cout
bayes_BgivenA
double bayes_BgivenA(double AgivenB, double A, double B)
Definition: bayes_theorem.cpp:20
std::endl
T endl(T... args)
bayes_AgivenB
double bayes_AgivenB(double BgivenA, double A, double B)
Definition: bayes_theorem.cpp:14