-
Notifications
You must be signed in to change notification settings - Fork 1
/
varying alpha (EWMA).py
75 lines (52 loc) · 1.62 KB
/
varying alpha (EWMA).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
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 18 23:38:58 2018
@author: zckoh
"""
import numpy as np
import matplotlib.pyplot as plt
import itertools
execfile("./QLSEP_class.py")
np.set_printoptions(threshold=np.nan)
#Get the original 48 slots data
slot = 30
day_counter = 1
lux_original = []
slot_true = 1
lux = []
tmp = []
with open("./NREL_data/20160901.csv", 'r') as f:
fifthlines = itertools.islice(f, 0, None, slot)
for lines in fifthlines:
tmp.append(lines.split(',')[2])
if(day_counter == (1440/slot)):
day_counter = 0
tmp = [w.replace('\n', '') for w in tmp]
lux_original.append([float(i) for i in tmp])
tmp = []
day_counter += 1
days = len(lux_original)
EWMA_val = np.array([[float(0)]*(1440/slot)]*days)
"""New model"""
index = 5
alpha_lst = np.linspace(0,1,num=11)
MAPE_lst = []
for k in range(0,len(alpha_lst)):
print alpha_lst[k]
for x in range(0,days):
for y in range(0,1440/slot):
EWMA_val[x][y] = alpha_lst[k]*(EWMA_val[x][y-1]) + (1-alpha_lst[k])*(float(lux_original[x-1][y]))
#now already complete, calculate the MAPE
[mape_EWMA, no_b1_EWMA] = MAPE_overall(lux_original,EWMA_val,days)
MAPE_lst.append(mape_EWMA)
#reset the EWMA_val
EWMA_val = np.array([[float(0)]*(1440/slot)]*days)
print MAPE_lst
plt.figure(1)
fig, ax = plt.subplots(figsize=(7.5,4))
ax.plot(alpha_lst,MAPE_lst,'b')
plt.xlabel(r'$\alpha$')
plt.ylabel('MAPE (%)')
plt.grid()
plt.savefig('alpha_vs_mape.png', dpi = 600)
plt.show()