diff --git a/benchmarks/benchmarks.py b/benchmarks/benchmarks.py index fa8776a..a2d83d2 100644 --- a/benchmarks/benchmarks.py +++ b/benchmarks/benchmarks.py @@ -10,10 +10,8 @@ from mpl_toolkits.mplot3d import Axes3D #from sklearn.cross_validation import KFold from pyFTS.benchmarks import Measures from pyFTS.partitioners import Grid -from pyFTS.common import Membership, FuzzySet, FLR, Transformations -import time +from pyFTS.common import Membership, FuzzySet, FLR, Transformations, Util -current_milli_time = lambda: int(round(time.time() * 1000)) def getIntervalStatistics(original, models): ret = "Model & RMSE & MAPE & Sharpness & Resolution & Coverage \\ \n" @@ -37,15 +35,6 @@ def plotDistribution(dist): vmin=0, vmax=1, edgecolors=None) -def uniquefilename(name): - if '.' in name: - tmp = name.split('.') - return tmp[0] + str(current_milli_time()) + '.' + tmp[1] - else: - return name + str(current_milli_time()) - - - def plotComparedSeries(original, models, colors, typeonlegend=False, save=False, file=None,tam=[20, 5]): fig = plt.figure(figsize=tam) ax = fig.add_subplot(111) @@ -89,10 +78,9 @@ def plotComparedSeries(original, models, colors, typeonlegend=False, save=False, ax.set_xlabel('T') ax.set_xlim([0, len(original)]) - if save: - plt.show() - fig.savefig(uniquefilename(file)) - plt.close(fig) + Util.showAndSaveImage(fig,file,save) + + def plotComparedIntervalsAhead(original, models, colors, distributions, time_from, time_to, @@ -158,10 +146,7 @@ def plotComparedIntervalsAhead(original, models, colors, distributions, time_fro ax.set_xlabel('T') ax.set_xlim([0, len(original)]) - if save: - plt.show() - fig.savefig(uniquefilename(file)) - plt.close(fig) + Util.showAndSaveImage(fig, file, save) def plotCompared(original, forecasts, labels, title): diff --git a/common/Transformations.py b/common/Transformations.py index 5c2865d..869b6f8 100644 --- a/common/Transformations.py +++ b/common/Transformations.py @@ -17,3 +17,10 @@ def boxcox(original, plambda): else: modified = [math.log(original[t]) for t in np.arange(0, n)] return np.array(modified) + + +def Z(original): + mu = np.mean(original) + sigma = np.std(original) + z = [(k - mu)/sigma for k in original] + return z diff --git a/common/Util.py b/common/Util.py new file mode 100644 index 0000000..386b2bd --- /dev/null +++ b/common/Util.py @@ -0,0 +1,20 @@ +import time +import matplotlib.pyplot as plt + + +current_milli_time = lambda: int(round(time.time() * 1000)) + + +def uniquefilename(name): + if '.' in name: + tmp = name.split('.') + return tmp[0] + str(current_milli_time()) + '.' + tmp[1] + else: + return name + str(current_milli_time()) + + +def showAndSaveImage(fig,file,flag): + if flag: + plt.show() + fig.savefig(uniquefilename(file)) + plt.close(fig) \ No newline at end of file diff --git a/partitioners/Util.py b/partitioners/Util.py index aa402a9..3c4bcf8 100644 --- a/partitioners/Util.py +++ b/partitioners/Util.py @@ -4,12 +4,12 @@ import matplotlib as plt import matplotlib.colors as pltcolors import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D -from pyFTS.common import Membership +from pyFTS.common import Membership, Util -def plotSets(data, sets, titles): +def plotSets(data, sets, titles, tam=[12, 10], save=False, file=None): num = len(sets) - fig = plt.figure(figsize=[12, 10]) + fig = plt.figure(figsize=tam) maxx = max(data) minx = min(data) h = 1/num @@ -24,4 +24,6 @@ def plotSets(data, sets, titles): elif s.mf == Membership.gaussmf: tmpx = [ kk for kk in np.arange(s.lower, s.upper)] tmpy = [s.membership(kk) for kk in np.arange(s.lower, s.upper)] - ax0.plot(tmpx, tmpy) \ No newline at end of file + ax0.plot(tmpx, tmpy) + + Util.showAndSaveImage(fig, file, save) \ No newline at end of file diff --git a/pfts.py b/pfts.py index 6522947..09f8362 100644 --- a/pfts.py +++ b/pfts.py @@ -204,7 +204,7 @@ class ProbabilisticFTS(ifts.IntervalFTS): # gerar o intervalo norm = sum(norms) if norm == 0: - ret.append([0, 0]) + ret.append(0) else: ret.append(sum(mp) / norm)