Skip to content

Commit

Permalink
Distribution Gallery: Add Categorical (#588)
Browse files Browse the repository at this point in the history
* Distribution Gallery: Add Categorical

* Update docs/examples/gallery/categorical.md

---------

Co-authored-by: Osvaldo A Martin <aloctavodia@gmail.com>
  • Loading branch information
aleicazatti and aloctavodia authored Nov 17, 2024
1 parent a1419be commit 3343509
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
90 changes: 90 additions & 0 deletions docs/examples/gallery/categorical.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
jupytext:
text_representation:
extension: .md
format_name: myst
kernelspec:
display_name: Python 3
language: python
name: python3
---
# Categorical Distribution

<audio controls> <source src="../../_static/categorical.mp3" type="audio/mpeg"> This browser cannot play the pronunciation audio file for this distribution. </audio>

The Categorical distribution is the most general discrete distribution and is parameterized by a vector $p$ where each element $p_i$ specifies the probabilities of each possible outcome.

## Probability Density Function (PDF):

```{code-cell}
---
tags: [remove-input]
mystnb:
image:
alt: Categorical Distribution PDF
---
from preliz import Categorical, style
style.use('preliz-doc')
ps = [[0.1, 0.6, 0.3], [0.3, 0.1, 0.1, 0.5]]
for p in ps:
Categorical(p).plot_pdf()
```

## Cumulative Distribution Function (CDF):

```{code-cell}
---
tags: [remove-input]
mystnb:
image:
alt: Categorical Distribution CDF
---
for p in ps:
Categorical(p).plot_cdf()
```

## Key properties and parameters:

```{eval-rst}
======== ===================================
Support :math:`x \in \{0, 1, \ldots, |p|-1\}`
======== ===================================
```

**Probability Mass Function (PMF):**

$$
f(x) = p_x
$$

**Cumulative Distribution Function (CDF):**

$$
F(x \mid p) = \begin{cases}
0 & \text{if } x < 0 \\
\sum_{i=0}^{x} p_i & \text{if } 0 \leq x < |p| \\
1 & \text{if } x \geq |p|
\end{cases}
$$

where $p$ is the array of probabilities for each category.

```{seealso}
:class: seealso
**Related Distributions:**
- [Bernoulli](bernoulli.md) - The Categorical distribution is a generalization of the Bernoulli distribution to more than two outcomes.
- [Discrete Uniform](discrete_uniform.md) - A special case of the Categorical distribution where all outcomes have equal probability.
```

## References

- [Wikipedia - Categorical Distribution](https://en.wikipedia.org/wiki/Categorical_distribution)





2 changes: 1 addition & 1 deletion docs/gallery_content.rst
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ Discrete Distributions
Binomial

.. grid-item-card::
:link: ./api_reference.html#preliz.distributions.categorical.Categorical
:link: ./examples/gallery/categorical.html
:text-align: center
:shadow: none
:class-card: example-gallery
Expand Down

0 comments on commit 3343509

Please sign in to comment.