BoxCox transformation; Particionamento de Huarng, implementação inicial

This commit is contained in:
Petrônio Cândido de Lima e Silva 2016-12-23 08:18:33 -02:00
parent 632b218f62
commit e00ebc93fb
3 changed files with 50 additions and 11 deletions

View File

@ -9,12 +9,6 @@ import Measures
from pyFTS.partitioners import Grid from pyFTS.partitioners import Grid
from pyFTS.common import Membership,FuzzySet,FLR,Transformations from pyFTS.common import Membership,FuzzySet,FLR,Transformations
def Teste(par):
x = np.arange(1,par)
y = [ yy**yy for yyy in x]
plt.plot(x,y)
def getIntervalStatistics(original,models): def getIntervalStatistics(original,models):
ret = "Model & RMSE & MAPE & Sharpness & Resolution & Coverage \\ \n" ret = "Model & RMSE & MAPE & Sharpness & Resolution & Coverage \\ \n"
for fts in models: for fts in models:
@ -126,8 +120,8 @@ 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")
for c in range(0,len(forecasted)): for c in range(0,len(forecasts)):
ax.plot(forecasted[c],label=labels[c]) ax.plot(forecasts[c],label=labels[c])
handles0, labels0 = ax.get_legend_handles_labels() handles0, labels0 = ax.get_legend_handles_labels()
ax.legend(handles0,labels0) ax.legend(handles0,labels0)
ax.set_title(title) ax.set_title(title)

View File

@ -1,8 +1,19 @@
import numpy as np import numpy as np
import math
from pyFTS import * from pyFTS import *
def differential(original): def differential(original):
n = len(original) n = len(original)
diff = [ original[t-1]-original[t] for t in np.arange(1,n) ] diff = [original[t - 1] - original[t] for t in np.arange(1, n)]
diff.insert(0,0) diff.insert(0, 0)
return np.array(diff) return np.array(diff)
def boxcox(original, plambda):
n = len(original)
if plambda != 0:
modified = [(original[t] ** plambda - 1) / plambda for t in np.arange(0, n)]
else:
modified = [math.log(original[t]) for t in np.arange(0, n)]
return np.array(modified)

34
partitioners/Huarng.py Normal file
View File

@ -0,0 +1,34 @@
import numpy as np
import math
import random as rnd
import functools,operator
from pyFTS.common import FuzzySet,Membership,Transformations
#print(common.__dict__)
def GridPartitionerTrimf(data,npart,names = None,prefix = "A"):
data2 = Transformations.differential(data)
davg = np.mean(data2)/2
if davg <= 1.0:
base = 0.1
elif davg > 1 and davg <= 10:
base = 1.0
elif davg > 10 and davg <= 100:
base = 10
else:
base = 100
sets = []
dmax = max(data)
dmax = dmax + dmax*0.10
dmin = min(data)
dmin = dmin - dmin*0.10
dlen = dmax - dmin
partlen = math.ceil(dlen / npart)
partition = math.ceil(dmin)
for c in range(npart):
sets.append(FuzzySet(prefix+str(c),Membership.trimf,[round(partition-partlen,3), partition, partition+partlen], partition ) )
partition = partition + partlen
return sets