forked from arviz-devs/preliz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Distributions Gallery: Add Triangular (arviz-devs#571)
- Loading branch information
1 parent
d17ee9f
commit fef16e3
Showing
2 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
--- | ||
jupytext: | ||
text_representation: | ||
extension: .md | ||
format_name: myst | ||
kernelspec: | ||
display_name: Python 3 | ||
language: python | ||
name: python3 | ||
--- | ||
# Triangular Distribution | ||
|
||
<audio controls> <source src="../../_static/triangular.mp3" type="audio/mpeg"> This browser cannot play the pronunciation audio file for this distribution. </audio> | ||
|
||
The Triangular distribution is a continuous probability distribution with a triangular shape. It is defined by three parameters: the lower bound $lower$, the mode $c$, and the upper bound $upper$. Where $lower \leq c \leq upper$. | ||
|
||
The Triangular distribution is often called a "lack of knowledge" distribution because it can be used when there is no prior knowledge about the distribution of the random variable other than the minimum, maximum, and most likely values. It is often used in business simulations and decision-making, project management, and audio dithering. | ||
|
||
## Probability Density Function (PDF): | ||
|
||
```{code-cell} | ||
--- | ||
tags: [remove-input] | ||
mystnb: | ||
image: | ||
alt: Triangular Distribution PDF | ||
--- | ||
from preliz import Triangular, style | ||
style.use('preliz-doc') | ||
lowers = [0., -1, 2] | ||
cs = [2., 0., 6.5] | ||
uppers = [4., 1, 8] | ||
for lower, c, upper in zip(lowers, cs, uppers): | ||
scale = upper - lower | ||
c_ = (c - lower) / scale | ||
Triangular(lower, c, upper).plot_pdf() | ||
``` | ||
|
||
## Cumulative Distribution Function (CDF): | ||
|
||
```{code-cell} | ||
--- | ||
tags: [remove-input] | ||
mystnb: | ||
image: | ||
alt: Triangular Distribution CDF | ||
--- | ||
for lower, c, upper in zip(lowers, cs, uppers): | ||
scale = upper - lower | ||
c_ = (c - lower) / scale | ||
Triangular(lower, c, upper).plot_cdf() | ||
``` | ||
|
||
## Key properties and parameters: | ||
|
||
```{eval-rst} | ||
======== ========================================== | ||
Support :math:`x \in [lower, upper]` | ||
Mean :math:`\dfrac{lower + upper + c}{3}` | ||
Variance :math:`\dfrac{upper^2 + lower^2 +c^2 - lower*upper - lower*c - upper*c}{18}` | ||
======== ========================================== | ||
``` | ||
|
||
**Probability Density Function (PDF):** | ||
|
||
$$ | ||
f(x|lower, c, upper) = | ||
\begin{cases} | ||
0 & \text{for } x < lower \\ | ||
\frac{2(x - lower)}{(upper - lower)(c - lower)} & \text{for } lower \leq x < c \\ | ||
\frac{2}{upper - lower} & \text{for } x = c \\ | ||
\frac{2(upper - x)}{(upper - lower)(upper - c)} & \text{for } c < x \leq upper \\ | ||
\end{cases} | ||
$$ | ||
|
||
**Cumulative Distribution Function (CDF):** | ||
|
||
$$ | ||
F(x|lower, c, upper) = | ||
\begin{cases} | ||
0 & \text{for } x < lower \\ | ||
\frac{(x - lower)^2}{(upper - lower)(c - lower)} & \text{for } lower \leq x < c \\ | ||
1 - \frac{(upper - x)^2}{(upper - lower)(upper - c)} & \text{for } c \leq x \leq upper \\ | ||
1 & \text{for } x \geq upper | ||
\end{cases} | ||
$$ | ||
|
||
```{seealso} | ||
:class: seealso | ||
**Related Distributions:** | ||
- [Uniform Distribution](uniform.md) - A distribution with constant probability that is also used when there is limited prior knowledge about the distribution of the random variable: in this case, only the $lower$ and $upper$ bounds are known. | ||
``` | ||
|
||
## References | ||
|
||
- Wikipedia. [Triangular distribution](https://en.wikipedia.org/wiki/Triangular_distribution). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters