Refatoração dos métodos de exibir e salvar gráfico

This commit is contained in:
Petrônio Cândido de Lima e Silva 2017-01-20 13:51:20 -02:00
parent b0fd83a839
commit 3cc0e0ebda
5 changed files with 39 additions and 25 deletions

View File

@ -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):

View File

@ -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

20
common/Util.py Normal file
View File

@ -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)

View File

@ -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
@ -25,3 +25,5 @@ def plotSets(data, sets, titles):
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)
Util.showAndSaveImage(fig, file, save)

View File

@ -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)