8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4131963 commit f6dd3bfCopy full SHA for f6dd3bf
probability/addition_rule.cpp
@@ -0,0 +1,28 @@
1
+#include <iostream>
2
+
3
+// calculates the probability of the events A or B for independent events
4
5
+double addition_rule_independent(double A, double B) {
6
+ return (A + B) - (A * B);
7
+}
8
9
+// calculates the probability of the events A or B for dependent events
10
+// note that if value of B_given_A is unknown, use chainrule to find it
11
12
+double addition_rule_dependent(double A, double B, double B_given_A) {
13
+ return (A + B) - (A * B_given_A);
14
15
16
+int main() {
17
+ double A = 0.5;
18
+ double B = 0.25;
19
+ double B_given_A = 0.05;
20
21
+ std::cout << "independent P(A or B) = "
22
+ << addition_rule_independent(A, B) << std::endl;
23
24
+ std::cout << "dependent P(A or B) = "
25
+ << addition_rule_dependent(A, B, B_given_A) << std::endl;
26
27
+ return 0;
28
0 commit comments