### Uniform Distribution
#### Continous
Consider,
$$\mathbb{U}[N_{bin},r'_{min},r'_{max},r_{min},r_{max}] = \frac{r'_{max}-r'_{min}}{N_{bin}(r_{max}-r_{min})} $$
Since in Matlab rand, the uniform distribution is defined in the range of $[0,1]$,
$$r\sim \mathbb{U}[0,1]$$
To extend the range $r\in [0,1]$ to $r'\in [a,b]$,
$$r' = r(b-a)+a$$

#### Discrete
\begin{equation}
p(x)=\left\{
  \begin{array}{@{}ll@{}}
    0.25, & \text{if}\ x\in\{1,2,3,4\} \\
    0, & \text{otherwise}
  \end{array}\right.
\end{equation}


```python
import numpy as np
import matplotlib.pyplot as plt
```


```python
s = np.random.uniform(1,5,10000)
count, bins, ignored = plt.hist(s, 100, density=True, align='left',rwidth=0.5)
plt.plot(bins, 0.25*np.ones_like(bins), linewidth=2, color='r')
```


```python
s = np.random.randint(1,5,100000)
plt.hist(s,   density=True, align='mid', rwidth=0.5)
```

### Degenerate Distribution
\begin{equation}
p(x)=\left\{
  \begin{array}{@{}ll@{}}
    1, & \text{if}\ x=1 \\
    0, & \text{if}\ x\in\{2,3,4\}
  \end{array}\right.
\end{equation}


```python
s = np.random.uniform(0,1,1000)
s = np.concatenate((s,np.zeros(5000)))
count, bins, ignored = plt.hist(s, 1, density=True, align='right')
plt.plot(range(0,6), np.ones(6), linewidth=2, color='r')
```


```python

```

4584656e06d6490e095185bad4687ed38ae31ab4
ipynb
Jupyter Notebook
Machine Learning A Probabilistic Perspective/2Probability/.ipynb_checkpoints/2.1discreteProbDistFig-checkpoint.ipynb
zcemycl/ProbabilisticPerspectiveMachineLearning
8291bc6cb935c5b5f9a88f7b436e6e42716c21ae
MIT
2019-11-20T10:20:29.000Z
2021-11-09T11:15:23.000Z
Machine Learning A Probabilistic Perspective/2Probability/.ipynb_checkpoints/2.1discreteProbDistFig-checkpoint.ipynb
zcemycl/ProbabilisticPerspectiveMachineLearning
8291bc6cb935c5b5f9a88f7b436e6e42716c21ae
MIT
Machine Learning A Probabilistic Perspective/2Probability/.ipynb_checkpoints/2.1discreteProbDistFig-checkpoint.ipynb
zcemycl/ProbabilisticPerspectiveMachineLearning
8291bc6cb935c5b5f9a88f7b436e6e42716c21ae
MIT
2020-05-27T03:56:38.000Z
2021-05-02T13:15:42.000Z
Qwen/Qwen-72B
1. YES
2. YES