Last active
December 2, 2022 08:40
-
-
Save maxdevblock/8a4fd2a16dc51c2a6435a1c4da4cdcd2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import numpy as np | |
import scipy.stats as sps | |
import matplotlib.pyplot as plt | |
tau = 5 | |
beta = 1/tau | |
alpha = 5 | |
t = 15 | |
lam = beta*t | |
d = sps.gamma(a=alpha, scale=1/beta) | |
x = np.linspace(0, d.ppf(.999), 1000) | |
y = d.pdf(x) | |
p = d.cdf(t) | |
D = sps.poisson(mu=lam) | |
X = np.arange(0, D.ppf(.999), 1) | |
Y = D.pmf(X) | |
P = 1 - D.cdf(alpha-1) | |
fig, ax = plt.subplots(1, 2, figsize=(12, 5), facecolor="w") | |
ax[0].plot(x, y) | |
ax[0].fill_between( | |
x[x<=15], | |
0, y[x<=15], | |
color="r", alpha=.25 | |
) | |
ax[0].plot([0, 0], [0, y[0]], "r") | |
ax[0].plot([15, 15], [0, y[x<=15][-1]], "r") | |
ax[0].axhline(0, color="k", alpha=.25) | |
ax[0].set_xlabel("Wating time $t$") | |
ax[0].set_ylabel("Probability Density") | |
ax[0].text(16, .005, f"$P(T\leq 15)={p*100:.3f}\;\%$") | |
ax[0].set_title(fr"$T \sim \mathrm{{Gamma}}(\alpha={alpha}, \beta={beta})$") | |
ax[0].set_xticks(np.arange(0, max(x)+5, 5)) | |
ax[1].stem(X, Y) | |
ax[1].bar(X[X>=alpha], Y[X>=alpha], color="r", alpha=.25) | |
ax[1].text(5, .12, f"$P(A \geq {alpha})={P*100:.3f}\;\%$") | |
ax[1].set_title(fr"$A \sim \mathrm{{Poisson}}(\lambda={lam:.0f}$)") | |
ax[1].set_xticks(X) | |
ax[1].set_xlabel(r"Completed processes $\alpha$") | |
ax[1].set_ylabel("Probability Mass") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment