![]() |
TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Conditional Probability More...
#include <cassert>#include <cmath>#include <iostream>#include <stdexcept>#include <string>Go to the source code of this file.
Namespaces | |
| namespace | probability |
| for std::string | |
| namespace | conditional_probability |
| Functions for the Conditional Probability algorithm implementation. | |
Functions | |
| double | probability::conditional_probability::conditional_compute (double p_intersect, double p_given) |
| Computes the conditional probability P(X|Y). | |
| static void | test () |
| Self-test implementations. | |
| int | main () |
| Main function. | |
In probability theory, conditional probability is a measure of the probability of an event occurring, given that another event (by assumption, presumption, assertion, or evidence) is already known to have occurred.
This particular method relies on event A occurring with some sort of relationship with another event B. In this situation, the event A can be analyzed by a conditional probability with respect to B.
If the event of interest is A and the event B is known or assumed to have occurred, "the conditional probability of A given B", or "the probability of A under the condition B" is given by the formula:
\[P(A \mid B) = \frac{P(A \cap B)}{P(B)}\]
where: \(P(B) > 0\).
Definition in file conditional_probability.cpp.
| double probability::conditional_probability::conditional_compute | ( | double | p_intersect, |
| double | p_given ) |
Computes the conditional probability P(X|Y).
| p_intersect | probability that both X and Y occur, in [0, P(Y)] |
| p_given | probability of the event that is given (Y), in (0, 1] |
| std::invalid_argument | if p_given is not in (0, 1], or if p_intersect is not in [0, p_given] |
Definition at line 51 of file conditional_probability.cpp.
| int main | ( | void | ) |
Main function.
Definition at line 159 of file conditional_probability.cpp.
|
static |
Self-test implementations.
tolerance for double comparison
Definition at line 70 of file conditional_probability.cpp.