From 2f3cb1adaa9a88d679736d49a5a6d35d03f7057b Mon Sep 17 00:00:00 2001 From: Krishna Vedala Date: Thu, 28 May 2020 16:34:29 -0400 Subject: [PATCH] document probability addition rule --- probability/addition_rule.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/probability/addition_rule.cpp b/probability/addition_rule.cpp index f19955071..780951489 100644 --- a/probability/addition_rule.cpp +++ b/probability/addition_rule.cpp @@ -1,28 +1,42 @@ +/** + * @file + * @brief Addition rule of probabilities + */ #include -// calculates the probability of the events A or B for independent events - +/** + * calculates the probability of the independent events A or B for independent + * events + * \parama [in] A probability of event A + * \parama [in] B probability of event B + * \returns probability of A and B + */ double addition_rule_independent(double A, double B) { return (A + B) - (A * B); } -// calculates the probability of the events A or B for dependent events -// note that if value of B_given_A is unknown, use chainrule to find it - +/** Calculates the probability of the events A or B for dependent events + * note that if value of B_given_A is unknown, use chainrule to find it + * \parama [in] A probability of event A + * \parama [in] B probability of event B + * \parama [in] B_given_A probability of event B condition A + * \returns probability of A and B + */ double addition_rule_dependent(double A, double B, double B_given_A) { return (A + B) - (A * B_given_A); } +/** Main function */ int main() { double A = 0.5; double B = 0.25; double B_given_A = 0.05; - std::cout << "independent P(A or B) = " - << addition_rule_independent(A, B) << std::endl; + std::cout << "independent P(A or B) = " << addition_rule_independent(A, B) + << std::endl; std::cout << "dependent P(A or B) = " - << addition_rule_dependent(A, B, B_given_A) << std::endl; + << addition_rule_dependent(A, B, B_given_A) << std::endl; return 0; }