-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualization.py
79 lines (60 loc) · 2.44 KB
/
visualization.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
Annual Monthly(and Seasonal) Temperature of India from 1901 - 2017 Dataset.
"""
import pandas
import matplotlib.pyplot as plt
import numpy as np
bias_correction = False
standard_normalization = True
genearal_normalization = not standard_normalization
beta1 = 0.9
beta2 = 0.999
"""
Intuitions:
--> The First Exponentially Weighted Moving Average is Sensitive towards the change in direction of the plot,
which is a little smoothened due to the Weighted average more focusing on the historical values of the Original plot,
which in terms retains the overall "momentum" of the plot.
--> Whereas the Second EWMA is particularly sensitive towards the Overall direction of the Original plot,
while smothening and averaging out all the nearby change in directions.
--> The Adam Curve is Sensitive Towards all the big changes in the directions of the original plot
as well as the curve moves along the overall direction of the Original plot.
P.S while using the bias correction the graphs explodes in certain regions.
"""
data = pandas.read_excel("datafile.xls")
data = data[["YEAR", "ANNUAL"]]
# General Normalization.
if genearal_normalization:
norm = "General"
data["ANNUAL"] = np.divide(data["ANNUAL"], np.max(data["ANNUAL"]))
# Standard - Score Normalization of the temperature values.
if standard_normalization:
norm = "S-Score"
s = np.std(data["ANNUAL"])
data["ANNUAL"] -= np.mean(data["ANNUAL"])
data["ANNUAL"] = data["ANNUAL"] / s
stemp = 0
Momentum = np.zeros((data["YEAR"].shape[0],))
vtemp = 0
Rms = np.zeros((data["YEAR"].shape[0],))
for i in range(1, data["ANNUAL"].shape[0] + 1):
vtemp = beta1 * (vtemp) + (1 - beta1) * data["ANNUAL"][i - 1]
stemp = beta2 * (stemp) + (1 - beta2) * data["ANNUAL"][i - 1]**2
# bias Correction.
if bias_correction:
vtemp /= (1 - beta1**i)
stemp = stemp / (1 - beta2**i)
Momentum[i - 1] = vtemp
Rms[i - 1] = stemp
Adam = np.divide(Momentum, (np.sqrt(np.abs(Rms)) + 10**-10))
plt.plot(data["YEAR"], data["ANNUAL"], color="blue",
label=f"{norm} Normalized Temprature")
plt.plot(data["YEAR"], Momentum, color="red",
label=f"EWMA (Momentum), beta1 : {beta1}")
plt.plot(data["YEAR"], Rms, color="yellow",
label=f"RMS EWMA (RMSProp), beta2 : {beta2}")
plt.plot(data["YEAR"], Adam, color="green",
label=f"Adam Curve, Bias Correction: {bias_correction}")
plt.legend()
plt.ylabel("Temprature")
plt.xlabel("Year")
plt.show()