- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Bayes Theorem for Conditional Probability in C/C++
Conditional probability denoted by P(A|B) is the probability of occurrence of an event ‘A’ given that event ‘B’ has already occurred.
Formula for conditional probability −
P(A|B) = P( A⋂B ) / P(B)
Bayes’s Theorem
It is the formula that shows the relation between probabilities of occurrences of mutually dependent events i.e. it given the relation between their conditional probabilities.
Given an event A and another event B, according to bayes’ theorem,
P(A/B) = {P(B/A) * P(A)} / P(B)
Lets derive the formula for Bayes’ theorem,
For this we will use the formula for conditional probability,
P(A|B) = P( A?B ) / P(B) —— 1 P(B|A) = P( B?A ) / P(A) —— 2
We know that A⋂B and B⋂A are the same, hence we can substitute the value of B⋂A with A⋂B equation 2.
P(B/A) = P(A⋂B) / P(A) P(B/A) * P(A) = P(A⋂B) —- 3
Now, using this value for A?B in equation 1, we will get the bayes’ theorem formula.
P(A/B) = {P(B/A) * P(A)} / P(B)
Some derivations for the Bayes’ Theorem,
Product Rule
depicted in equation 3, it says that the probability of both the events to occur in the same trials is equal to the product of conditional probability of the event and the probability of occurrence of evidence event.
P(A?B) = P(A/B) * P(B)
From this rule we can derive two important formulas −
If A⊆B i.e. A is the subset of B which means all the elements of set A are in set B, then
P(A⋂B) = P(A), then P(A/B) = P(A) / P(B)
If B⊆A i.e. B is the subset of A which means all the elements of set B are in set A, then
P(A⋂B) = P(B), then P(A/B) = 1
Bayes’ Theorem form more than three events −
If we have more that three mutually dependent events, their conditional probability will have the following relation,
P(X1/Y) = (P(X1)*P(Y/X1) / [P(X1 * P(Y/X1)) + P(X2 * P(Y/X2)) + P(X3 * P(Y/X3)) + …]
- Related Articles
- C# Numeric Promotion for Conditional Expression
- C++ Program for Zeckendorf's Theorem?
- Midy’s theorem in C++
- Conditional ternary operator ( ?: ) in C++
- What are conditional attributes in C#?
- Lagrange’s four square theorem in C++
- What is conditional compilation in C language?
- An application on Bertrandís ballot theorem in C/C++
- How do I use the conditional operator in C/C++?
- Bayes’ Rule in Data Structure
- Extended Midy's theorem in C++
- Fermat's Last Theorem in C++
- Fermat's little theorem in C++
- How to use the ?: conditional operator in C#?
- C++ Program to Implement Euler Theorem
