-
Notifications
You must be signed in to change notification settings - Fork 1
/
varying no of slots(NREL data).py
250 lines (189 loc) · 6.71 KB
/
varying no of slots(NREL data).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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 23 13:00:30 2018
Using data from NREL
Vary the no of slots per day and calculating its MAPE
No sharing of parameters, use actual collected data
@author: zckoh
"""
import numpy as np
import matplotlib.pyplot as plt
import itertools
from QLSEP_class import QLSEP_node,MAPE_overall
np.set_printoptions(threshold=np.nan)
def safe_div(x,y):
if y == 0:
return 0
return x / y
"""Import data"""
slot = 30
day_counter = 1
lux_B1 = []
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_B1.append([float(i) for i in tmp])
tmp = []
day_counter += 1
days = len(lux_B1)
print len(lux_B1[20])
"""Different sampling frequency"""
lux_60min = []
lux_90min = []
lux_120min = []
tmp_60 = []
tmp_90 = []
tmp_120 = []
#save for each 2,3,4 times
for x in range(len(lux_B1)):
for i in range(len(lux_B1[x])):
if(i%2==0):
tmp_60.append(lux_B1[x][i])
if(i%3==0):
tmp_90.append(lux_B1[x][i])
if(i%4==0):
tmp_120.append(lux_B1[x][i])
lux_60min.append(tmp_60)
tmp_60 = []
lux_90min.append(tmp_90)
tmp_90 = []
lux_120min.append(tmp_120)
tmp_120 = []
"""calculate EWMA + QLSEP for each total slot"""
index = 84
plot_switch = 1
"""48 slots"""
node48 = QLSEP_node(0.001,0.4,3,slot,days,50)
for x in range(0,days):
for y in range(0,1440/slot):
node48.EWMA(x,y,lux_B1[x-1][y])
node48.Calculate_PER(x,y,lux_B1[x][y-1],(np.amax(lux_B1[x])*0.03))
node48.Q_val_update(x,y)
node48.QLSEP_prediction(x,y)
"""
if(x==index):
print node48.q_values
print node48.QLSEP_val[index]
print node48.EWMA_val[index]
print "DR = "
print node48.QLSEP_val[index]/node48.EWMA_val[index]
"""
"""Find MAPE(EWMA)"""
print "MAPE(%%)\t N (48 slots) %s (EWMA)" % MAPE_overall(lux_B1,node48.EWMA_val,days)
"""Find MAPE(QLSEP)"""
print "MAPE(%%)\t N (48 slots) %s (QLSEP)\n" % MAPE_overall(lux_B1,node48.QLSEP_val,days)
if(plot_switch):
time = np.linspace(1,1440, num = 1440/slot)
plt.figure(1)
fig, ax = plt.subplots(figsize=(7,4))
ax.plot(time,lux_B1[index],'g',label = 'Actual')
ax.plot(time,node48.QLSEP_val[index],'r',label = 'QLSEP')
ax.plot(time,node48.EWMA_val[index],'b',label = 'EWMA')
legend = ax.legend(loc='upper right', shadow=True)
frame = legend.get_frame()
frame.set_facecolor('1.0')
for label in legend.get_texts():
label.set_fontsize('medium')
for label in legend.get_lines():
label.set_linewidth(1.5) # the legend line width
plt.xlabel('Time(Hour)')
plt.ylabel('Light Intensity (klux)')
plt.grid()
plt.title('Day %s (48 slots)' % str(index+1))
"""24 slots"""
node24 = QLSEP_node(0.001,0.4,3,60,days,50)
for x in range(0,days):
for y in range(0,1440/60):
node24.EWMA(x,y,lux_60min[x-1][y])
node24.Calculate_PER(x,y,lux_60min[x][y-1],(np.amax(lux_B1[x])*0.03))
node24.Q_val_update(x,y)
node24.QLSEP_prediction(x,y)
"""Find MAPE(EWMA)"""
print "MAPE(%%)\t N (24 slots) %s (EWMA)" % MAPE_overall(lux_60min,node24.EWMA_val,days)
"""Find MAPE(QLSEP)"""
print "MAPE(%%)\t N (24 slots) %s (QLSEP)\n" % MAPE_overall(lux_60min,node24.QLSEP_val,days)
if(plot_switch):
time = np.linspace(1,1440, num = 1440/60)
plt.figure(1)
fig, ax = plt.subplots(figsize=(7,4))
ax.plot(time,lux_60min[index],'g',label = 'Actual')
ax.plot(time,node24.QLSEP_val[index],'r',label = 'QLSEP')
ax.plot(time,node24.EWMA_val[index],'b',label = 'EWMA')
legend = ax.legend(loc='upper right', shadow=True)
frame = legend.get_frame()
frame.set_facecolor('1.0')
for label in legend.get_texts():
label.set_fontsize('medium')
for label in legend.get_lines():
label.set_linewidth(1.5) # the legend line width
plt.xlabel('Time(Hour)')
plt.ylabel('Light Intensity (klux)')
plt.grid()
plt.title('Day %s (24 slots)' % str(index+1))
"""16 slots"""
node16 = QLSEP_node(0.001,0.4,3,90,days,50)
for x in range(0,days):
for y in range(0,1440/90):
node16.EWMA(x,y,lux_90min[x-1][y])
node16.Calculate_PER(x,y,lux_90min[x][y-1],(np.amax(lux_B1[x])*0.03))
node16.Q_val_update(x,y)
node16.QLSEP_prediction(x,y)
"""Find MAPE(EWMA)"""
print "MAPE(%%)\t N (16 slots) %s (EWMA)" % MAPE_overall(lux_90min,node16.EWMA_val,days)
"""Find MAPE(QLSEP)"""
print "MAPE(%%)\t N (16 slots) %s (QLSEP)\n" % MAPE_overall(lux_90min,node16.QLSEP_val,days)
if(plot_switch):
time = np.linspace(1,1440, num = 1440/90)
plt.figure(1)
fig, ax = plt.subplots(figsize=(7,4))
ax.plot(time,lux_90min[index],'gx',label = 'Actual')
ax.plot(time,node16.QLSEP_val[index],'rx',label = 'QLSEP')
ax.plot(time,node16.EWMA_val[index],'bx',label = 'EWMA')
legend = ax.legend(loc='upper right', shadow=True)
frame = legend.get_frame()
frame.set_facecolor('1.0')
for label in legend.get_texts():
label.set_fontsize('medium')
for label in legend.get_lines():
label.set_linewidth(1.5) # the legend line width
plt.xlabel('Time(Hour)')
plt.ylabel('Light Intensity (klux)')
plt.grid()
plt.title('Day %s (16 slots)' % str(index+1))
"""12 slots"""
node12 = QLSEP_node(0.001,0.4,3,120,days,50)
for x in range(0,days):
for y in range(0,1440/120):
node12.EWMA(x,y,lux_120min[x-1][y])
node12.Calculate_PER(x,y,lux_120min[x][y-1],(np.amax(lux_B1[x])*0.03))
node12.Q_val_update(x,y)
node12.QLSEP_prediction(x,y)
"""Find MAPE(EWMA)"""
print "MAPE(%%)\t N (12 slots) %s (EWMA)" % MAPE_overall(lux_120min,node12.EWMA_val,days)
"""Find MAPE(QLSEP)"""
print "MAPE(%%)\t N (12 slots) %s (QLSEP)\n" % MAPE_overall(lux_120min,node12.QLSEP_val,days)
if(plot_switch):
time = np.linspace(1,1440, num = 1440/120)
plt.figure(1)
fig, ax = plt.subplots(figsize=(7,4))
ax.plot(time,lux_120min[index],'g',label = 'Actual')
ax.plot(time,node12.QLSEP_val[index],'r',label = 'QLSEP')
ax.plot(time,node12.EWMA_val[index],'b',label = 'EWMA')
legend = ax.legend(loc='upper right', shadow=True)
frame = legend.get_frame()
frame.set_facecolor('1.0')
for label in legend.get_texts():
label.set_fontsize('medium')
for label in legend.get_lines():
label.set_linewidth(1.5) # the legend line width
plt.xlabel('Time(Hour)')
plt.ylabel('Light Intensity (klux)')
plt.grid()
plt.title('Day %s (12 slots)' % str(index+1))