diff --git a/benchmarks/benchmarks.py b/benchmarks/benchmarks.py index a37c80a..562750c 100644 --- a/benchmarks/benchmarks.py +++ b/benchmarks/benchmarks.py @@ -9,12 +9,6 @@ import Measures from pyFTS.partitioners import Grid 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): ret = "Model & RMSE & MAPE & Sharpness & Resolution & Coverage \\ \n" for fts in models: @@ -126,8 +120,8 @@ def plotCompared(original,forecasts,labels,title): fig = plt.figure(figsize=[13,6]) ax = fig.add_subplot(111) ax.plot(original,color='k',label="Original") - for c in range(0,len(forecasted)): - ax.plot(forecasted[c],label=labels[c]) + for c in range(0,len(forecasts)): + ax.plot(forecasts[c],label=labels[c]) handles0, labels0 = ax.get_legend_handles_labels() ax.legend(handles0,labels0) ax.set_title(title) diff --git a/common/Transformations.py b/common/Transformations.py index 26447a4..5c2865d 100644 --- a/common/Transformations.py +++ b/common/Transformations.py @@ -1,8 +1,19 @@ import numpy as np +import math from pyFTS import * + def differential(original): n = len(original) - diff = [ original[t-1]-original[t] for t in np.arange(1,n) ] - diff.insert(0,0) - return np.array(diff) \ No newline at end of file + diff = [original[t - 1] - original[t] for t in np.arange(1, n)] + diff.insert(0, 0) + 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) diff --git a/partitioners/Huarng.py b/partitioners/Huarng.py new file mode 100644 index 0000000..27d55d4 --- /dev/null +++ b/partitioners/Huarng.py @@ -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 +