-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdist_cartoon.py
56 lines (40 loc) · 1.1 KB
/
dist_cartoon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import bound_utils as bu
# set font size and LaTex params
plt.rcParams.update({
'font.size': 20,
'text.usetex': True,
'text.latex.preamble': r'\usepackage{amsfonts}'
})
# set figure size ratio
plt.figure(figsize=(10,6))
# sample GMM distribution
comp_1 = np.random.normal(6, 1, 1000)
comp_2 = np.random.normal(15, 4, 1000)
data = np.hstack((comp_1, comp_2))
tau = 0.7
E = np.mean(data)
VaR = np.quantile(data, tau)
CVaR = bu.MC_CVAR(data, tau)
print("# Samples= ", data.shape[0])
print("E[Y] = ", E)
print("VaR[Y] = ", VaR)
print("CVaR[Y] = ", CVaR)
# plot density
ax = sns.kdeplot(data, fill=True, linewidth=0)
# plot E[Y]
plt.axvline(E)
plt.text(E+0.1,0.1132,r'$\mathbb{E}[Y]$',rotation=-90)
# plot VaR[Y]
plt.axvline(VaR)
plt.text(VaR+0.1,0.1051,r'$\textup{VaR}_{\tau}(Y)$',rotation=-90)
# plot CVaR[Y]
plt.axvline(CVaR)
plt.text(CVaR+0.1,0.10,r'$\textup{CVaR}_{\tau}(Y)$',rotation=-90)
# plt.axhline(0.129)
ax.set(xlabel="$Y$")
image_name = 'experiments/figures/distribution_cartoon.svg'
plt.savefig(image_name)
plt.show()