PIFTS forecast n steps ahead
This commit is contained in:
parent
3f757fb977
commit
e336a0670e
@ -46,7 +46,7 @@ def coverage(targets,forecasts):
|
|||||||
if targets[i] >= forecasts[i][0] and targets[i] <= forecasts[i][1] :
|
if targets[i] >= forecasts[i][0] and targets[i] <= forecasts[i][1] :
|
||||||
preds.append(1)
|
preds.append(1)
|
||||||
else:
|
else:
|
||||||
preds.append(1)
|
preds.append(0)
|
||||||
return np.mean(preds)
|
return np.mean(preds)
|
||||||
|
|
||||||
def getIntervalStatistics(original,models):
|
def getIntervalStatistics(original,models):
|
||||||
@ -54,11 +54,11 @@ def getIntervalStatistics(original,models):
|
|||||||
for fts in models:
|
for fts in models:
|
||||||
forecasts = fts.forecast(original)
|
forecasts = fts.forecast(original)
|
||||||
ret = ret + fts.shortname + " & "
|
ret = ret + fts.shortname + " & "
|
||||||
ret = ret + str( round(rmse_interval(original[fts.order :],forecasts),2)) + " & "
|
ret = ret + str( round(rmse_interval(original[fts.order-1 :],forecasts),2)) + " & "
|
||||||
ret = ret + str( round(mape_interval(original[fts.order :],forecasts),2)) + " & "
|
ret = ret + str( round(mape_interval(original[fts.order-1 :],forecasts),2)) + " & "
|
||||||
ret = ret + str( round(sharpness(forecasts),2)) + " & "
|
ret = ret + str( round(sharpness(forecasts),2)) + " & "
|
||||||
ret = ret + str( round(resolution(forecasts),2)) + " & "
|
ret = ret + str( round(resolution(forecasts),2)) + " & "
|
||||||
ret = ret + str( round(coverage(original[fts.order :],forecasts),2)) + " \\ \n"
|
ret = ret + str( round(coverage(original[fts.order-1 :],forecasts),2)) + " \\ \n"
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def plotComparedSeries(original,models, colors):
|
def plotComparedSeries(original,models, colors):
|
||||||
@ -99,7 +99,46 @@ def plotComparedSeries(original,models, colors):
|
|||||||
ax.set_xlim([0,len(original)])
|
ax.set_xlim([0,len(original)])
|
||||||
|
|
||||||
|
|
||||||
def plotCompared(original,forecasted,labels,title):
|
def plotComparedIntervalsAhead(original,models, colors, time_from, time_to):
|
||||||
|
fig = plt.figure(figsize=[25,10])
|
||||||
|
ax = fig.add_subplot(111)
|
||||||
|
|
||||||
|
mi = []
|
||||||
|
ma = []
|
||||||
|
|
||||||
|
ax.plot(original,color='black',label="Original")
|
||||||
|
count = 0
|
||||||
|
for fts in models:
|
||||||
|
if fts.isInterval:
|
||||||
|
forecasted = fts.forecastAhead(original[:time_from],time_to)
|
||||||
|
lower = [kk[0] for kk in forecasted]
|
||||||
|
upper = [kk[1] for kk in forecasted]
|
||||||
|
mi.append(min(lower))
|
||||||
|
ma.append(max(upper))
|
||||||
|
for k in np.arange(0,time_from):
|
||||||
|
lower.insert(0,None)
|
||||||
|
upper.insert(0,None)
|
||||||
|
ax.plot(lower,color=colors[count],label=fts.shortname)
|
||||||
|
ax.plot(upper,color=colors[count])
|
||||||
|
|
||||||
|
else:
|
||||||
|
forecasted = fts.forecast(original)
|
||||||
|
mi.append(min(forecasted))
|
||||||
|
ma.append(max(forecasted))
|
||||||
|
forecasted.insert(0,None)
|
||||||
|
ax.plot(forecasted,color=colors[count],label=fts.shortname)
|
||||||
|
|
||||||
|
handles0, labels0 = ax.get_legend_handles_labels()
|
||||||
|
ax.legend(handles0,labels0)
|
||||||
|
count = count + 1
|
||||||
|
#ax.set_title(fts.name)
|
||||||
|
ax.set_ylim([min(mi),max(ma)])
|
||||||
|
ax.set_ylabel('F(T)')
|
||||||
|
ax.set_xlabel('T')
|
||||||
|
ax.set_xlim([0,len(original)])
|
||||||
|
|
||||||
|
|
||||||
|
def plotCompared(original,forecasts,labels,title):
|
||||||
fig = plt.figure(figsize=[13,6])
|
fig = plt.figure(figsize=[13,6])
|
||||||
ax = fig.add_subplot(111)
|
ax = fig.add_subplot(111)
|
||||||
ax.plot(original,color='k',label="Original")
|
ax.plot(original,color='k',label="Original")
|
||||||
|
14
pifts.py
14
pifts.py
@ -83,7 +83,7 @@ class ProbabilisticIntervalFTS(ifts.IntervalFTS):
|
|||||||
|
|
||||||
ret = []
|
ret = []
|
||||||
|
|
||||||
for k in np.arange(self.order,l):
|
for k in np.arange(self.order-1,l):
|
||||||
|
|
||||||
affected_flrgs = []
|
affected_flrgs = []
|
||||||
affected_flrgs_memberships = []
|
affected_flrgs_memberships = []
|
||||||
@ -96,8 +96,7 @@ class ProbabilisticIntervalFTS(ifts.IntervalFTS):
|
|||||||
count = 0
|
count = 0
|
||||||
lags = {}
|
lags = {}
|
||||||
if self.order > 1:
|
if self.order > 1:
|
||||||
subset = ndata[k-self.order : k ]
|
subset = ndata[k-(self.order-1) : k+1 ]
|
||||||
|
|
||||||
for instance in subset:
|
for instance in subset:
|
||||||
mb = common.fuzzyInstance(instance, self.sets)
|
mb = common.fuzzyInstance(instance, self.sets)
|
||||||
tmp = np.argwhere( mb )
|
tmp = np.argwhere( mb )
|
||||||
@ -149,6 +148,15 @@ class ProbabilisticIntervalFTS(ifts.IntervalFTS):
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def forecastAhead(self,data,steps):
|
||||||
|
ret = [[data[k],data[k]] for k in np.arange(len(data)-self.order,len(data))]
|
||||||
|
for k in np.arange(self.order,steps):
|
||||||
|
lower = self.forecast( [ret[x][0] for x in np.arange(k-self.order,k)] )
|
||||||
|
upper = self.forecast( [ret[x][1] for x in np.arange(k-self.order,k)] )
|
||||||
|
ret.append([np.min(lower),np.max(upper)])
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
tmp = self.name + ":\n"
|
tmp = self.name + ":\n"
|
||||||
for r in sorted(self.flrgs):
|
for r in sorted(self.flrgs):
|
||||||
|
Loading…
Reference in New Issue
Block a user