mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
document bayes theorem
This commit is contained in:
parent
2f3cb1adaa
commit
589dceb5b3
@ -1,24 +1,28 @@
|
|||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief [Bayes' theorem](https://en.wikipedia.org/wiki/Bayes%27_theorem)
|
||||||
|
*
|
||||||
|
* Bayes' theorem allows one to find \f$P(A|B)\f$ given \f$P(B|A)\f$ or
|
||||||
|
* \f$P(B|A)\f$ given \f$P(A|B)\f$ and \f$P(A)\f$ and \f$P(B)\f$.\n
|
||||||
|
* Note that \f$P(A|B)\f$ is read 'The probability of A given that the event B
|
||||||
|
* has occured'.
|
||||||
|
*/
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// bayes' theorem > https://en.wikipedia.org/wiki/Bayes%27_theorem
|
/** returns P(A|B)
|
||||||
|
*/
|
||||||
// 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) {
|
double bayes_AgivenB(double BgivenA, double A, double B) {
|
||||||
return (BgivenA * A) / B;
|
return (BgivenA * A) / B;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns P(B|A)
|
/** returns P(B|A)
|
||||||
|
*/
|
||||||
double bayes_BgivenA(double AgivenB, double A, double B) {
|
double bayes_BgivenA(double AgivenB, double A, double B) {
|
||||||
return (AgivenB * B) / A;
|
return (AgivenB * B) / A;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Main function
|
||||||
|
*/
|
||||||
int main() {
|
int main() {
|
||||||
double A = 0.01;
|
double A = 0.01;
|
||||||
double B = 0.1;
|
double B = 0.1;
|
||||||
|
Loading…
Reference in New Issue
Block a user