> ## Documentation Index
> Fetch the complete documentation index at: https://aegean.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Probability Basics

> Fundamental probability concepts for machine learning.

If the contents in this section are new to you, we recommend starting with Stanford's [Probability for Computer Scientists (CS109)](https://probabilitycoders.stanford.edu/spr26).

Note also the Khan Academy [Statistics and Probability](https://www.khanacademy.org/math/statistics-probability) course, especially [Unit 7: Probability](https://www.khanacademy.org/math/statistics-probability/probability-library) and [Unit 9: Random variables](https://www.khanacademy.org/math/statistics-probability/random-variables-stats-library).

1. The whole purpose of probabilistic modeling is to introduce uncertainty into our problem statement. There are three types of uncertainties, which fall into the broader [aleatoric and epistemic](/aiml-common/lectures/aleatoric-epistemic/index) categories:

   * Inherent stochasticity - e.g. impact of wind in self-driving car control systems at moderate to high speed.
   * Incomplete observability - e.g. sensor imperfections causing loss of sensing information
   * Incomplete modeling - e.g. models and algorithms that are not implementable to an analog world and need to be discretized.

2. Probabilities can be used in two ways.

   * Probabilities can describe frequencies of outcomes in random experiments
   * Probabilities can also be used, more generally, to describe degrees of belief in propositions that do not involve random variables. This more general use of probability to quantify beliefs is known as the Bayesian viewpoint. It is also known as the subjective interpretation of probability, since the probabilities depend on assumptions.

The three important probabilities that we need to be concerned with in data mining are the joint, marginal and conditional probabilities. The pictures below present some examples that we will go through.

<img src="https://mintcdn.com/aegeanaiinc/RIwOMIddP1DOHwvm/aiml-common/lectures/ml-math/probability/images/discrete-prob.png?fit=max&auto=format&n=RIwOMIddP1DOHwvm&q=85&s=651733757719a8a086a8474724b8631e" alt="discrete-prob" width="878" height="200" data-path="aiml-common/lectures/ml-math/probability/images/discrete-prob.png" />

*Discrete probability distribution function (pdf). On the right side is what is called a Hinton diagram where the area of the square represents the probability in a way that the sum equals to 1.0.*

<img src="https://mintcdn.com/aegeanaiinc/RIwOMIddP1DOHwvm/aiml-common/lectures/ml-math/probability/images/figure21.png?fit=max&auto=format&n=RIwOMIddP1DOHwvm&q=85&s=411d0f1ee7e0d9edf662d196825502ff" alt="monogram" width="292" height="738" data-path="aiml-common/lectures/ml-math/probability/images/figure21.png" />

*A more complicated discrete probability distribution over the letters of the English alphabet (letter 27 symbolizes space) as measured by reading the Linux FAQ document.*

<img src="https://mintcdn.com/aegeanaiinc/RIwOMIddP1DOHwvm/aiml-common/lectures/ml-math/probability/images/continuous-prob.png?fit=max&auto=format&n=RIwOMIddP1DOHwvm&q=85&s=739de61ee4fea76423ea38e6d573e1a7" alt="continuous-prob" width="665" height="334" data-path="aiml-common/lectures/ml-math/probability/images/continuous-prob.png" />

*Continuous probability distribution density function (pdf) - the area under the curve equals  1.0*

<img src="https://mintcdn.com/aegeanaiinc/RIwOMIddP1DOHwvm/aiml-common/lectures/ml-math/probability/images/figure2.2.png?fit=max&auto=format&n=RIwOMIddP1DOHwvm&q=85&s=27defe405a0d4d07870e9fb16fbf2b24" alt="joint-bigram" width="412" height="386" data-path="aiml-common/lectures/ml-math/probability/images/figure2.2.png" />

*Joint probability $P(x,y)$ distribution over the 27x27 possible bigrams $xy$ found in the Linux FAQ document.*

<img src="https://mintcdn.com/aegeanaiinc/RIwOMIddP1DOHwvm/aiml-common/lectures/ml-math/probability/images/joint-prob.png?fit=max&auto=format&n=RIwOMIddP1DOHwvm&q=85&s=a88bf851028dc48cdc9b1b8695404740" alt="joint-prob" width="930" height="607" data-path="aiml-common/lectures/ml-math/probability/images/joint-prob.png" />

*(e) and (f) represent joint distributions of discrete and continuous random variables*

## Sum and Product rules

The following video explains the sum and product rules that are extensivbely used in data science and for understanding the Bayes rule.

<iframe width="560" height="315" src="https://www.youtube.com/embed/bwjOOzFSo9c" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen />

### Sum rule and the Marginal Probability

Given the joint what is the marginal probability $P(x)$ ?

$P(x)   = \sum_y P(x,y) = \sum_y P(x | y)P(y)$

<img src="https://mintcdn.com/aegeanaiinc/RIwOMIddP1DOHwvm/aiml-common/lectures/ml-math/probability/images/marginal-prob.png?fit=max&auto=format&n=RIwOMIddP1DOHwvm&q=85&s=20d964042b5d454aee635e212d2735b4" alt="marginal-prob" width="1163" height="361" data-path="aiml-common/lectures/ml-math/probability/images/marginal-prob.png" />

*Extracting the marginal out of the joint*

### Conditional Probability and the Product or chain rule

This is obtained from the definition of conditional probability:

$P(x,y) = P(x | y)P(y) = P(y | x)P(x)$

<img src="https://mintcdn.com/aegeanaiinc/RIwOMIddP1DOHwvm/aiml-common/lectures/ml-math/probability/images/conditional-bigrams.png?fit=max&auto=format&n=RIwOMIddP1DOHwvm&q=85&s=f4404e3dc7d10d705a95c1fb0faf04fe" alt="conditional-bigram" width="672" height="271" data-path="aiml-common/lectures/ml-math/probability/images/conditional-bigrams.png" />

*Conditional probability distribution over the 27x27 possible bigrams $xy$ found in the Linux FAQ document.*

<Note title="Question">
  Are $x$ and $y$ in the example above independent?
</Note>

**Key references**: (Kendall & Gal, 2017; Kendall & Gal, 2017; Frazier, 2018)

## References

* Frazier, P. (2018). *A Tutorial on Bayesian Optimization*.
* Kendall, A., Gal, Y. (2017). *What uncertainties do we need in Bayesian deep learning for computer vision?*.
* Kendall, A., Gal, Y. (2017). *What Uncertainties Do We Need in Bayesian Deep Learning for Computer Vision?*.

***

<Callout icon="pen-to-square" iconType="regular">
  [Edit this page on GitHub](https://github.com/aegean-ai/eaia/edit/main/src/aiml-common/lectures/ml-math/probability/index.mdx) or [file an issue](https://github.com/aegean-ai/eaia/issues/new/choose).
</Callout>
