Exponential Distributions

Exponential distributions

from matplotlib import pyplot as plt

from symbulate import *
W = RV(Exponential(rate = 1 / 30))

w = W.sim(10000)

w
Index Result
019.31839707102859
138.907071499553666
221.927303602168685
315.075911145136045
414.569965399393402
568.87110665884259
622.488723125132488
72.264654223306332
826.614583774147018
......
999933.17331598333397
plt.figure();

w.plot()

Exponential(rate = 1 / 30).plot()

plt.show();

w.count_gt(45) / 10000, 1 - Exponential(rate = 1 / 30).cdf(45)
(0.2227, 0.2231301601484298)

Scaling

U = RV(Exponential(rate = 1))

W = U / (1 / 30)

plt.figure(); 

W.sim(10000).plot()

Exponential(rate = 1 / 30).plot()

plt.show();

U = RV(Exponential(rate = 1))

V = U / 2

plt.figure(); 

V.sim(10000).plot()

Exponential(rate = 2).plot()

plt.show();

Memoryless property

plt.figure();

W.sim(10000).plot()

(W - 120 | (W > 120) ).sim(10000).plot()

plt.show();

Exponential race

X, Y = RV(Exponential(rate = 1 / 10) * Exponential(rate = 1 / 20))

W = (X & Y).apply(min)
xyw = (X & Y & W).sim(10000)
xyw
Index Result
0(4.983024727303675, 1.8686496510707014, 1.8686496510707014)
1(3.532554503008326, 9.05367112944098, 3.532554503008326)
2(24.918965681064886, 13.345421877996436, 13.345421877996436)
3(1.0775484149017658, 42.42848811731041, 1.0775484149017658)
4(8.548471948094639, 7.969724384024137, 7.969724384024137)
5(2.799644404617912, 44.18113902851118, 2.799644404617912)
6(13.52302122544879, 5.549623631722809, 5.549623631722809)
7(2.222538632722782, 7.602869821226346, 2.222538632722782)
8(3.3007495617180953, 8.126766296265734, 3.3007495617180953)
......
9999(23.287665393006094, 0.410007076623495, 0.410007076623495)
xyw.mean()
(9.853554692021284, 20.148862821285917, 6.602680210076662)
plt.figure();

W.sim(10000).plot()

Exponential(rate = 1 / 10 + 1 / 20).plot()

plt.show();

(Y > X).sim(10000).tabulate(normalize = True)
Outcome Relative Frequency
False0.339
True0.661
Total1.0
plt.figure();

(W | (Y > X) ).sim(10000).plot()

(W | (Y < X) ).sim(10000).plot()

Exponential(rate = 1 / 10 + 1 / 20).plot()

plt.show();

Gamma distributions

W1, W2, W3 = RV(Exponential(rate = 2) ** 3)

T = W1 + W2 + W3
sim = (W1 & W2 & W3 & T).sim(10000)

sim
Index Result
0(0.4052504524799489, 0.5114739087659492, 0.2816990600116868, 1.198423421257585)
1(0.2845006034749414, 0.784147170615129, 0.06580140653945067, 1.1344491806295212)
2(0.29037566745592863, 0.40689436589149, 1.2309530778525988, 1.9282231112000174)
3(0.3761683472390624, 0.3912870039018704, 1.7872597578528382, 2.554715108993771)
4(0.601298208076717, 0.14219483464185464, 0.503822210308268, 1.2473152530268397)
5(1.3643831264151047, 0.6027998436707337, 0.005046870394153958, 1.9722298404799925)
6(2.131537555459863, 0.8582450938251214, 0.01889120059840637, 3.0086738498833903)
7(0.004463730964075298, 0.12675742084063174, 0.2831797269746502, 0.4144008787793573)
8(0.7406988438093932, 0.17534287199045778, 0.025007696913787885, 0.941049412713639)
......
9999(0.4468714918036265, 1.2508675378247072, 0.4194708243947566, 2.1172098540230904)
sim.mean()
(0.4994192595452543, 0.5008799046109623, 0.5030317990526548, 1.5033309632088712)
sim.var()
(0.2519628669400152, 0.25448442216859424, 0.25792731168795424, 0.7653816655218177)
sim.sd()
(0.5019590291448249, 0.5044644904932301, 0.5078654464402498, 0.8748609406767557)
plt.figure();

T.sim(10000).plot()

Gamma(shape = 3, rate = 2).plot()

plt.show();