Estudo Comparativo de Modelos de Séries Temporais Nebulosas

Importações Comuns


In [1]:
import numpy as np
import pandas as pd
import matplotlib as plt
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from sklearn.cross_validation import KFold
%pylab inline


Populating the interactive namespace from numpy and matplotlib

Metodologia

O objetivo desse estudo é gerar um modelo de predição de séries temporais para os conjuntos de dados Enrollments e TAIEX, obtido a partir da comparação do desempenho entre algumas das mais conhecidas técnicas existentes na literatura. É desejável, mas não imprescindível, ainda que esse modelo seja analisável com boa interpretabilidade das regras.

Para cada método de FTS implementado será investigado o seu desempenho para: \begin{enumerate} \item Os valores originais da série ($F(T)$) e as variações ($\Delta F(T)$) \item Diferentes partições de $U$ \item Variação nos parâmetros específicos de cada modelo \end{enumerate}

Serão escolhidos os parâmetros para cada modelo com menor erro percentual médio / erro quadrático médio e depois os diversos modelos serão comparados entre si.


In [2]:
# Erro quadrático médio
def rmse(predictions,targets):
    return np.sqrt(np.mean((predictions-targets)**2))

# Erro Percentual médio
def mape(predictions,targets):
    return np.mean(abs(predictions-targets)/predictions)

In [3]:
def plotComparedSeries(original,fts,title):
	fig = plt.figure(figsize=[20,6])
	ax = fig.add_subplot(111)
	predicted = [fts.predict(xx) for xx in original]
	error = rmse(original,predicted)
	ax.plot(original,color='b',label="Original")
	ax.plot(predicted,color='r',label="Predicted")
	handles0, labels0 = ax.get_legend_handles_labels()
	ax.legend(handles0,labels0)
	ax.set_title(title)
	ax.set_ylabel('F(T)')
	ax.set_xlabel('T')
	ax.set_xlim([0,len(original)])
	ax.set_ylim([min(original),max(original)])

In [109]:
def plotCompared(original,predicted,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(predicted)):
		ax.plot(predicted[c],label=labels[c])
	handles0, labels0 = ax.get_legend_handles_labels()
	ax.legend(handles0,labels0)
	ax.set_title(title)
	ax.set_ylabel('F(T)')
	ax.set_xlabel('T')
	ax.set_xlim([0,len(original)])
	ax.set_ylim([min(original),max(original)])

In [5]:
a = np.arange(0,5)
a


Out[5]:
array([0, 1, 2, 3, 4])

In [101]:
def SelecaoKFold_MenorRMSE(original,parameters,modelo):
	nfolds = 5
	ret = []
	errors = np.array([[0 for k in parameters] for z in np.arange(0,nfolds)])
	predicted_best = []
	print("Série Original")
	fig = plt.figure(figsize=[18,10])
	fig.suptitle("Comparação de modelos ")
	ax0 = fig.add_axes([0, 0.5, 0.65, 0.45]) #left, bottom, width, height
	ax0.set_xlim([0,len(original)])
	ax0.set_ylim([min(original),max(original)])
	ax0.set_title('Série Temporal')
	ax0.set_ylabel('F(T)')
	ax0.set_xlabel('T')
	ax0.plot(original,label="Original")
	min_rmse_fold = 100000.0
	best = None
	fc = 0 #Fold count
	kf = KFold(len(original), n_folds=nfolds)
	for train_ix, test_ix in kf:
		train = original[train_ix]
		test = original[test_ix]
		min_rmse = 100000.0
		best_fold = None
		predicted_best_fold = []
		errors_fold = []
		pc = 0 #Parameter count
		for p in parameters:
			sets = GridPartitionerTrimf(train,p)
			fts = modelo(str(p)+ " particoes")
			fts.learn(train,sets)
			predicted = [fts.predict(xx) for xx in test]
			error = rmse(np.array(predicted),np.array(test))
			errors_fold.append(error)
			print(fc, p, error)
			errors[fc,pc] = error
			if error < min_rmse:
				min_rmse = error
				best_fold = fts
				predicted_best_fold = predicted
			pc = pc + 1
		predicted_best_fold = [best_fold.predict(xx) for xx in original]
		ax0.plot(predicted_best_fold,label=best_fold.name)
		if np.mean(errors_fold) < min_rmse_fold:
			min_rmse_fold = np.mean(errors)
			best = best_fold
			predicted_best = predicted_best_fold 
		fc = fc + 1
	handles0, labels0 = ax0.get_legend_handles_labels()
	ax0.legend(handles0, labels0)
	ax1 = Axes3D(fig, rect=[0.7, 0.5, 0.3, 0.45], elev=30, azim=144)
	#ax1 = fig.add_axes([0.6, 0.0, 0.45, 0.45], projection='3d')
	ax1.set_title('Comparação dos Erros Quadráticos Médios')
	ax1.set_zlabel('RMSE')
	ax1.set_xlabel('K-fold')
	ax1.set_ylabel('Partições')
	X,Y = np.meshgrid(np.arange(0,nfolds),parameters)
	surf = ax1.plot_surface(X, Y, errors.T, rstride=1, cstride=1, antialiased=True)
	ret.append(best)
	ret.append(predicted_best)

    # Modelo diferencial
	print("\nSérie Diferencial")
	errors = np.array([[0 for k in parameters] for z in np.arange(0,nfolds)])
	predictedd_best = []
	ax2 = fig.add_axes([0, 0, 0.65, 0.45]) #left, bottom, width, height
	ax2.set_xlim([0,len(original)])
	ax2.set_ylim([min(original),max(original)])
	ax2.set_title('Série Temporal')
	ax2.set_ylabel('F(T)')
	ax2.set_xlabel('T')
	ax2.plot(original,label="Original")
	min_rmse = 100000.0
	min_rmse_fold = 100000.0
	bestd = None
	fc = 0
	diff = diferencas(original)       
	kf = KFold(len(original), n_folds=nfolds)
	for train_ix, test_ix in kf:
		train = diff[train_ix]
		test = diff[test_ix]
		min_rmse = 100000.0
		best_fold = None
		predicted_best_fold = []
		errors_fold = []
		pc = 0
		for p in parameters:
			sets = GridPartitionerTrimf(train,p)
			fts = modelo(str(p)+ " particoes")
			fts.learn(train,sets)
			predicted = [fts.predictDiff(test,xx) for xx in np.arange(len(test))]
			error = rmse(np.array(predicted),np.array(test))
			print(fc, p,error)
			errors[fc,pc] = error
			errors_fold.append(error)
			if error < min_rmse:
				min_rmse = error
				best_fold = fts
			pc = pc + 1
		predicted_best_fold = [best_fold.predictDiff(original, xx) for xx in np.arange(len(original))]
		ax2.plot(predicted_best_fold,label=best_fold.name)
		if np.mean(errors_fold) < min_rmse_fold:
			min_rmse_fold = np.mean(errors)
			best = best_fold
			predicted_best = predicted_best_fold
		fc = fc + 1
	handles0, labels0 = ax2.get_legend_handles_labels()
	ax2.legend(handles0, labels0)
	ax3 = Axes3D(fig, rect=[0.7, 0, 0.3, 0.45], elev=30, azim=144)
	#ax1 = fig.add_axes([0.6, 0.0, 0.45, 0.45], projection='3d')
	ax3.set_title('Comparação dos Erros Quadráticos Médios')
	ax3.set_zlabel('RMSE')
	ax3.set_xlabel('K-fold')
	ax3.set_ylabel('Partições')
	X,Y = np.meshgrid(np.arange(0,nfolds),parameters)
	surf = ax3.plot_surface(X, Y, errors.T, rstride=1, cstride=1, antialiased=True)
	ret.append(best)
	ret.append(predicted_best)
	return ret

In [7]:
def SelecaoSimples_MenorRMSE(original,parameters,modelo):
	ret = []
	errors = []
	predicted_best = []
	print("Série Original")
	fig = plt.figure(figsize=[20,12])
	fig.suptitle("Comparação de modelos ")
	ax0 = fig.add_axes([0, 0.5, 0.65, 0.45]) #left, bottom, width, height
	ax0.set_xlim([0,len(original)])
	ax0.set_ylim([min(original),max(original)])
	ax0.set_title('Série Temporal')
	ax0.set_ylabel('F(T)')
	ax0.set_xlabel('T')
	ax0.plot(original,label="Original")
	min_rmse = 100000.0
	best = None
	for p in parameters:
		sets = GridPartitionerTrimf(original,p)
		fts = modelo(str(p)+ " particoes")
		fts.learn(original,sets)
		predicted = [fts.predict(xx) for xx in original]
		ax0.plot(predicted,label=fts.name)
		error = rmse(np.array(predicted),np.array(original))
		print(p,error)
		errors.append(error)
		if error < min_rmse:
			min_rmse = error
			best = fts
			predicted_best = predicted
	handles0, labels0 = ax0.get_legend_handles_labels()
	ax0.legend(handles0, labels0)
	ax1 = fig.add_axes([0.7, 0.5, 0.3, 0.45]) #left, bottom, width, height
	ax1.set_title('Comparação dos Erros Quadráticos Médios')
	ax1.set_ylabel('RMSE')
	ax1.set_xlabel('Quantidade de Partições')
	ax1.set_xlim([min(parameters),max(parameters)])
	ax1.plot(parameters,errors)
	ret.append(best)
	ret.append(predicted_best)
    # Modelo diferencial
	print("\nSérie Diferencial")
	errors = []
	predictedd_best = []
	ax2 = fig.add_axes([0, 0, 0.65, 0.45]) #left, bottom, width, height
	ax2.set_xlim([0,len(original)])
	ax2.set_ylim([min(original),max(original)])
	ax2.set_title('Série Temporal')
	ax2.set_ylabel('F(T)')
	ax2.set_xlabel('T')
	ax2.plot(original,label="Original")
	min_rmse = 100000.0
	bestd = None
	for p in parameters:
		sets = GridPartitionerTrimf(diferencas(original),p)
		fts = modelo(str(p)+ " particoes")
		fts.learn(diferencas(original),sets)
		predicted = [fts.predictDiff(original, xx) for xx in range(1,len(original))]
		predicted.insert(0,original[0])
		ax2.plot(predicted,label=fts.name)
		error = rmse(np.array(predicted),np.array(original))
		print(p,error)
		errors.append(error)
		if error < min_rmse:
			min_rmse = error
			bestd = fts
			predictedd_best = predicted
	handles0, labels0 = ax2.get_legend_handles_labels()
	ax2.legend(handles0, labels0)
	ax3 = fig.add_axes([0.7, 0, 0.3, 0.45]) #left, bottom, width, height
	ax3.set_title('Comparação dos Erros Quadráticos Médios')
	ax3.set_ylabel('RMSE')
	ax3.set_xlabel('Quantidade de Partições')
	ax3.set_xlim([min(parameters),max(parameters)])
	ax3.plot(parameters,errors)
	ret.append(bestd)
	ret.append(predictedd_best)
	return ret

In [106]:
def compareModelsPlot(original,models_fo,models_ho):
    fig = plt.figure(figsize=[13,6])
    fig.suptitle("Comparação de modelos ")
    ax0 = fig.add_axes([0, 0, 1, 1]) #left, bottom, width, height
    rows = []
    for model in models_fo:
        fts = model["model"]
        ax0.plot(model["predicted"], label=model["name"])
    for model in models_ho:
        fts = model["model"]
        ax0.plot(model["predicted"], label=model["name"])
    handles0, labels0 = ax0.get_legend_handles_labels()
    ax0.legend(handles0, labels0)
    
def compareModelsTable(original,models_fo,models_ho):
    fig = plt.figure(figsize=[12,4])
    fig.suptitle("Comparação de modelos ")
    columns = ['Modelo','Ordem','Partições','RMSE','MAPE (%)']
    rows = []
    for model in models_fo:
        fts = model["model"]
        error_r = rmse(model["predicted"],original)
        error_m = round(mape(model["predicted"],original)*100,2)
        rows.append([model["name"],fts.order,len(fts.sets),error_r,error_m])
    for model in models_ho:
        fts = model["model"]
        error_r = rmse(model["predicted"][fts.order:],original[fts.order:])
        error_m = round(mape(model["predicted"][fts.order:],original[fts.order:])*100,2)
        rows.append([model["name"],fts.order,len(fts.sets),error_r,error_m])
    ax1 = fig.add_axes([0, 0, 1, 1]) #left, bottom, width, height
    ax1.set_xticks([])
    ax1.set_yticks([])
    ax1.table(cellText=rows,
                      colLabels=columns,
                      cellLoc='center',
                      bbox=[0,0,1,1])
    sup = "\\begin{tabular}{"
    header = ""
    body = ""
    footer = ""

    for c in columns:
        sup = sup + "|c"
        if len(header) > 0:
            header = header + " & "
        header = header + "\\textbf{" + c + "} "
    sup = sup + "|} \\hline\n"
    header = header + "\\\\ \\hline \n"    
    
    for r in rows:
        lin = ""
        for c in r:
            if len(lin) > 0:
                lin = lin + " & "
            lin = lin + str(c)
        
        body = body + lin + "\\\\ \\hline \n" 
        
    return sup + header + body + "\\end{tabular}"

In [9]:
enrolments_modelbase_fo = []
enrolments_modelbase_ho = []
taiex_modelbase_fo = []
taiex_modelbase_ho = []

Dados de Treinamento e Validação

Série Diferencial / Variações

A função de diferença serve para gerar um dataset que, ao invés do valor $F(t)$ original da série, terá a diferença entre dois valores consecutivos ou seja $\Delta F(t) = F(t-1) - F(t)$. O primeiro valor da série de diferenças é sempre considerado $0$.

Nesse tipo de série, o universo de discurso é dado por $U = [\min(\Delta F(t)),\max(\Delta F(t))]$


In [10]:
def diferencas(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)

University Of Alabama Enrollments

O dataset abaixo foi retirado do artigo \cite{song1993fuzzy}


In [99]:
enrollments = pd.read_csv("DataSets/Enrollments.csv", sep=";")
enrollments = np.array(enrollments["Enrollments"])
fig = plt.figure(figsize=[10,5])
plot(enrollments)


Out[99]:
[<matplotlib.lines.Line2D at 0xaa17dd6c>]

In [98]:
fig = plt.figure(figsize=[10,5])
plot(diferencas(enrollments))


Out[98]:
[<matplotlib.lines.Line2D at 0xa9ef8e8c>]

TAIEX - Taiwan Stock Exchange Index

O dataset foi provido por \cite{taiex2015}


In [97]:
taiex = pd.read_csv("DataSets/TAIEX.csv", sep=",")
taiexsample = np.array(taiex["avg"][1:2000])
fig = plt.figure(figsize=[10,5])
plot(taiexsample)


Out[97]:
[<matplotlib.lines.Line2D at 0xaa07f6ac>]

In [96]:
fig = plt.figure(figsize=[10,5])
plot(diferencas(taiexsample))
#np.array(taiexsample)


Out[96]:
[<matplotlib.lines.Line2D at 0xaa0f7f4c>]

Códigos Comuns

Funções de Pertinência


In [15]:
def trimf(x,parameters):
	if(x < parameters[0]):
		return 0
	elif(x >= parameters[0] and x < parameters[1]):
		return (x-parameters[0])/(parameters[1]-parameters[0])
	elif(x >= parameters[1] and x <= parameters[2]):
		return (parameters[2]-x)/(parameters[2]-parameters[1])
	else: 
		return 0

def trapmf(x, parameters):
		if(x < parameters[0]):
			return 0
		elif(x >= parameters[0] and x < parameters[1]):
			return (x-parameters[0])/(parameters[1]-parameters[0])
		elif(x >= parameters[1] and x <= parameters[2]):
			return 1
		elif(x >= parameters[2] and x <= parameters[3]):
			return (parameters[3]-x)/(parameters[3]-parameters[2])
		else: 
			return 0

def gaussmf(x,parameters):
		return math.exp(-0.5*((x-parameters[0]) / parameters[1] )**2)


def bellmf(x,parameters):
		return 1 / (1 + abs((xx - parameters[2])/parameters[0])**(2*parameters[1]))


def sigmf(x,parameters):
		return 1 / (1 + math.exp(-parameters[0] * (x - parameters[1])))

Conjuntos Nebulosos


In [16]:
class FuzzySet:

	def __init__(self,name,mf,parameters,centroid):
		self.name = name
		self.mf = mf
		self.parameters = parameters
		self.centroid = centroid
        
	def membership(self,x):
		return self.mf(x,self.parameters)
    
	def __str__(self):
		return self.name + ": " + str(self.mf) + "(" + str(self.parameters) + ")"

Particionadores do Universo de Discurso


In [17]:
def GridPartitionerTrimf(data,npart,names = None,prefix = "A"):
	sets = []
	dmax = max(data)
	dmin = min(data)
	dlen = dmax - dmin
	partlen = dlen / npart
	partition = dmin
	for c in range(npart):
		sets.append( FuzzySet(prefix+str(c),trimf,[partition-partlen, partition, partition+partlen], partition ) )
		partition = partition + partlen
		
	return sets

In [18]:
sts = GridPartitionerTrimf(enrollments,10)
for s in sts:
    print(s)


A0: <function trimf at 0xaa1b6464>([12426.799999999999, 13055, 13683.200000000001])
A1: <function trimf at 0xaa1b6464>([13055.0, 13683.200000000001, 14311.400000000001])
A2: <function trimf at 0xaa1b6464>([13683.200000000001, 14311.400000000001, 14939.600000000002])
A3: <function trimf at 0xaa1b6464>([14311.400000000001, 14939.600000000002, 15567.800000000003])
A4: <function trimf at 0xaa1b6464>([14939.600000000002, 15567.800000000003, 16196.000000000004])
A5: <function trimf at 0xaa1b6464>([15567.800000000003, 16196.000000000004, 16824.200000000004])
A6: <function trimf at 0xaa1b6464>([16196.000000000004, 16824.200000000004, 17452.400000000005])
A7: <function trimf at 0xaa1b6464>([16824.200000000004, 17452.400000000005, 18080.600000000006])
A8: <function trimf at 0xaa1b6464>([17452.400000000005, 18080.600000000006, 18708.800000000007])
A9: <function trimf at 0xaa1b6464>([18080.600000000006, 18708.800000000007, 19337.000000000007])

In [19]:
class FTS:
	def __init__(self,order,name):
		self.sets = {}
		self.flrgs = {}
		self.order = order
		self.name = name
        
	def fuzzy(self,data):
		best = {"fuzzyset":"", "membership":0.0}

		for f in self.sets:
			fset = self.sets[f]
			if best["membership"] <= fset.membership(data):
				best["fuzzyset"] = fset.name
				best["membership"] = fset.membership(data)

		return best

	def defuzzy(self,data):
		pass

	def learn(self, data, sets):
		pass  

	def predict(self,data):
		return self.defuzzy(data)

	def predictDiff(self,data,t):
		return data[t] + self.defuzzy(data[t-1]-data[t])

	def __str__(self):
		tmp = self.name + ":\n"
		for r in self.flrgs.keys():
			tmp = tmp + str(self.flrgs[r]) + "\n"
		return tmp

In [ ]:

First Order Fuzzy Time Series

Os trabalhos pioneiros em séries temporais nebulosas são de \cite{song1993fuzzy} e a evolução apresentada por \cite{chen1996forecasting}. Nesses trabalhos define-se que o modelo de primeira ordem (\textit{First Order Fuzzy Time Series}) caracteriza-se por presumir que $F(t)$ é determinado unicamente por $F(t-1)$ ( ou $F(t-2)$ ou ... ou $F(t-m)$ ).

FTS - Código Fonte


In [20]:
class FirstOrderFLRG:
	def __init__(self,premiss):
		self.premiss = premiss
		self.consequent = set()
	
	def append(self,c):
		self.consequent.add(c)

	def __str__(self):
		tmp = self.premiss + " -> "
		tmp2 = ""
		for c in self.consequent:
			if len(tmp2) > 0:
				tmp2 = tmp2 + ","
			tmp2 = tmp2 + c
		return tmp + tmp2

In [21]:
class FirstOrderFTS(FTS):
	def __init__(self,name):
		super(FirstOrderFTS, self).__init__(1,name)
        
	def defuzzy(self,data):
        
		actual = self.fuzzy(data)
        
		if actual["fuzzyset"] not in self.flrgs:
			return self.sets[actual["fuzzyset"]].centroid

		flrg = self.flrgs[actual["fuzzyset"]]

		count = 0.0
		denom = 0.0

		for s in flrg.consequent:
			denom = denom + self.sets[s].centroid
			count = count + 1.0

		return denom/count
        
	def learn(self, data, sets):
		last = {"fuzzyset":"", "membership":0.0}
		actual = {"fuzzyset":"", "membership":0.0}
		
		for s in sets:
			self.sets[s.name] = s
		
		self.flrgs = {}
		count = 1
		for inst in data:
			actual = self.fuzzy(inst)
			
			if count > self.order:
				if last["fuzzyset"] not in self.flrgs:
					self.flrgs[last["fuzzyset"]] = FirstOrderFLRG(last["fuzzyset"])
			
				self.flrgs[last["fuzzyset"]].append(actual["fuzzyset"])    
			count = count + 1
			last = actual

FTS - Experimento com o dataset Enrollments


In [22]:
fts1,fts1p,ftsd1,ftsd1p = SelecaoSimples_MenorRMSE(enrollments,[4,8, 10,20, 30],FirstOrderFTS)


Série Original
4 824.468539217
8 1489.85136323
10 435.391975956
20 630.50536693
30 504.555710502

Série Diferencial
4 318.45943084
8 462.123024346
10 385.15987482
20 492.788040519
30 513.883680045

In [23]:
print(fts1)


10 particoes:
A0 -> A1
A6 -> A6,A5,A8
A5 -> A4,A6
A3 -> A4,A5,A3
A4 -> A4,A6,A3
A9 -> A9
A1 -> A1,A3
A8 -> A9


In [24]:
plotCompared(enrollments,[fts1p,ftsd1p],["Normal","Diferenças"],'')
enrolments_modelbase_fo.append({"name":"FTS","model":fts1,"predicted":fts1p})
enrolments_modelbase_fo.append({"name":"FTS Dif.","model":ftsd1,"predicted":ftsd1p})


FTS - Experimento com o dataset TAIEX


In [102]:
fts2,fts2p,ftsd2,ftsd2p= SelecaoKFold_MenorRMSE(taiexsample,[10,15,20,25,30,35],FirstOrderFTS)


Série Original
0 10 199.873647999
0 15 130.202701911
0 20 94.2070950366
0 25 78.6505526659
0 30 244.570087966
0 35 90.6568444078
1 10 332.114316343
1 15 207.234853698
1 20 143.926633637
1 25 136.921627024
1 30 395.960841822
1 35 89.8036289868
2 10 186.445272344
2 15 136.17258399
2 20 121.878069043
2 25 116.678346067
2 30 273.584531751
2 35 84.4098587618
3 10 372.602475581
3 15 280.568365173
3 20 389.314036614
3 25 372.462096818
3 30 403.369130404
3 35 191.302007064
4 10 1470.07412034
4 15 1820.12617247
4 20 1682.72427989
4 25 1540.13132105
4 30 1156.84806365
4 35 2143.85797342

Série Diferencial
0 10 63.0426005645
0 15 35.0260661753
0 20 46.0256257953
0 25 33.3927309063
0 30 38.56795484
0 35 39.0551866268
1 10 51.2676362909
1 15 43.8078872614
1 20 47.6139575343
1 25 40.6333917422
1 30 38.4400391198
1 35 48.7708958374
2 10 71.2729311547
2 15 66.8766094156
2 20 71.5706563389
2 25 63.3542735368
2 30 57.5989874657
2 35 69.9883131833
3 10 61.3851127157
3 15 66.8146148313
3 20 56.0785945588
3 25 75.5308792812
3 30 72.8628362289
3 35 94.7831267714
4 10 66.2530791567
4 15 43.6181435564
4 20 41.8508512836
4 25 44.2325382296
4 30 42.3597218318
4 35 42.37980633

In [26]:
print(ftsd2)


25 particoes:
A14 -> A14,A15,A6,A5,A16,A9,A17,A8,A12,A19,A7,A20,A11,A10,A13,A18
A6 -> A6,A5,A16,A9,A8,A12,A7,A11,A10,A13
A19 -> A12,A8
A11 -> A14,A15,A6,A16,A9,A12,A8,A7,A11,A10,A13,A18
A3 -> A4,A10
A10 -> A14,A15,A6,A3,A16,A2,A9,A24,A12,A8,A17,A7,A11,A10,A22,A13
A9 -> A14,A15,A6,A5,A16,A9,A17,A12,A8,A7,A11,A10,A21,A13
A17 -> A14,A15,A16,A9,A19,A12,A11,A18,A13
A8 -> A14,A6,A5,A9,A12,A8,A7,A11,A10,A13
A7 -> A14,A3,A9,A17,A12,A8,A7,A11,A10
A21 -> A8
A2 -> A9,A12
A4 -> A4,A13,A9
A12 -> A14,A15,A6,A5,A16,A9,A17,A12,A8,A7,A0,A20,A11,A10,A13,A18
A18 -> A14,A15,A6,A17,A12,A8,A11,A10,A13
A24 -> A18
A15 -> A14,A15,A16,A9,A12,A8,A20,A11,A10,A13,A18
A5 -> A10,A8,A14,A9,A12
A16 -> A15,A16,A9,A17,A12,A7,A11,A21,A10,A13,A18
A0 -> A11
A20 -> A13,A15,A3,A8
A22 -> A12
A13 -> A14,A15,A6,A16,A2,A9,A17,A8,A12,A7,A11,A10,A13,A4,A18


In [27]:
plotCompared(taiexsample,[fts2p,ftsd2p],["Normal","Diferenças"],'')
taiex_modelbase_fo.append({"name":"FTS","model":fts2,"predicted":fts2p})
taiex_modelbase_fo.append({"name":"FTS Dif.","model":ftsd2,"predicted":ftsd2p})


Weighted Fuzzy Time Series

O trabalho de \cite{yu2005weighted} propõe um modelo - as \textit{Weighted Fuzzy Time Series} - em que os grupos de regras permitem repetições no consequente e tenham ponderação monotonicamente crescente, baseado na ordem cronológica dos termos no consequente. Nesse modelo as FLRG's permitem a repetição de conjuntos no consequente das regras, e os conjuntos devem ser apresentados em ordem cronológica.

WFTS - Código Fonte


In [28]:
class WeightedFLRG(FTS):
	def __init__(self,premiss):
		self.premiss = premiss
		self.consequent = []
		self.count = 1.0

	def append(self,c):
		self.consequent.append(c)
		self.count = self.count + 1.0

	def weights(self):
		tot = sum( np.arange(1.0,self.count,1.0) )
		return np.array([ k/tot for k in np.arange(1.0,self.count,1.0) ])
        
	def __str__(self):
		tmp = self.premiss + " -> "
		tmp2 = ""
		cc = 1.0
		tot = sum( np.arange(1.0,self.count,1.0) )
		for c in self.consequent:
			if len(tmp2) > 0:
				tmp2 = tmp2 + ","
			tmp2 = tmp2 + c + "(" + str(cc/tot) + ")"
			cc = cc + 1.0
		return tmp + tmp2

In [29]:
class WeightedFTS(FTS):
	def __init__(self,name):
		super(WeightedFTS, self).__init__(1,name)
        
	def defuzzy(self,data):
        
		actual = self.fuzzy(data)
        
		if actual["fuzzyset"] not in self.flrgs:
			return self.sets[actual["fuzzyset"]].centroid

		flrg = self.flrgs[actual["fuzzyset"]]

		mi = np.array([self.sets[s].centroid for s in flrg.consequent])
        
		return mi.dot( flrg.weights() )
        
	def learn(self, data, sets):
		last = {"fuzzyset":"", "membership":0.0}
		actual = {"fuzzyset":"", "membership":0.0}
		
		for s in sets:
			self.sets[s.name] = s
		
		self.flrgs = {}
		count = 1
		for inst in data:
			actual = self.fuzzy(inst)
			
			if count > self.order:
				if last["fuzzyset"] not in self.flrgs:
					self.flrgs[last["fuzzyset"]] = WeightedFLRG(last["fuzzyset"])
			
				self.flrgs[last["fuzzyset"]].append(actual["fuzzyset"])    
			count = count + 1
			last = actual

WFTS - Experimento com o dataset Enrollments


In [30]:
wfts1,wfts1p,wftsd1,wftsd1p = SelecaoSimples_MenorRMSE(enrollments,[6,8,10,12,14], WeightedFTS)


Série Original
6 1469.11529887
8 1736.75458077
10 489.718215586
12 669.096511757
14 523.447886773

Série Diferencial
6 502.659582059
8 400.937452453
10 404.600907881
12 398.685259658
14 489.728297622

In [31]:
print(wfts1)


10 particoes:
A0 -> A1(1.0)
A6 -> A6(0.166666666667),A5(0.333333333333),A8(0.5)
A5 -> A4(0.333333333333),A6(0.666666666667)
A3 -> A4(0.166666666667),A3(0.333333333333),A5(0.5)
A4 -> A4(0.047619047619),A4(0.0952380952381),A4(0.142857142857),A6(0.190476190476),A4(0.238095238095),A3(0.285714285714)
A9 -> A9(0.166666666667),A9(0.333333333333),A9(0.5)
A1 -> A1(0.333333333333),A3(0.666666666667)
A8 -> A9(1.0)


In [32]:
plotCompared(enrollments,[wfts1p,wftsd1p],["Normal","Diferenças"],'')
enrolments_modelbase_fo.append({"name":"WFTS","model":wfts1,"predicted":wfts1p})
enrolments_modelbase_fo.append({"name":"WFTS Dif.","model":wftsd1,"predicted":wftsd1p})


WFTS - Experimento com o dataset TAIEX


In [33]:
wfts2,wfts2p,wftsd2,wftsd2p = SelecaoKFold_MenorRMSE(taiexsample,[2,5,10,15,20,25,30,35], WeightedFTS)


Série Original
0 2 1134.31988753
0 5 306.101184895
0 10 211.654861979
0 15 133.047922956
0 20 93.6094013008
0 25 77.5784468693
0 30 66.6305913671
0 35 58.9294204783
1 2 1422.85437658
1 5 490.766314004
1 10 232.949369062
1 15 151.383244689
1 20 103.073132767
1 25 83.130777915
1 30 91.6492993623
1 35 65.7161284205
2 2 1143.34685399
2 5 383.998205071
2 10 193.203077473
2 15 139.309184977
2 20 100.589969335
2 25 75.3914287192
2 30 75.2167667994
2 35 60.4872530915
3 2 1651.99887594
3 5 546.606644545
3 10 270.770337911
3 15 179.333327954
3 20 272.296502395
3 25 334.998128675
3 30 388.336393866
3 35 114.97157321
4 2 792.567657984
4 5 383.418913212
4 10 1456.11147281
4 15 1811.64732597
4 20 1531.67083588
4 25 1352.22019867
4 30 1146.35704414
4 35 2154.96750054

Série Diferencial
0 2 41.8288977534
0 5 20.2537652398
0 10 24.5597336835
0 15 22.1443368427
0 20 22.6338319428
0 25 21.6514837976
0 30 27.0131645563
0 35 25.3897633536
1 2 41.7054991679
1 5 23.0428704493
1 10 28.6578935126
1 15 35.4150721629
1 20 28.1851332899
1 25 28.3790151837
1 30 32.4291057684
1 35 44.5260340536
2 2 74.5275223626
2 5 21.2110235052
2 10 38.1630770674
2 15 43.1225805334
2 20 50.4494220648
2 25 46.1266663692
2 30 47.8952209552
2 35 65.2857710242
3 2 31.3182744917
3 5 39.3988770471
3 10 41.4233920756
3 15 58.815505278
3 20 56.9767138154
3 25 73.8049417274
3 30 74.4148536224
3 35 91.7844706137
4 2 39.2147260417
4 5 23.1099815272
4 10 25.6451537462
4 15 26.4087204764
4 20 23.9955358036
4 25 24.9969000833
4 30 27.1707418027
4 35 28.2481537799

In [34]:
print(wfts2)


35 particoes:
A14 -> A14(0.000438981562774),A14(0.000877963125549),A14(0.00131694468832),A14(0.0017559262511),A15(0.00219490781387),A14(0.00263388937665),A14(0.00307287093942),A14(0.00351185250219),A14(0.00395083406497),A13(0.00438981562774),A14(0.00482879719052),A14(0.00526777875329),A14(0.00570676031607),A14(0.00614574187884),A14(0.00658472344162),A13(0.00702370500439),A14(0.00746268656716),A14(0.00790166812994),A14(0.00834064969271),A14(0.00877963125549),A14(0.00921861281826),A14(0.00965759438104),A15(0.0100965759438),A14(0.0105355575066),A14(0.0109745390694),A13(0.0114135206321),A14(0.0118525021949),A14(0.0122914837577),A14(0.0127304653205),A14(0.0131694468832),A14(0.013608428446),A14(0.0140474100088),A15(0.0144863915716),A15(0.0149253731343),A14(0.0153643546971),A15(0.0158033362599),A13(0.0162423178227),A14(0.0166812993854),A13(0.0171202809482),A15(0.017559262511),A15(0.0179982440737),A15(0.0184372256365),A13(0.0188762071993),A14(0.0193151887621),A13(0.0197541703248),A13(0.0201931518876),A13(0.0206321334504),A14(0.0210711150132),A14(0.0215100965759),A13(0.0219490781387),A14(0.0223880597015),A14(0.0228270412643),A14(0.023266022827),A14(0.0237050043898),A14(0.0241439859526),A14(0.0245829675154),A15(0.0250219490781),A14(0.0254609306409),A14(0.0258999122037),A14(0.0263388937665),A13(0.0267778753292),A14(0.027216856892),A14(0.0276558384548),A14(0.0280948200176),A15(0.0285338015803),A14(0.0289727831431),A13(0.0294117647059)
A0 -> A0(0.0277777777778),A0(0.0555555555556),A1(0.0833333333333),A0(0.111111111111),A0(0.138888888889),A0(0.166666666667),A0(0.194444444444),A1(0.222222222222)
A8 -> A8(0.00128205128205),A9(0.0025641025641),A10(0.00384615384615),A8(0.00512820512821),A8(0.00641025641026),A7(0.00769230769231),A9(0.00897435897436),A8(0.0102564102564),A8(0.0115384615385),A9(0.0128205128205),A9(0.0141025641026),A8(0.0153846153846),A8(0.0166666666667),A8(0.0179487179487),A8(0.0192307692308),A9(0.0205128205128),A8(0.0217948717949),A8(0.0230769230769),A8(0.024358974359),A8(0.025641025641),A7(0.0269230769231),A9(0.0282051282051),A8(0.0294871794872),A8(0.0307692307692),A8(0.0320512820513),A9(0.0333333333333),A8(0.0346153846154),A8(0.0358974358974),A8(0.0371794871795),A7(0.0384615384615),A8(0.0397435897436),A8(0.0410256410256),A7(0.0423076923077),A8(0.0435897435897),A7(0.0448717948718),A7(0.0461538461538),A8(0.0474358974359),A8(0.0487179487179),A7(0.05)
A6 -> A6(0.00189393939394),A7(0.00378787878788),A6(0.00568181818182),A6(0.00757575757576),A6(0.0094696969697),A6(0.0113636363636),A6(0.0132575757576),A6(0.0151515151515),A5(0.0170454545455),A6(0.0189393939394),A6(0.0208333333333),A6(0.0227272727273),A6(0.0246212121212),A6(0.0265151515152),A5(0.0284090909091),A5(0.030303030303),A6(0.032196969697),A5(0.0340909090909),A6(0.0359848484848),A7(0.0378787878788),A6(0.0397727272727),A6(0.0416666666667),A6(0.0435606060606),A7(0.0454545454545),A6(0.0473484848485),A6(0.0492424242424),A5(0.0511363636364),A6(0.0530303030303),A6(0.0549242424242),A6(0.0568181818182),A5(0.0587121212121),A5(0.0606060606061)
A32 -> A32(0.004329004329),A32(0.00865800865801),A32(0.012987012987),A32(0.017316017316),A33(0.021645021645),A31(0.025974025974),A33(0.030303030303),A32(0.034632034632),A33(0.038961038961),A31(0.04329004329),A32(0.047619047619),A32(0.0519480519481),A33(0.0562770562771),A32(0.0606060606061),A31(0.0649350649351),A32(0.0692640692641),A32(0.0735930735931),A31(0.0779220779221),A29(0.0822510822511),A33(0.0865800865801),A31(0.0909090909091)
A3 -> A3(0.0151515151515),A4(0.030303030303),A3(0.0454545454545),A3(0.0606060606061),A2(0.0757575757576),A3(0.0909090909091),A3(0.106060606061),A3(0.121212121212),A4(0.136363636364),A3(0.151515151515),A4(0.166666666667)
A1 -> A1(0.0277777777778),A1(0.0555555555556),A0(0.0833333333333),A1(0.111111111111),A0(0.138888888889),A2(0.166666666667),A1(0.194444444444),A2(0.222222222222)
A10 -> A11(0.000725689404935),A11(0.00145137880987),A10(0.0021770682148),A10(0.00290275761974),A10(0.00362844702467),A9(0.00435413642961),A10(0.00507982583454),A10(0.00580551523948),A9(0.00653120464441),A10(0.00725689404935),A10(0.00798258345428),A10(0.00870827285922),A11(0.00943396226415),A10(0.0101596516691),A11(0.010885341074),A10(0.011611030479),A10(0.0123367198839),A11(0.0130624092888),A10(0.0137880986938),A10(0.0145137880987),A11(0.0152394775036),A10(0.0159651669086),A10(0.0166908563135),A10(0.0174165457184),A9(0.0181422351234),A9(0.0188679245283),A11(0.0195936139332),A10(0.0203193033382),A10(0.0210449927431),A10(0.021770682148),A9(0.022496371553),A10(0.0232220609579),A10(0.0239477503628),A11(0.0246734397678),A11(0.0253991291727),A10(0.0261248185776),A11(0.0268505079826),A11(0.0275761973875),A10(0.0283018867925),A10(0.0290275761974),A10(0.0297532656023),A11(0.0304789550073),A10(0.0312046444122),A10(0.0319303338171),A10(0.0326560232221),A10(0.033381712627),A9(0.0341074020319),A10(0.0348330914369),A9(0.0355587808418),A10(0.0362844702467),A10(0.0370101596517),A9(0.0377358490566)
A9 -> A10(0.00078431372549),A8(0.00156862745098),A8(0.00235294117647),A9(0.00313725490196),A9(0.00392156862745),A9(0.00470588235294),A9(0.00549019607843),A9(0.00627450980392),A9(0.00705882352941),A9(0.0078431372549),A10(0.00862745098039),A8(0.00941176470588),A9(0.0101960784314),A9(0.0109803921569),A10(0.0117647058824),A9(0.0125490196078),A9(0.0133333333333),A9(0.0141176470588),A9(0.0149019607843),A9(0.0156862745098),A9(0.0164705882353),A9(0.0172549019608),A9(0.0180392156863),A8(0.0188235294118),A9(0.0196078431373),A8(0.0203921568627),A8(0.0211764705882),A9(0.0219607843137),A9(0.0227450980392),A9(0.0235294117647),A9(0.0243137254902),A9(0.0250980392157),A9(0.0258823529412),A9(0.0266666666667),A8(0.0274509803922),A9(0.0282352941176),A10(0.0290196078431),A10(0.0298039215686),A9(0.0305882352941),A9(0.0313725490196),A9(0.0321568627451),A10(0.0329411764706),A8(0.0337254901961),A8(0.0345098039216),A10(0.0352941176471),A9(0.0360784313725),A10(0.036862745098),A9(0.0376470588235),A9(0.038431372549),A8(0.0392156862745)
A19 -> A19(0.00105708245243),A19(0.00211416490486),A19(0.00317124735729),A19(0.00422832980973),A19(0.00528541226216),A19(0.00634249471459),A19(0.00739957716702),A19(0.00845665961945),A19(0.00951374207188),A20(0.0105708245243),A19(0.0116279069767),A19(0.0126849894292),A19(0.0137420718816),A19(0.014799154334),A20(0.0158562367865),A21(0.0169133192389),A19(0.0179704016913),A19(0.0190274841438),A20(0.0200845665962),A20(0.0211416490486),A18(0.0221987315011),A18(0.0232558139535),A18(0.0243128964059),A18(0.0253699788584),A19(0.0264270613108),A19(0.0274841437632),A18(0.0285412262156),A19(0.0295983086681),A20(0.0306553911205),A20(0.0317124735729),A19(0.0327695560254),A19(0.0338266384778),A19(0.0348837209302),A20(0.0359408033827),A19(0.0369978858351),A18(0.0380549682875),A19(0.03911205074),A19(0.0401691331924),A20(0.0412262156448),A19(0.0422832980973),A18(0.0433403805497),A19(0.0443974630021),A20(0.0454545454545)
A17 -> A17(0.0010101010101),A17(0.0020202020202),A17(0.0030303030303),A17(0.0040404040404),A18(0.00505050505051),A17(0.00606060606061),A18(0.00707070707071),A17(0.00808080808081),A17(0.00909090909091),A17(0.010101010101),A17(0.0111111111111),A17(0.0121212121212),A17(0.0131313131313),A18(0.0141414141414),A17(0.0151515151515),A18(0.0161616161616),A17(0.0171717171717),A17(0.0181818181818),A15(0.0191919191919),A18(0.020202020202),A17(0.0212121212121),A18(0.0222222222222),A15(0.0232323232323),A18(0.0242424242424),A17(0.0252525252525),A18(0.0262626262626),A17(0.0272727272727),A17(0.0282828282828),A18(0.0292929292929),A17(0.030303030303),A17(0.0313131313131),A17(0.0323232323232),A16(0.0333333333333),A17(0.0343434343434),A17(0.0353535353535),A16(0.0363636363636),A17(0.0373737373737),A17(0.0383838383838),A18(0.0393939393939),A17(0.040404040404),A18(0.0414141414141),A16(0.0424242424242),A17(0.0434343434343),A16(0.0444444444444)
A24 -> A24(0.000255362614913),A24(0.000510725229826),A24(0.00076608784474),A24(0.00102145045965),A25(0.00127681307457),A23(0.00153217568948),A24(0.00178753830439),A24(0.00204290091931),A24(0.00229826353422),A25(0.00255362614913),A23(0.00280898876404),A24(0.00306435137896),A24(0.00331971399387),A24(0.00357507660878),A24(0.0038304392237),A24(0.00408580183861),A23(0.00434116445352),A24(0.00459652706844),A24(0.00485188968335),A25(0.00510725229826),A24(0.00536261491318),A24(0.00561797752809),A24(0.005873340143),A24(0.00612870275792),A24(0.00638406537283),A25(0.00663942798774),A23(0.00689479060266),A23(0.00715015321757),A25(0.00740551583248),A24(0.0076608784474),A24(0.00791624106231),A23(0.00817160367722),A24(0.00842696629213),A24(0.00868232890705),A25(0.00893769152196),A23(0.00919305413687),A24(0.00944841675179),A25(0.0097037793667),A24(0.00995914198161),A24(0.0102145045965),A25(0.0104698672114),A24(0.0107252298264),A23(0.0109805924413),A23(0.0112359550562),A24(0.0114913176711),A24(0.011746680286),A23(0.0120020429009),A23(0.0122574055158),A23(0.0125127681307),A23(0.0127681307457),A24(0.0130234933606),A23(0.0132788559755),A24(0.0135342185904),A24(0.0137895812053),A24(0.0140449438202),A24(0.0143003064351),A24(0.0145556690501),A24(0.014811031665),A24(0.0150663942799),A25(0.0153217568948),A24(0.0155771195097),A24(0.0158324821246),A23(0.0160878447395),A25(0.0163432073544),A24(0.0165985699694),A23(0.0168539325843),A24(0.0171092951992),A23(0.0173646578141),A24(0.017620020429),A24(0.0178753830439),A25(0.0181307456588),A25(0.0183861082737),A25(0.0186414708887),A24(0.0188968335036),A24(0.0191521961185),A25(0.0194075587334),A24(0.0196629213483),A24(0.0199182839632),A24(0.0201736465781),A23(0.0204290091931),A24(0.020684371808),A23(0.0209397344229),A24(0.0211950970378),A23(0.0214504596527),A25(0.0217058222676),A24(0.0219611848825),A24(0.0222165474974),A23(0.0224719101124)
A7 -> A7(0.0026455026455),A7(0.00529100529101),A6(0.00793650793651),A7(0.010582010582),A7(0.0132275132275),A8(0.015873015873),A7(0.0185185185185),A7(0.021164021164),A7(0.0238095238095),A7(0.026455026455),A7(0.0291005291005),A7(0.031746031746),A6(0.0343915343915),A9(0.037037037037),A7(0.0396825396825),A8(0.042328042328),A6(0.0449735449735),A7(0.047619047619),A7(0.0502645502646),A7(0.0529100529101),A8(0.0555555555556),A8(0.0582010582011),A8(0.0608465608466),A7(0.0634920634921),A7(0.0661375661376),A7(0.0687830687831),A6(0.0714285714286)
A25 -> A25(0.000341763499658),A25(0.000683526999316),A25(0.00102529049897),A25(0.00136705399863),A25(0.00170881749829),A26(0.00205058099795),A25(0.00239234449761),A24(0.00273410799727),A25(0.00307587149692),A26(0.00341763499658),A26(0.00375939849624),A25(0.0041011619959),A25(0.00444292549556),A25(0.00478468899522),A25(0.00512645249487),A26(0.00546821599453),A25(0.00580997949419),A24(0.00615174299385),A24(0.00649350649351),A25(0.00683526999316),A25(0.00717703349282),A25(0.00751879699248),A25(0.00786056049214),A25(0.0082023239918),A25(0.00854408749146),A25(0.00888585099111),A25(0.00922761449077),A26(0.00956937799043),A25(0.00991114149009),A26(0.0102529049897),A24(0.0105946684894),A26(0.0109364319891),A25(0.0112781954887),A25(0.0116199589884),A25(0.011961722488),A25(0.0123034859877),A25(0.0126452494874),A24(0.012987012987),A24(0.0133287764867),A26(0.0136705399863),A26(0.014012303486),A25(0.0143540669856),A25(0.0146958304853),A25(0.015037593985),A25(0.0153793574846),A25(0.0157211209843),A25(0.0160628844839),A25(0.0164046479836),A25(0.0167464114833),A25(0.0170881749829),A24(0.0174299384826),A25(0.0177717019822),A25(0.0181134654819),A25(0.0184552289815),A25(0.0187969924812),A24(0.0191387559809),A26(0.0194805194805),A25(0.0198222829802),A26(0.0201640464798),A24(0.0205058099795),A25(0.0208475734792),A24(0.0211893369788),A24(0.0215311004785),A26(0.0218728639781),A26(0.0222146274778),A25(0.0225563909774),A24(0.0228981544771),A24(0.0232399179768),A25(0.0235816814764),A25(0.0239234449761),A24(0.0242652084757),A26(0.0246069719754),A25(0.0249487354751),A24(0.0252904989747),A25(0.0256322624744),A24(0.025974025974)
A30 -> A30(0.0026455026455),A30(0.00529100529101),A31(0.00793650793651),A30(0.010582010582),A30(0.0132275132275),A29(0.015873015873),A29(0.0185185185185),A28(0.021164021164),A30(0.0238095238095),A29(0.026455026455),A29(0.0291005291005),A30(0.031746031746),A30(0.0343915343915),A30(0.037037037037),A29(0.0396825396825),A30(0.042328042328),A30(0.0449735449735),A30(0.047619047619),A29(0.0502645502646),A29(0.0529100529101),A30(0.0555555555556),A30(0.0582010582011),A29(0.0608465608466),A31(0.0634920634921),A30(0.0661375661376),A29(0.0687830687831),A28(0.0714285714286)
A21 -> A21(0.000402414486922),A21(0.000804828973843),A21(0.00120724346076),A22(0.00160965794769),A22(0.00201207243461),A22(0.00241448692153),A23(0.00281690140845),A21(0.00321931589537),A21(0.00362173038229),A22(0.00402414486922),A22(0.00442655935614),A21(0.00482897384306),A22(0.00523138832998),A22(0.0056338028169),A21(0.00603621730382),A21(0.00643863179074),A21(0.00684104627767),A20(0.00724346076459),A22(0.00764587525151),A21(0.00804828973843),A22(0.00845070422535),A21(0.00885311871227),A21(0.0092555331992),A21(0.00965794768612),A20(0.010060362173),A19(0.01046277666),A22(0.0108651911469),A21(0.0112676056338),A21(0.0116700201207),A21(0.0120724346076),A21(0.0124748490946),A21(0.0128772635815),A21(0.0132796780684),A20(0.0136820925553),A21(0.0140845070423),A21(0.0144869215292),A21(0.0148893360161),A21(0.015291750503),A21(0.0156941649899),A21(0.0160965794769),A21(0.0164989939638),A21(0.0169014084507),A22(0.0173038229376),A21(0.0177062374245),A22(0.0181086519115),A21(0.0185110663984),A20(0.0189134808853),A20(0.0193158953722),A21(0.0197183098592),A21(0.0201207243461),A22(0.020523138833),A21(0.0209255533199),A20(0.0213279678068),A23(0.0217303822938),A21(0.0221327967807),A22(0.0225352112676),A21(0.0229376257545),A21(0.0233400402414),A21(0.0237424547284),A22(0.0241448692153),A22(0.0245472837022),A21(0.0249496981891),A20(0.0253521126761),A21(0.025754527163),A21(0.0261569416499),A21(0.0265593561368),A22(0.0269617706237),A21(0.0273641851107),A22(0.0277665995976),A20(0.0281690140845)
A2 -> A2(0.010989010989),A1(0.021978021978),A2(0.032967032967),A1(0.043956043956),A2(0.0549450549451),A2(0.0659340659341),A2(0.0769230769231),A2(0.0879120879121),A2(0.0989010989011),A3(0.10989010989),A2(0.120879120879),A2(0.131868131868),A3(0.142857142857)
A18 -> A18(0.000380517503805),A18(0.00076103500761),A18(0.00114155251142),A17(0.00152207001522),A18(0.00190258751903),A18(0.00228310502283),A18(0.00266362252664),A17(0.00304414003044),A18(0.00342465753425),A18(0.00380517503805),A18(0.00418569254186),A18(0.00456621004566),A18(0.00494672754947),A18(0.00532724505327),A18(0.00570776255708),A18(0.00608828006088),A18(0.00646879756469),A18(0.00684931506849),A18(0.0072298325723),A18(0.0076103500761),A18(0.00799086757991),A17(0.00837138508371),A18(0.00875190258752),A19(0.00913242009132),A18(0.00951293759513),A18(0.00989345509893),A17(0.0102739726027),A18(0.0106544901065),A17(0.0110350076104),A18(0.0114155251142),A18(0.011796042618),A18(0.0121765601218),A18(0.0125570776256),A19(0.0129375951294),A18(0.0133181126332),A18(0.013698630137),A18(0.0140791476408),A18(0.0144596651446),A18(0.0148401826484),A18(0.0152207001522),A17(0.015601217656),A18(0.0159817351598),A18(0.0163622526636),A17(0.0167427701674),A18(0.0171232876712),A18(0.017503805175),A18(0.0178843226788),A19(0.0182648401826),A19(0.0186453576865),A18(0.0190258751903),A19(0.0194063926941),A18(0.0197869101979),A18(0.0201674277017),A18(0.0205479452055),A17(0.0209284627093),A19(0.0213089802131),A18(0.0216894977169),A17(0.0220700152207),A18(0.0224505327245),A18(0.0228310502283),A18(0.0232115677321),A18(0.0235920852359),A18(0.0239726027397),A18(0.0243531202435),A18(0.0247336377473),A18(0.0251141552511),A18(0.0254946727549),A19(0.0258751902588),A18(0.0262557077626),A19(0.0266362252664),A17(0.0270167427702),A17(0.027397260274)
A12 -> A11(0.000546448087432),A12(0.00109289617486),A12(0.0016393442623),A14(0.00218579234973),A11(0.00273224043716),A11(0.00327868852459),A13(0.00382513661202),A11(0.00437158469945),A13(0.00491803278689),A12(0.00546448087432),A12(0.00601092896175),A11(0.00655737704918),A12(0.00710382513661),A12(0.00765027322404),A11(0.00819672131148),A12(0.00874316939891),A12(0.00928961748634),A12(0.00983606557377),A13(0.0103825136612),A12(0.0109289617486),A12(0.0114754098361),A12(0.0120218579235),A11(0.0125683060109),A12(0.0131147540984),A11(0.0136612021858),A12(0.0142076502732),A11(0.0147540983607),A12(0.0153005464481),A13(0.0158469945355),A12(0.016393442623),A12(0.0169398907104),A12(0.0174863387978),A10(0.0180327868852),A12(0.0185792349727),A12(0.0191256830601),A12(0.0196721311475),A12(0.020218579235),A11(0.0207650273224),A12(0.0213114754098),A12(0.0218579234973),A13(0.0224043715847),A12(0.0229508196721),A13(0.0234972677596),A12(0.024043715847),A13(0.0245901639344),A12(0.0251366120219),A11(0.0256830601093),A13(0.0262295081967),A12(0.0267759562842),A11(0.0273224043716),A12(0.027868852459),A12(0.0284153005464),A12(0.0289617486339),A12(0.0295081967213),A12(0.0300546448087),A12(0.0306010928962),A12(0.0311475409836),A11(0.031693989071),A11(0.0322404371585),A11(0.0327868852459)
A34 -> A34(0.00246305418719),A34(0.00492610837438),A34(0.00738916256158),A34(0.00985221674877),A34(0.012315270936),A34(0.0147783251232),A33(0.0172413793103),A33(0.0197044334975),A34(0.0221674876847),A34(0.0246305418719),A34(0.0270935960591),A34(0.0295566502463),A33(0.0320197044335),A34(0.0344827586207),A34(0.0369458128079),A34(0.0394088669951),A33(0.0418719211823),A34(0.0443349753695),A34(0.0467980295567),A34(0.0492610837438),A33(0.051724137931),A33(0.0541871921182),A34(0.0566502463054),A34(0.0591133004926),A34(0.0615763546798),A34(0.064039408867),A34(0.0665024630542),A32(0.0689655172414)
A4 -> A4(0.00833333333333),A4(0.0166666666667),A4(0.025),A3(0.0333333333333),A5(0.0416666666667),A5(0.05),A4(0.0583333333333),A4(0.0666666666667),A2(0.075),A3(0.0833333333333),A4(0.0916666666667),A5(0.1),A4(0.108333333333),A4(0.116666666667),A4(0.125)
A27 -> A27(0.000649350649351),A26(0.0012987012987),A27(0.00194805194805),A26(0.0025974025974),A27(0.00324675324675),A27(0.0038961038961),A27(0.00454545454545),A27(0.00519480519481),A26(0.00584415584416),A27(0.00649350649351),A27(0.00714285714286),A27(0.00779220779221),A28(0.00844155844156),A27(0.00909090909091),A27(0.00974025974026),A27(0.0103896103896),A26(0.011038961039),A27(0.0116883116883),A27(0.0123376623377),A27(0.012987012987),A27(0.0136363636364),A28(0.0142857142857),A27(0.0149350649351),A28(0.0155844155844),A28(0.0162337662338),A27(0.0168831168831),A27(0.0175324675325),A26(0.0181818181818),A27(0.0188311688312),A26(0.0194805194805),A26(0.0201298701299),A26(0.0207792207792),A27(0.0214285714286),A28(0.0220779220779),A27(0.0227272727273),A26(0.0233766233766),A26(0.024025974026),A29(0.0246753246753),A26(0.0253246753247),A27(0.025974025974),A26(0.0266233766234),A27(0.0272727272727),A27(0.0279220779221),A25(0.0285714285714),A29(0.0292207792208),A26(0.0298701298701),A27(0.0305194805195),A28(0.0311688311688),A27(0.0318181818182),A27(0.0324675324675),A27(0.0331168831169),A27(0.0337662337662),A27(0.0344155844156),A26(0.0350649350649),A26(0.0357142857143)
A15 -> A15(0.000308641975309),A15(0.000617283950617),A15(0.000925925925926),A15(0.00123456790123),A15(0.00154320987654),A15(0.00185185185185),A15(0.00216049382716),A15(0.00246913580247),A15(0.00277777777778),A15(0.00308641975309),A16(0.0033950617284),A16(0.0037037037037),A15(0.00401234567901),A15(0.00432098765432),A15(0.00462962962963),A14(0.00493827160494),A15(0.00524691358025),A15(0.00555555555556),A15(0.00586419753086),A15(0.00617283950617),A15(0.00648148148148),A15(0.00679012345679),A15(0.0070987654321),A14(0.00740740740741),A15(0.00771604938272),A15(0.00802469135802),A15(0.00833333333333),A15(0.00864197530864),A14(0.00895061728395),A15(0.00925925925926),A15(0.00956790123457),A15(0.00987654320988),A15(0.0101851851852),A16(0.0104938271605),A15(0.0108024691358),A16(0.0111111111111),A15(0.0114197530864),A15(0.0117283950617),A15(0.012037037037),A15(0.0123456790123),A15(0.0126543209877),A15(0.012962962963),A15(0.0132716049383),A15(0.0135802469136),A16(0.0138888888889),A15(0.0141975308642),A15(0.0145061728395),A15(0.0148148148148),A17(0.0151234567901),A16(0.0154320987654),A15(0.0157407407407),A15(0.016049382716),A15(0.0163580246914),A15(0.0166666666667),A15(0.016975308642),A15(0.0172839506173),A15(0.0175925925926),A15(0.0179012345679),A15(0.0182098765432),A15(0.0185185185185),A15(0.0188271604938),A14(0.0191358024691),A14(0.0194444444444),A14(0.0197530864198),A15(0.0200617283951),A15(0.0203703703704),A15(0.0206790123457),A15(0.020987654321),A15(0.0212962962963),A16(0.0216049382716),A16(0.0219135802469),A14(0.0222222222222),A15(0.0225308641975),A15(0.0228395061728),A15(0.0231481481481),A15(0.0234567901235),A15(0.0237654320988),A15(0.0240740740741),A15(0.0243827160494),A14(0.0246913580247)
A5 -> A5(0.00121951219512),A4(0.00243902439024),A4(0.00365853658537),A5(0.00487804878049),A5(0.00609756097561),A5(0.00731707317073),A5(0.00853658536585),A5(0.00975609756098),A5(0.0109756097561),A5(0.0121951219512),A5(0.0134146341463),A6(0.0146341463415),A5(0.0158536585366),A5(0.0170731707317),A5(0.0182926829268),A5(0.019512195122),A5(0.0207317073171),A6(0.0219512195122),A5(0.0231707317073),A5(0.0243902439024),A5(0.0256097560976),A5(0.0268292682927),A4(0.0280487804878),A5(0.0292682926829),A5(0.030487804878),A5(0.0317073170732),A5(0.0329268292683),A5(0.0341463414634),A5(0.0353658536585),A6(0.0365853658537),A5(0.0378048780488),A5(0.0390243902439),A6(0.040243902439),A5(0.0414634146341),A6(0.0426829268293),A6(0.0439024390244),A5(0.0451219512195),A5(0.0463414634146),A5(0.0475609756098),A4(0.0487804878049)
A26 -> A26(0.00062656641604),A26(0.00125313283208),A25(0.00187969924812),A26(0.00250626566416),A26(0.0031328320802),A27(0.00375939849624),A26(0.00438596491228),A27(0.00501253132832),A26(0.00563909774436),A25(0.0062656641604),A26(0.00689223057644),A26(0.00751879699248),A27(0.00814536340852),A25(0.00877192982456),A25(0.0093984962406),A27(0.0100250626566),A26(0.0106516290727),A25(0.0112781954887),A26(0.0119047619048),A26(0.0125313283208),A25(0.0131578947368),A26(0.0137844611529),A25(0.0144110275689),A26(0.015037593985),A26(0.015664160401),A27(0.016290726817),A26(0.0169172932331),A27(0.0175438596491),A25(0.0181704260652),A25(0.0187969924812),A26(0.0194235588972),A26(0.0200501253133),A26(0.0206766917293),A25(0.0213032581454),A26(0.0219298245614),A26(0.0225563909774),A27(0.0231829573935),A26(0.0238095238095),A26(0.0244360902256),A27(0.0250626566416),A25(0.0256892230576),A27(0.0263157894737),A27(0.0269423558897),A27(0.0275689223058),A27(0.0281954887218),A26(0.0288220551378),A26(0.0294486215539),A27(0.0300751879699),A26(0.030701754386),A27(0.031328320802),A26(0.031954887218),A26(0.0325814536341),A27(0.0332080200501),A25(0.0338345864662),A27(0.0344611528822),A25(0.0350877192982)
A33 -> A32(0.00735294117647),A34(0.0147058823529),A33(0.0220588235294),A33(0.0294117647059),A34(0.0367647058824),A32(0.0441176470588),A33(0.0514705882353),A33(0.0588235294118),A34(0.0661764705882),A32(0.0735294117647),A34(0.0808823529412),A34(0.0882352941176),A32(0.0955882352941),A33(0.102941176471),A34(0.110294117647),A34(0.117647058824)
A16 -> A16(0.000546448087432),A16(0.00109289617486),A16(0.0016393442623),A15(0.00218579234973),A15(0.00273224043716),A15(0.00327868852459),A16(0.00382513661202),A16(0.00437158469945),A16(0.00491803278689),A16(0.00546448087432),A16(0.00601092896175),A16(0.00655737704918),A16(0.00710382513661),A16(0.00765027322404),A16(0.00819672131148),A16(0.00874316939891),A16(0.00928961748634),A16(0.00983606557377),A16(0.0103825136612),A16(0.0109289617486),A16(0.0114754098361),A16(0.0120218579235),A16(0.0125683060109),A16(0.0131147540984),A16(0.0136612021858),A16(0.0142076502732),A16(0.0147540983607),A16(0.0153005464481),A16(0.0158469945355),A16(0.016393442623),A16(0.0169398907104),A16(0.0174863387978),A15(0.0180327868852),A16(0.0185792349727),A16(0.0191256830601),A16(0.0196721311475),A16(0.020218579235),A16(0.0207650273224),A16(0.0213114754098),A16(0.0218579234973),A16(0.0224043715847),A16(0.0229508196721),A16(0.0234972677596),A16(0.024043715847),A16(0.0245901639344),A17(0.0251366120219),A16(0.0256830601093),A17(0.0262295081967),A17(0.0267759562842),A16(0.0273224043716),A16(0.027868852459),A16(0.0284153005464),A14(0.0289617486339),A16(0.0295081967213),A16(0.0300546448087),A15(0.0306010928962),A17(0.0311475409836),A16(0.031693989071),A17(0.0322404371585),A14(0.0327868852459)
A28 -> A28(0.00128205128205),A28(0.0025641025641),A28(0.00384615384615),A28(0.00512820512821),A28(0.00641025641026),A28(0.00769230769231),A29(0.00897435897436),A29(0.0102564102564),A28(0.0115384615385),A27(0.0128205128205),A29(0.0141025641026),A27(0.0153846153846),A28(0.0166666666667),A28(0.0179487179487),A29(0.0192307692308),A28(0.0205128205128),A28(0.0217948717949),A28(0.0230769230769),A28(0.024358974359),A28(0.025641025641),A29(0.0269230769231),A28(0.0282051282051),A28(0.0294871794872),A28(0.0307692307692),A27(0.0320512820513),A28(0.0333333333333),A29(0.0346153846154),A30(0.0358974358974),A28(0.0371794871795),A27(0.0384615384615),A27(0.0397435897436),A28(0.0410256410256),A28(0.0423076923077),A28(0.0435897435897),A29(0.0448717948718),A28(0.0461538461538),A28(0.0474358974359),A28(0.0487179487179),A27(0.05)
A22 -> A21(0.000261233019854),A22(0.000522466039707),A22(0.000783699059561),A22(0.00104493207941),A23(0.00130616509927),A23(0.00156739811912),A22(0.00182863113898),A22(0.00208986415883),A22(0.00235109717868),A20(0.00261233019854),A24(0.00287356321839),A22(0.00313479623824),A21(0.0033960292581),A22(0.00365726227795),A22(0.00391849529781),A22(0.00417972831766),A22(0.00444096133751),A22(0.00470219435737),A22(0.00496342737722),A22(0.00522466039707),A23(0.00548589341693),A23(0.00574712643678),A21(0.00600835945664),A22(0.00626959247649),A23(0.00653082549634),A21(0.0067920585162),A21(0.00705329153605),A22(0.0073145245559),A22(0.00757575757576),A22(0.00783699059561),A22(0.00809822361546),A22(0.00835945663532),A22(0.00862068965517),A21(0.00888192267503),A22(0.00914315569488),A23(0.00940438871473),A22(0.00966562173459),A22(0.00992685475444),A22(0.0101880877743),A21(0.0104493207941),A21(0.010710553814),A21(0.0109717868339),A22(0.0112330198537),A21(0.0114942528736),A23(0.0117554858934),A20(0.0120167189133),A22(0.0122779519331),A22(0.012539184953),A22(0.0128004179728),A22(0.0130616509927),A21(0.0133228840125),A21(0.0135841170324),A22(0.0138453500522),A22(0.0141065830721),A22(0.014367816092),A21(0.0146290491118),A23(0.0148902821317),A22(0.0151515151515),A22(0.0154127481714),A22(0.0156739811912),A21(0.0159352142111),A22(0.0161964472309),A22(0.0164576802508),A22(0.0167189132706),A22(0.0169801462905),A23(0.0172413793103),A22(0.0175026123302),A21(0.0177638453501),A22(0.0180250783699),A22(0.0182863113898),A24(0.0185475444096),A22(0.0188087774295),A22(0.0190700104493),A22(0.0193312434692),A23(0.019592476489),A22(0.0198537095089),A23(0.0201149425287),A22(0.0203761755486),A22(0.0206374085684),A23(0.0208986415883),A22(0.0211598746082),A23(0.021421107628),A22(0.0216823406479),A21(0.0219435736677),A22(0.0222048066876),A22(0.0224660397074),A21(0.0227272727273)
A23 -> A23(0.000350877192982),A23(0.000701754385965),A22(0.00105263157895),A23(0.00140350877193),A23(0.00175438596491),A23(0.00210526315789),A24(0.00245614035088),A23(0.00280701754386),A24(0.00315789473684),A24(0.00350877192982),A24(0.00385964912281),A20(0.00421052631579),A22(0.00456140350877),A22(0.00491228070175),A20(0.00526315789474),A24(0.00561403508772),A24(0.0059649122807),A23(0.00631578947368),A23(0.00666666666667),A22(0.00701754385965),A23(0.00736842105263),A23(0.00771929824561),A24(0.0080701754386),A22(0.00842105263158),A23(0.00877192982456),A23(0.00912280701754),A24(0.00947368421053),A23(0.00982456140351),A23(0.0101754385965),A23(0.0105263157895),A23(0.0108771929825),A24(0.0112280701754),A23(0.0115789473684),A23(0.0119298245614),A23(0.0122807017544),A23(0.0126315789474),A22(0.0129824561404),A23(0.0133333333333),A24(0.0136842105263),A23(0.0140350877193),A24(0.0143859649123),A25(0.0147368421053),A22(0.0150877192982),A24(0.0154385964912),A24(0.0157894736842),A23(0.0161403508772),A24(0.0164912280702),A23(0.0168421052632),A23(0.0171929824561),A22(0.0175438596491),A23(0.0178947368421),A23(0.0182456140351),A22(0.0185964912281),A22(0.0189473684211),A23(0.019298245614),A22(0.019649122807),A23(0.02),A23(0.020350877193),A23(0.020701754386),A23(0.0210526315789),A22(0.0214035087719),A23(0.0217543859649),A23(0.0221052631579),A22(0.0224561403509),A24(0.0228070175439),A23(0.0231578947368),A24(0.0235087719298),A23(0.0238596491228),A23(0.0242105263158),A22(0.0245614035088),A24(0.0249122807018),A23(0.0252631578947),A23(0.0256140350877),A24(0.0259649122807),A22(0.0263157894737)
A20 -> A20(0.00062656641604),A20(0.00125313283208),A20(0.00187969924812),A19(0.00250626566416),A20(0.0031328320802),A20(0.00375939849624),A20(0.00438596491228),A21(0.00501253132832),A21(0.00563909774436),A20(0.0062656641604),A19(0.00689223057644),A21(0.00751879699248),A19(0.00814536340852),A21(0.00877192982456),A20(0.0093984962406),A20(0.0100250626566),A20(0.0106516290727),A20(0.0112781954887),A20(0.0119047619048),A19(0.0125313283208),A20(0.0131578947368),A19(0.0137844611529),A20(0.0144110275689),A20(0.015037593985),A21(0.015664160401),A20(0.016290726817),A20(0.0169172932331),A19(0.0175438596491),A20(0.0181704260652),A19(0.0187969924812),A20(0.0194235588972),A20(0.0200501253133),A20(0.0206766917293),A20(0.0213032581454),A20(0.0219298245614),A21(0.0225563909774),A20(0.0231829573935),A20(0.0238095238095),A21(0.0244360902256),A21(0.0250626566416),A20(0.0256892230576),A20(0.0263157894737),A21(0.0269423558897),A22(0.0275689223058),A20(0.0281954887218),A20(0.0288220551378),A19(0.0294486215539),A20(0.0300751879699),A21(0.030701754386),A20(0.031328320802),A21(0.031954887218),A20(0.0325814536341),A20(0.0332080200501),A20(0.0338345864662),A20(0.0344611528822),A18(0.0350877192982)
A29 -> A29(0.000925069380204),A29(0.00185013876041),A29(0.00277520814061),A30(0.00370027752081),A30(0.00462534690102),A30(0.00555041628122),A29(0.00647548566142),A30(0.00740055504163),A29(0.00832562442183),A29(0.00925069380204),A27(0.0101757631822),A29(0.0111008325624),A29(0.0120259019426),A29(0.0129509713228),A30(0.0138760407031),A30(0.0148011100833),A28(0.0157261794635),A29(0.0166512488437),A29(0.0175763182239),A29(0.0185013876041),A29(0.0194264569843),A29(0.0203515263645),A28(0.0212765957447),A29(0.0222016651249),A29(0.0231267345051),A29(0.0240518038853),A29(0.0249768732655),A29(0.0259019426457),A29(0.0268270120259),A30(0.0277520814061),A28(0.0286771507863),A29(0.0296022201665),A29(0.0305272895467),A30(0.0314523589269),A30(0.0323774283071),A30(0.0333024976873),A27(0.0342275670675),A31(0.0351526364477),A30(0.0360777058279),A29(0.0370027752081),A29(0.0379278445883),A28(0.0388529139685),A29(0.0397779833488),A29(0.040703052729),A29(0.0416281221092),A28(0.0425531914894)
A13 -> A13(0.000649350649351),A13(0.0012987012987),A13(0.00194805194805),A13(0.0025974025974),A13(0.00324675324675),A13(0.0038961038961),A14(0.00454545454545),A13(0.00519480519481),A14(0.00584415584416),A13(0.00649350649351),A14(0.00714285714286),A14(0.00779220779221),A14(0.00844155844156),A13(0.00909090909091),A12(0.00974025974026),A13(0.0103896103896),A13(0.011038961039),A14(0.0116883116883),A12(0.0123376623377),A13(0.012987012987),A13(0.0136363636364),A11(0.0142857142857),A13(0.0149350649351),A13(0.0155844155844),A12(0.0162337662338),A13(0.0168831168831),A13(0.0175324675325),A13(0.0181818181818),A13(0.0188311688312),A12(0.0194805194805),A13(0.0201298701299),A13(0.0207792207792),A14(0.0214285714286),A13(0.0220779220779),A13(0.0227272727273),A12(0.0233766233766),A12(0.024025974026),A13(0.0246753246753),A13(0.0253246753247),A12(0.025974025974),A12(0.0266233766234),A13(0.0272727272727),A13(0.0279220779221),A12(0.0285714285714),A13(0.0292207792208),A14(0.0298701298701),A14(0.0305194805195),A13(0.0311688311688),A13(0.0318181818182),A13(0.0324675324675),A13(0.0331168831169),A13(0.0337662337662),A14(0.0344155844156),A14(0.0350649350649),A12(0.0357142857143)
A11 -> A11(0.000480769230769),A11(0.000961538461538),A12(0.00144230769231),A12(0.00192307692308),A11(0.00240384615385),A9(0.00288461538462),A12(0.00336538461538),A11(0.00384615384615),A10(0.00432692307692),A12(0.00480769230769),A12(0.00528846153846),A9(0.00576923076923),A12(0.00625),A13(0.00673076923077),A11(0.00721153846154),A11(0.00769230769231),A11(0.00817307692308),A12(0.00865384615385),A11(0.00913461538462),A11(0.00961538461538),A11(0.0100961538462),A11(0.0105769230769),A12(0.0110576923077),A11(0.0115384615385),A11(0.0120192307692),A12(0.0125),A10(0.0129807692308),A11(0.0134615384615),A10(0.0139423076923),A11(0.0144230769231),A11(0.0149038461538),A11(0.0153846153846),A11(0.0158653846154),A11(0.0163461538462),A10(0.0168269230769),A10(0.0173076923077),A11(0.0177884615385),A11(0.0182692307692),A11(0.01875),A12(0.0192307692308),A11(0.0197115384615),A11(0.0201923076923),A10(0.0206730769231),A11(0.0211538461538),A12(0.0216346153846),A11(0.0221153846154),A11(0.0225961538462),A11(0.0230769230769),A11(0.0235576923077),A12(0.0240384615385),A12(0.0245192307692),A10(0.025),A11(0.0254807692308),A11(0.0259615384615),A12(0.0264423076923),A12(0.0269230769231),A11(0.0274038461538),A10(0.0278846153846),A11(0.0283653846154),A10(0.0288461538462),A11(0.0293269230769),A11(0.0298076923077),A11(0.0302884615385),A10(0.0307692307692)
A31 -> A31(0.00584795321637),A31(0.0116959064327),A32(0.0175438596491),A32(0.0233918128655),A31(0.0292397660819),A30(0.0350877192982),A31(0.0409356725146),A31(0.046783625731),A32(0.0526315789474),A31(0.0584795321637),A32(0.0643274853801),A31(0.0701754385965),A31(0.0760233918129),A31(0.0818713450292),A32(0.0877192982456),A31(0.093567251462),A32(0.0994152046784),A28(0.105263157895)


In [35]:
plotCompared(taiexsample,[wfts2p,wftsd2p],["Normal","Diferenças"],'')
taiex_modelbase_fo.append({"name":"WFTS","model":wfts2,"predicted":wfts2p})
taiex_modelbase_fo.append({"name":"WFTS Dif.","model":wftsd2,"predicted":wftsd2p})


Improved Weighted Fuzzy Time Series

Os trabalhos de \cite{ismail2011enrollment} e \cite{efendi2013improved} modificam a forma como os pesos são assinalados às regras no modelo de \cite{yu2005weighted}. A diferença mais importante é que a quantidade de recorrências de cada regra é que vai determinar o seu peso, para uma regra $A_i \rightarrow A_j,A_k$, tendo $A_i \rightarrow A_j$ $n_1$ recorrências e $A_i \rightarrow A_k$ $n_2$ recorrências, o valor de cada peso será $w_k = n_k / \sum_{i=1..n} n_i$, sendo $n$ o número de regras.

IWFTS - Código Fonte


In [36]:
class ImprovedWeightedFLRG:
	def __init__(self,premiss):
		self.premiss = premiss
		self.consequent = {}
		self.count = 0.0

	def append(self,c):
		if c not in self.consequent:
			self.consequent[c] = 1.0
		else:
			self.consequent[c] = self.consequent[c] + 1.0
		self.count = self.count + 1.0

	def weights(self):
		return np.array([ self.consequent[c]/self.count for c in self.consequent.keys() ])
        
	def __str__(self):
		tmp = self.premiss + " -> "
		tmp2 = ""
		for c in self.consequent.keys():
			if len(tmp2) > 0:
				tmp2 = tmp2 + ","
			tmp2 = tmp2 + c + "(" + str(self.consequent[c]/self.count) + ")"
		return tmp + tmp2

In [37]:
class ImprovedWeightedFTS(FTS):
	def __init__(self,name):
		super(ImprovedWeightedFTS, self).__init__(1,name)
        
	def defuzzy(self,data):
		actual = self.fuzzy(data)
		if actual["fuzzyset"] not in self.flrgs:
			return self.sets[actual["fuzzyset"]].centroid
		flrg = self.flrgs[actual["fuzzyset"]]
		mi = np.array([self.sets[s].centroid for s in flrg.consequent.keys()])
		return mi.dot( flrg.weights() )
        
	def learn(self, data, sets):
		last = {"fuzzyset":"", "membership":0.0}
		actual = {"fuzzyset":"", "membership":0.0}
		
		for s in sets:
			self.sets[s.name] = s
		
		self.flrgs = {}
		count = 1
		for inst in data:
			actual = self.fuzzy(inst)
			
			if count > self.order:
				if last["fuzzyset"] not in self.flrgs:
					self.flrgs[last["fuzzyset"]] = ImprovedWeightedFLRG(last["fuzzyset"])
			
				self.flrgs[last["fuzzyset"]].append(actual["fuzzyset"])    
			count = count + 1
			last = actual

IWFTS - Experimento com o dataset Enrollments


In [38]:
#fts = ImprovedWeightedFTS()
#sets = GridPartitionerTrimf(enrollments["Enrollments"],8)
#fts.learn(enrollments["Enrollments"],sets)

iwfts1,iwfts1p,iwftsd1,iwftsd1p = SelecaoSimples_MenorRMSE(enrollments,[6,8,10,12,14], ImprovedWeightedFTS)


Série Original
6 1223.85830842
8 1483.3701904
10 422.250747348
12 570.537792052
14 482.697281037

Série Diferencial
6 484.842445186
8 399.931984881
10 405.181426862
12 382.097267165
14 498.167600324

In [39]:
print(iwfts1)


10 particoes:
A0 -> A1(1.0)
A6 -> A6(0.3333333333333333),A5(0.3333333333333333),A8(0.3333333333333333)
A5 -> A4(0.5),A6(0.5)
A3 -> A4(0.3333333333333333),A5(0.3333333333333333),A3(0.3333333333333333)
A4 -> A4(0.6666666666666666),A6(0.16666666666666666),A3(0.16666666666666666)
A9 -> A9(1.0)
A1 -> A1(0.5),A3(0.5)
A8 -> A9(1.0)


In [40]:
plotCompared(enrollments,[iwfts1p,iwftsd1p],["Normal","Diferenças"],'')
enrolments_modelbase_fo.append({"name":"IWFTS","model":iwfts1,"predicted":iwfts1p})
enrolments_modelbase_fo.append({"name":"IWFTS Dif.","model":iwftsd1,"predicted":iwftsd1p})


IWFTS - Experimento com o dataset TAIEX


In [41]:
iwfts2,iwfts2p,iwftsd2,iwftsd2p = SelecaoKFold_MenorRMSE(taiexsample,[2,5,10,15,20,25,30,35], ImprovedWeightedFTS)


Série Original
0 2 1102.43154749
0 5 306.588479104
0 10 201.737951925
0 15 131.332904884
0 20 95.2517421796
0 25 79.4023447013
0 30 66.1376923757
0 35 55.6434046179
1 2 1414.48412767
1 5 484.937675917
1 10 225.554926179
1 15 148.603661133
1 20 99.6499378843
1 25 80.375164683
1 30 89.2448698306
1 35 62.575357917
2 2 1133.20070357
2 5 379.654360705
2 10 192.815117126
2 15 136.883015714
2 20 101.667451046
2 25 77.1415051272
2 30 71.8992533785
2 35 61.1943844612
3 2 1649.34045533
3 5 545.206084041
3 10 262.86952491
3 15 175.499456287
3 20 266.113694025
3 25 335.418683079
3 30 387.454755561
3 35 105.346876208
4 2 808.881297
4 5 380.849452299
4 10 1456.16766339
4 15 1818.64085321
4 20 1531.19319377
4 25 1345.86251517
4 30 1140.42739904
4 35 2187.23076974

Série Diferencial
0 2 42.2264698415
0 5 22.2412799468
0 10 24.2123256813
0 15 22.3954630774
0 20 21.4742051968
0 25 21.6689147893
0 30 26.0586288987
0 35 24.1802921642
1 2 42.1614735791
1 5 23.6376827325
1 10 27.5703906196
1 15 33.4834486234
1 20 27.9182594076
1 25 28.3469687815
1 30 31.7280089603
1 35 43.3229011001
2 2 77.607760229
2 5 24.1425102383
2 10 36.1241181827
2 15 42.6435738013
2 20 48.6738533376
2 25 45.2955910432
2 30 47.4285683609
2 35 63.9311607819
3 2 39.8944577027
3 5 36.8503865173
3 10 42.2486960923
3 15 60.5848949363
3 20 55.6516188049
3 25 73.0050850283
3 30 74.1883940039
3 35 92.3414116204
4 2 42.1608635314
4 5 22.2972822117
4 10 23.6064611262
4 15 26.1083930649
4 20 23.0383042601
4 25 23.4151360103
4 30 24.5676178581
4 35 25.885489637

In [42]:
print(iwfts2)


35 particoes:
A14 -> A14(0.6716417910447762),A13(0.1791044776119403),A15(0.14925373134328357)
A0 -> A0(0.75),A1(0.25)
A8 -> A7(0.1794871794871795),A10(0.02564102564102564),A9(0.1794871794871795),A8(0.6153846153846154)
A6 -> A7(0.09375),A6(0.6875),A5(0.21875)
A32 -> A33(0.23809523809523808),A32(0.47619047619047616),A29(0.047619047619047616),A31(0.23809523809523808)
A3 -> A4(0.2727272727272727),A2(0.09090909090909091),A3(0.6363636363636364)
A1 -> A1(0.5),A2(0.25),A0(0.25)
A10 -> A9(0.15384615384615385),A11(0.23076923076923078),A10(0.6153846153846154)
A9 -> A8(0.2),A9(0.64),A10(0.16)
A19 -> A18(0.16279069767441862),A21(0.023255813953488372),A19(0.6046511627906976),A20(0.20930232558139536)
A17 -> A16(0.09090909090909091),A18(0.25),A15(0.045454545454545456),A17(0.6136363636363636)
A24 -> A23(0.23863636363636365),A25(0.17045454545454544),A24(0.5909090909090909)
A7 -> A7(0.6296296296296297),A6(0.14814814814814814),A9(0.037037037037037035),A8(0.18518518518518517)
A25 -> A25(0.6052631578947368),A24(0.21052631578947367),A26(0.18421052631578946)
A30 -> A28(0.07407407407407407),A30(0.5185185185185185),A29(0.3333333333333333),A31(0.07407407407407407)
A21 -> A23(0.02857142857142857),A19(0.014285714285714285),A20(0.11428571428571428),A22(0.2571428571428571),A21(0.5857142857142857)
A2 -> A1(0.15384615384615385),A2(0.6923076923076923),A3(0.15384615384615385)
A18 -> A18(0.7361111111111112),A19(0.1111111111111111),A17(0.1527777777777778)
A12 -> A14(0.016666666666666666),A13(0.13333333333333333),A10(0.016666666666666666),A11(0.25),A12(0.5833333333333334)
A34 -> A34(0.75),A33(0.21428571428571427),A32(0.03571428571428571)
A4 -> A4(0.6),A2(0.06666666666666667),A5(0.2),A3(0.13333333333333333)
A27 -> A27(0.5636363636363636),A25(0.01818181818181818),A28(0.10909090909090909),A29(0.03636363636363636),A26(0.2727272727272727)
A15 -> A14(0.1),A16(0.1),A15(0.7875),A17(0.0125)
A5 -> A4(0.1),A6(0.15),A5(0.75)
A26 -> A27(0.2857142857142857),A25(0.23214285714285715),A26(0.48214285714285715)
A33 -> A33(0.3125),A34(0.4375),A32(0.25)
A16 -> A14(0.03333333333333333),A16(0.8),A15(0.08333333333333333),A17(0.08333333333333333)
A28 -> A27(0.15384615384615385),A28(0.6410256410256411),A30(0.02564102564102564),A29(0.1794871794871795)
A22 -> A24(0.022988505747126436),A23(0.14942528735632185),A20(0.022988505747126436),A22(0.6091954022988506),A21(0.19540229885057472)
A23 -> A23(0.52),A25(0.013333333333333334),A24(0.24),A22(0.2),A20(0.02666666666666667)
A20 -> A18(0.017857142857142856),A21(0.19642857142857142),A20(0.625),A22(0.017857142857142856),A19(0.14285714285714285)
A29 -> A27(0.043478260869565216),A28(0.10869565217391304),A30(0.2391304347826087),A29(0.5869565217391305),A31(0.021739130434782608)
A13 -> A14(0.2),A13(0.6),A11(0.01818181818181818),A12(0.18181818181818182)
A11 -> A13(0.015625),A10(0.15625),A9(0.03125),A11(0.5625),A12(0.234375)
A31 -> A30(0.05555555555555555),A28(0.05555555555555555),A32(0.3333333333333333),A31(0.5555555555555556)


In [43]:
plotCompared(taiexsample,[iwfts2p,iwftsd2p],["Normal","Diferenças"],'')
taiex_modelbase_fo.append({"name":"IWFTS","model":iwfts2,"predicted":iwfts2p})
taiex_modelbase_fo.append({"name":"IWFTS Dif.","model":iwftsd2,"predicted":iwftsd2p})


Exponentialy Weighted Fuzzy Time Series

O método EWFTS - \textit{Exponentialy Weighted Fuzzy Time Series}, é utilizado em \cite{sadaei2014short}, e contrasta com o crescimento linear dos pesos proposto por \cite{yu2005weighted} modificando-os por um crescimento exponencial. Dada a FLRG $A_i \rightarrow A_1,A_3,...,A_k$, a matriz $M(t) = [m_1, m_2, ...,m_k]$ dos centros de $A_1,A_3,...,A_k$ a matriz de pesos $w(t)$ será definida por um parâmetro $c$, que formará a série exponencial $c^0, c^1, ..., c^{k-1}$ normalizada. O parâmetro $c$ deve ser maior do que zero.

$$ w(t) = \left[ \frac{1}{\sum_{h=1}^k c^{h-1}},\frac{c^1}{\sum_{h=1}^k c^{h-1}},...,\frac{c^{k-1}}{\sum_{h=1}^k c^{h-1}} \right] $$

EWFTS - Código Fonte


In [44]:
class ExponentialyWeightedFLRG:
	def __init__(self,premiss,c):
		self.premiss = premiss
		self.consequent = []
		self.count = 0.0
		self.c = c

	def append(self,c):
		self.consequent.append(c)
		self.count = self.count + 1.0

	def weights(self):
		wei = [ self.c**k for k in np.arange(0.0,self.count,1.0)]
		tot = sum( wei )
		return np.array([ k/tot for k in wei ])
        
	def __str__(self):
		tmp = self.premiss + " -> "
		tmp2 = ""
		cc = 0
		wei = [ self.c**k for k in np.arange(0.0,self.count,1.0)]
		tot = sum( wei )
		for c in self.consequent:
			if len(tmp2) > 0:
				tmp2 = tmp2 + ","
			tmp2 = tmp2 + c + "(" + str(wei[cc]/tot) + ")"
			cc = cc + 1
		return tmp + tmp2

In [45]:
class ExponentialyWeightedFTS(FTS):
	def __init__(self,name):
		super(ExponentialyWeightedFTS, self).__init__(1,name)
        
	def defuzzy(self,data):
        
		actual = self.fuzzy(data)
        
		if actual["fuzzyset"] not in self.flrgs:
			return self.sets[actual["fuzzyset"]].centroid

		flrg = self.flrgs[actual["fuzzyset"]]

		mi = np.array([self.sets[s].centroid for s in flrg.consequent])
        
		return mi.dot( flrg.weights() )
        
	def learn(self, data, sets):
		last = {"fuzzyset":"", "membership":0.0}
		actual = {"fuzzyset":"", "membership":0.0}
		
		for s in sets:
			self.sets[s.name] = s
		
		self.flrgs = {}
		count = 1
		for inst in data:
			actual = self.fuzzy(inst)
			
			if count > self.order:
				if last["fuzzyset"] not in self.flrgs:
					self.flrgs[last["fuzzyset"]] = ExponentialyWeightedFLRG(last["fuzzyset"],2)
			
				self.flrgs[last["fuzzyset"]].append(actual["fuzzyset"])    
			count = count + 1
			last = actual

EWFTS - Experimento com o dataset Enrollments


In [46]:
ewfts1,ewfts1p,ewftsd1,ewftsd1p = SelecaoSimples_MenorRMSE(enrollments,[6,8,10,12,14], ExponentialyWeightedFTS)


Série Original
6 1595.03329663
8 1774.84095057
10 519.438292024
12 689.880524451
14 553.604229768

Série Diferencial
6 541.56601998
8 425.525684217
10 405.970793118
12 413.933252692
14 469.826090164

In [47]:
print(ewfts1)


10 particoes:
A0 -> A1(1.0)
A6 -> A6(0.142857142857),A5(0.285714285714),A8(0.571428571429)
A5 -> A4(0.333333333333),A6(0.666666666667)
A3 -> A4(0.142857142857),A3(0.285714285714),A5(0.571428571429)
A4 -> A4(0.015873015873),A4(0.031746031746),A4(0.0634920634921),A6(0.126984126984),A4(0.253968253968),A3(0.507936507937)
A9 -> A9(0.142857142857),A9(0.285714285714),A9(0.571428571429)
A1 -> A1(0.333333333333),A3(0.666666666667)
A8 -> A9(1.0)


In [48]:
plotCompared(enrollments,[ewfts1p,ewftsd1p],["Normal","Diferenças"],'')
enrolments_modelbase_fo.append({"name":"EWFTS","model":ewfts1,"predicted":ewfts1p})
enrolments_modelbase_fo.append({"name":"EWFTS Dif.","model":ewftsd1,"predicted":ewftsd1p})


EWFTS - Experimento com o dataset TAIEX


In [129]:
ewfts2,ewfts2p,ewftsd2,ewftsd2p = SelecaoKFold_MenorRMSE(taiexsample,[2,5,10,15,20,25,30,35], ImprovedWeightedFTS)


Série Original
0 2 1102.43154749
0 5 306.588479104
0 10 201.737951925
0 15 131.332904884
0 20 95.2517421796
0 25 79.4023447013
0 30 66.1376923757
0 35 55.6434046179
1 2 1414.48412767
1 5 484.937675917
1 10 225.554926179
1 15 148.603661133
1 20 99.6499378843
1 25 80.375164683
1 30 89.2448698306
1 35 62.575357917
2 2 1133.20070357
2 5 379.654360705
2 10 192.815117126
2 15 136.883015714
2 20 101.667451046
2 25 77.1415051272
2 30 71.8992533785
2 35 61.1943844612
3 2 1649.34045533
3 5 545.206084041
3 10 262.86952491
3 15 175.499456287
3 20 266.113694025
3 25 335.418683079
3 30 387.454755561
3 35 105.346876208
4 2 808.881297
4 5 380.849452299
4 10 1456.16766339
4 15 1818.64085321
4 20 1531.19319377
4 25 1345.86251517
4 30 1140.42739904
4 35 2187.23076974

Série Diferencial
0 2 42.2264698415
0 5 22.2412799468
0 10 24.2123256813
0 15 22.3954630774
0 20 21.4742051968
0 25 21.6689147893
0 30 26.0586288987
0 35 24.1802921642
1 2 42.1614735791
1 5 23.6376827325
1 10 27.5703906196
1 15 33.4834486234
1 20 27.9182594076
1 25 28.3469687815
1 30 31.7280089603
1 35 43.3229011001
2 2 77.607760229
2 5 24.1425102383
2 10 36.1241181827
2 15 42.6435738013
2 20 48.6738533376
2 25 45.2955910432
2 30 47.4285683609
2 35 63.9311607819
3 2 39.8944577027
3 5 36.8503865173
3 10 42.2486960923
3 15 60.5848949363
3 20 55.6516188049
3 25 73.0050850283
3 30 74.1883940039
3 35 92.3414116204
4 2 42.1608635314
4 5 22.2972822117
4 10 23.6064611262
4 15 26.1083930649
4 20 23.0383042601
4 25 23.4151360103
4 30 24.5676178581
4 35 25.885489637

In [50]:
print(ewfts2)


35 particoes:
A14 -> A14(0.6716417910447762),A13(0.1791044776119403),A15(0.14925373134328357)
A0 -> A0(0.75),A1(0.25)
A8 -> A7(0.1794871794871795),A10(0.02564102564102564),A9(0.1794871794871795),A8(0.6153846153846154)
A6 -> A7(0.09375),A6(0.6875),A5(0.21875)
A32 -> A33(0.23809523809523808),A32(0.47619047619047616),A29(0.047619047619047616),A31(0.23809523809523808)
A3 -> A4(0.2727272727272727),A2(0.09090909090909091),A3(0.6363636363636364)
A1 -> A1(0.5),A2(0.25),A0(0.25)
A10 -> A9(0.15384615384615385),A11(0.23076923076923078),A10(0.6153846153846154)
A9 -> A8(0.2),A9(0.64),A10(0.16)
A19 -> A18(0.16279069767441862),A21(0.023255813953488372),A19(0.6046511627906976),A20(0.20930232558139536)
A17 -> A16(0.09090909090909091),A18(0.25),A15(0.045454545454545456),A17(0.6136363636363636)
A24 -> A23(0.23863636363636365),A25(0.17045454545454544),A24(0.5909090909090909)
A7 -> A7(0.6296296296296297),A6(0.14814814814814814),A9(0.037037037037037035),A8(0.18518518518518517)
A25 -> A25(0.6052631578947368),A24(0.21052631578947367),A26(0.18421052631578946)
A30 -> A28(0.07407407407407407),A30(0.5185185185185185),A29(0.3333333333333333),A31(0.07407407407407407)
A21 -> A23(0.02857142857142857),A19(0.014285714285714285),A20(0.11428571428571428),A22(0.2571428571428571),A21(0.5857142857142857)
A2 -> A1(0.15384615384615385),A2(0.6923076923076923),A3(0.15384615384615385)
A18 -> A18(0.7361111111111112),A19(0.1111111111111111),A17(0.1527777777777778)
A12 -> A14(0.016666666666666666),A13(0.13333333333333333),A10(0.016666666666666666),A11(0.25),A12(0.5833333333333334)
A34 -> A34(0.75),A33(0.21428571428571427),A32(0.03571428571428571)
A4 -> A4(0.6),A2(0.06666666666666667),A5(0.2),A3(0.13333333333333333)
A27 -> A27(0.5636363636363636),A25(0.01818181818181818),A28(0.10909090909090909),A29(0.03636363636363636),A26(0.2727272727272727)
A15 -> A14(0.1),A16(0.1),A15(0.7875),A17(0.0125)
A5 -> A4(0.1),A6(0.15),A5(0.75)
A26 -> A27(0.2857142857142857),A25(0.23214285714285715),A26(0.48214285714285715)
A33 -> A33(0.3125),A34(0.4375),A32(0.25)
A16 -> A14(0.03333333333333333),A16(0.8),A15(0.08333333333333333),A17(0.08333333333333333)
A28 -> A27(0.15384615384615385),A28(0.6410256410256411),A30(0.02564102564102564),A29(0.1794871794871795)
A22 -> A24(0.022988505747126436),A23(0.14942528735632185),A20(0.022988505747126436),A22(0.6091954022988506),A21(0.19540229885057472)
A23 -> A23(0.52),A25(0.013333333333333334),A24(0.24),A22(0.2),A20(0.02666666666666667)
A20 -> A18(0.017857142857142856),A21(0.19642857142857142),A20(0.625),A22(0.017857142857142856),A19(0.14285714285714285)
A29 -> A27(0.043478260869565216),A28(0.10869565217391304),A30(0.2391304347826087),A29(0.5869565217391305),A31(0.021739130434782608)
A13 -> A14(0.2),A13(0.6),A11(0.01818181818181818),A12(0.18181818181818182)
A11 -> A13(0.015625),A10(0.15625),A9(0.03125),A11(0.5625),A12(0.234375)
A31 -> A30(0.05555555555555555),A28(0.05555555555555555),A32(0.3333333333333333),A31(0.5555555555555556)


In [51]:
plotCompared(taiexsample,[ewfts2p,ewftsd2p],["Normal","Diferenças"],'')
taiex_modelbase_fo.append({"name":"EWFTS","model":ewfts2,"predicted":ewfts2p})
taiex_modelbase_fo.append({"name":"EWFTS Dif.","model":ewftsd2,"predicted":ewftsd2p})


High Order Fuzzy Time Series

Essa implementação segue os trabalho de \cite{hwang1998handling} e \cite{chen2014high}. Esses modelos se diferenciam dos modelos de primeira ordem pelo uso de $m$ preditores em conjunto, $F(t-1),...,F(t-m)$ tal que $F(t)$ é determinado por $F(t-1)$ e $F(t-2)$ e ... e $F(t-m)$. Regras nesse estilo devem ser interpretadas como SE $F(t-1)$ E $F(t-2)$ E ... E $F(t-m)$ ENTÃO $F(t)$.

O ponto focal desse modelo é a escolha da quantidade $w$ de defasagens de tempo que serão utilizadas na predição, a chamada janela base. Com $w$ serão desenvolvidas o vetor de critérios $C(t)$ e a matriz de operação $O^w(t)$ a partir das quais se obterá a matriz das relações $R(t)$. O vetor $C(t)$ contém as pertinências

\begin{equation} \begin{split} C(t) = \left[ \begin{array}{cccc} C_1 & C_2 & ... & C_k \end{array} \right] \\ C_i = f_{ai}( F(t-1) ) \quad 1 \leq i \leq k \end{split} \end{equation}\begin{equation} \begin{split} O^w(t) = \left[ \begin{array}{cccc} O_{11} & O_{12} & ... & O_{1k} \\ ... \\ O_{w1} & O_{w2} & ... &O_{wk} \end{array} \right] \\ O_{ji} = f_{ai}( F(t-j) ) \quad 1 \leq i \leq k \quad 1 \leq j \leq w \end{split} \end{equation}\begin{equation} \begin{split} R(t) = O^w(t) \times C(t) \\ R_{ji} = O_{ij} \times C_j \quad 1 \leq i \leq k \quad 1 \leq j \leq w \\ R(t) = \left[ \begin{array}{cccc} R_{11} & R_{12} & ... & R_{1k} \\ ... \\ R_{w1} & R_{w2} & ... & R_{wk} \end{array} \right] \end{split} \end{equation}\begin{equation} F(t) = \left[ \begin{array}{cccc} \max(R_{11} & R_{21} & ... & R_{w1}) \\ ... \\ \max(R_{1k} & R_{2k} & ... & R_{wk}) \end{array} \right] \end{equation}

As pertinências de $F(t)$ para os $k$ conjuntos nebulosos na fórmula. Para deffuzificar o valor a partir de dos conjuntos, utiliza-se a mesma metodologia dos modelos de primeira ordem.

HOFTS - Código Fonte


In [52]:
class HighOrderFTS(FTS):
	def __init__(self,order,name):
		super(HighOrderFTS, self).__init__(order,name)
        
	def defuzzy(self,data,t):
		cn = np.array([0.0 for k in range(len(self.sets))])
		ow = np.array([[0.0 for k in range(len(self.sets))] for z in range(self.order-1)])
		rn = np.array([[0.0 for k in range(len(self.sets))] for z in range(self.order-1)])
		ft = np.array([0.0 for k in range(len(self.sets))])

		for s in range(len(self.sets)):
			cn[s] = self.sets[s].membership(data[t]) 
			for w in range(self.order-1):
				ow[w,s] = self.sets[s].membership(data[t-w]) 
				rn[w,s] = ow[w,s] * cn[s]
				ft[s] = max(ft[s],rn[w,s])
		mft =  max(ft)
		out = 0.0
		count = 0.0
		for s in range(len(self.sets)):
			if ft[s] == mft:
				out = out + self.sets[s].centroid
				count = count + 1.0
		return out / count


	def learn(self, data, sets):
		self.sets = sets
    
	def predict(self,data,t):
		return self.defuzzy(data,t)

	def predictDiff(self,data,t):
		return data[t] + self.defuzzy(diferencas(data),t)

In [53]:
def HOSelecaoSimples_MenorRMSE(original,parameters,orders):
	ret = []
	errors = np.array([[0 for k in range(len(parameters))] for kk in range(len(orders))])
	predicted_best = []
	print("Série Original")
	fig = plt.figure(figsize=[20,12])
	fig.suptitle("Comparação de modelos ")
	ax0 = fig.add_axes([0, 0.5, 0.6, 0.45]) #left, bottom, width, height
	ax0.set_xlim([0,len(original)])
	ax0.set_ylim([min(original),max(original)])
	ax0.set_title('Série Temporal')
	ax0.set_ylabel('F(T)')
	ax0.set_xlabel('T')
	ax0.plot(original,label="Original")
	min_rmse = 100000.0
	best = None
	pc = 0
	for p in parameters:
		oc = 0
		for o in orders:
			sets = GridPartitionerTrimf(original,p)
			fts = HighOrderFTS(o,"k = " + str(p)+ " w = " + str(o))
			fts.learn(original,sets)
			predicted = [fts.predict(original, xx) for xx in range(o,len(original))]
			error = rmse(np.array(predicted),np.array(original[o:]))
			for kk in range(o):
				predicted.insert(0,None)
			ax0.plot(predicted,label=fts.name)
			print(o,p,error)
			errors[oc,pc] = error
			if error < min_rmse:
				min_rmse = error
				best = fts
				predicted_best = predicted
			oc = oc + 1
		pc = pc + 1
		handles0, labels0 = ax0.get_legend_handles_labels()
	ax0.legend(handles0, labels0)
	ax1 = Axes3D(fig, rect=[0.6, 0.5, 0.45, 0.45], elev=30, azim=144)
	#ax1 = fig.add_axes([0.6, 0.5, 0.45, 0.45], projection='3d')
	ax1.set_title('Comparação dos Erros Quadráticos Médios por tamanho da janela')
	ax1.set_ylabel('RMSE')
	ax1.set_xlabel('Quantidade de Partições')
	ax1.set_zlabel('W')
	X,Y = np.meshgrid(parameters,orders)
	surf = ax1.plot_surface(X, Y, errors, rstride=1, cstride=1, antialiased=True)
	ret.append(best)
	ret.append(predicted_best)

    # Modelo diferencial
	print("\nSérie Diferencial")
	errors = np.array([[0 for k in range(len(parameters))] for kk in range(len(orders))])
	predictedd_best = []
	ax2 = fig.add_axes([0, 0, 0.6, 0.45]) #left, bottom, width, height
	ax2.set_xlim([0,len(original)])
	ax2.set_ylim([min(original),max(original)])
	ax2.set_title('Série Temporal')
	ax2.set_ylabel('F(T)')
	ax2.set_xlabel('T')
	ax2.plot(original,label="Original")
	min_rmse = 100000.0
	bestd = None
	pc = 0
	for p in parameters:
		oc = 0
		for o in orders:
			sets = GridPartitionerTrimf(diferencas(original),p)
			fts = HighOrderFTS(o,"k = " + str(p)+ " w = " + str(o))
			fts.learn(original,sets)
			predicted = [fts.predictDiff(original, xx) for xx in range(o,len(original))]
			error = rmse(np.array(predicted),np.array(original[o:]))
			for kk in range(o):
				predicted.insert(0,None)
			ax2.plot(predicted,label=fts.name)
			print(o,p,error)
			errors[oc,pc] = error
			if error < min_rmse:
				min_rmse = error
				bestd = fts
				predictedd_best = predicted
			oc = oc + 1
		pc = pc + 1
	handles0, labels0 = ax2.get_legend_handles_labels()
	ax2.legend(handles0, labels0)
	ax3 = Axes3D(fig, rect=[0.6, 0.0, 0.45, 0.45], elev=30, azim=144)
	#ax3 = fig.add_axes([0.6, 0.0, 0.45, 0.45], projection='3d')
	ax3.set_title('Comparação dos Erros Quadráticos Médios')
	ax3.set_ylabel('RMSE')
	ax3.set_xlabel('Quantidade de Partições')
	ax3.set_zlabel('W')
	X,Y = np.meshgrid(parameters,orders)
	surf = ax3.plot_surface(X, Y, errors, rstride=1, cstride=1, antialiased=True)
	ret.append(bestd)
	ret.append(predictedd_best)
	return ret

HOFTS - Experimento com o dataset Enrollments


In [126]:
hofts1,hofts1p,hoftsd1,hoftsd1p = HOSelecaoSimples_MenorRMSE(enrollments,[4,8,10,12],[2,3,4,5,6])


Série Original
2 4 1135.40636586
3 4 1155.361058
4 4 1186.9043316
5 4 1204.42722078
6 4 1229.61003886
2 8 835.295995909
3 8 856.973636305
4 8 883.150995823
5 8 908.676371016
6 8 936.310132936
2 10 259.279733107
3 10 262.652177443
4 10 263.670269676
5 10 270.05177717
6 10 270.858487037
2 12 784.234389787
3 12 802.799265809
4 12 824.630432797
5 12 846.971076057
6 12 872.097903854

Série Diferencial
2 4 543.426170813
3 4 556.209732428
4 4 544.96920466
5 4 525.080235465
6 4 539.608267201
2 8 582.100861777
3 8 574.005751536
4 8 564.87514061
5 8 553.669066088
6 8 570.01249044
2 10 597.680525448
3 10 606.556520992
4 10 590.747088675
5 10 572.561374568
6 10 590.013104198
2 12 590.671770635
3 12 604.789602933
4 12 597.098008077
5 12 589.773383766
6 12 605.732072937

In [127]:
plotCompared(enrollments,[hofts1p,hoftsd1p],["Normal","Diferenças"],'')
enrolments_modelbase_ho.append({"name":"HOFTS","model":hofts1,"predicted":hofts1p})
enrolments_modelbase_ho.append({"name":"HOFTS Dif.","model":hoftsd1,"predicted":hoftsd1p})


HOFTS - Experimento com o dataset TAIEX


In [56]:
hofts2,hofts2p,hoftsd2,hoftsd2p = HOSelecaoSimples_MenorRMSE(taiexsample,[5,10,15,20,25],[2,3,4,5,6])


Série Original
2 5 420.57062921
3 5 421.074390874
4 5 421.289762726
5 5 421.697997436
6 5 422.241515409
2 10 221.289804954
3 10 222.366615545
4 10 223.91162587
5 10 225.035331451
6 10 225.810826706
2 15 158.399228661
3 15 160.038495828
4 15 161.092282383
5 15 161.956580208
6 15 162.190150288
2 20 97.3770402887
3 20 98.9555730853
4 20 100.128367177
5 20 100.803960107
6 20 101.044837329
2 25 77.3405880162
3 25 79.1417464992
4 25 79.9399729255
5 25 80.2503027492
6 25 80.3857920219

Série Diferencial
2 5 120.139253189
3 5 116.29864945
4 5 114.679791656
5 5 113.774404806
6 5 113.231350094
2 10 104.202757461
3 10 102.695092483
4 10 102.249016989
5 10 102.23956903
6 10 102.238481147
2 15 101.819865076
3 15 101.407275297
4 15 101.32408971
5 15 101.310091042
6 15 100.892448729
2 20 100.846365148
3 20 100.299884271
4 20 100.222684317
5 20 100.188602273
6 20 99.9597963798
2 25 100.68696984
3 25 100.665035942
4 25 100.589558484
5 25 100.420285523
6 25 100.379561696

In [57]:
plotCompared(taiexsample,[hofts2p,hoftsd2p],["Normal","Diferenças"],'')
taiex_modelbase_ho.append({"name":"HOFTS","model":hofts2,"predicted":hofts2p})
taiex_modelbase_ho.append({"name":"HOFTS Dif.","model":hoftsd2,"predicted":hoftsd2p})


Comparação entre os modelos

Enrollments


In [108]:
compareModelsPlot(enrollments,enrolments_modelbase_fo,enrolments_modelbase_ho)



In [86]:
tab = compareModelsTable(enrollments,enrolments_modelbase_fo,enrolments_modelbase_ho)



In [113]:
plotCompared(enrollments,[hofts1p],['HOFTS'],'')



In [115]:
print(ftsd1)


4 particoes:
A1 -> A1,A2,A0,A3
A2 -> A1,A2,A3
A0 -> A1
A3 -> A2,A3


In [128]:
for s in hofts1.sets:
    print(s)


A0: <function trimf at 0xaa1b6464>([12426.799999999999, 13055, 13683.200000000001])
A1: <function trimf at 0xaa1b6464>([13055.0, 13683.200000000001, 14311.400000000001])
A2: <function trimf at 0xaa1b6464>([13683.200000000001, 14311.400000000001, 14939.600000000002])
A3: <function trimf at 0xaa1b6464>([14311.400000000001, 14939.600000000002, 15567.800000000003])
A4: <function trimf at 0xaa1b6464>([14939.600000000002, 15567.800000000003, 16196.000000000004])
A5: <function trimf at 0xaa1b6464>([15567.800000000003, 16196.000000000004, 16824.200000000004])
A6: <function trimf at 0xaa1b6464>([16196.000000000004, 16824.200000000004, 17452.400000000005])
A7: <function trimf at 0xaa1b6464>([16824.200000000004, 17452.400000000005, 18080.600000000006])
A8: <function trimf at 0xaa1b6464>([17452.400000000005, 18080.600000000006, 18708.800000000007])
A9: <function trimf at 0xaa1b6464>([18080.600000000006, 18708.800000000007, 19337.000000000007])

TAIEX


In [107]:
#taiex_modelbase_fo
compareModelsPlot(taiexsample,taiex_modelbase_fo,taiex_modelbase_ho)



In [89]:
tab = compareModelsTable(taiexsample,taiex_modelbase_fo,taiex_modelbase_ho)



In [121]:
plotCompared(taiexsample,[wftsd2p],['WFTS Dif'],'')



In [135]:
#for s in wfts2.sets: print(wfts2.sets[s])
print(iwfts2)


35 particoes:
A14 -> A14(0.6716417910447762),A13(0.1791044776119403),A15(0.14925373134328357)
A0 -> A0(0.75),A1(0.25)
A8 -> A7(0.1794871794871795),A10(0.02564102564102564),A9(0.1794871794871795),A8(0.6153846153846154)
A6 -> A7(0.09375),A6(0.6875),A5(0.21875)
A32 -> A33(0.23809523809523808),A32(0.47619047619047616),A29(0.047619047619047616),A31(0.23809523809523808)
A3 -> A4(0.2727272727272727),A2(0.09090909090909091),A3(0.6363636363636364)
A1 -> A1(0.5),A2(0.25),A0(0.25)
A10 -> A9(0.15384615384615385),A11(0.23076923076923078),A10(0.6153846153846154)
A9 -> A8(0.2),A9(0.64),A10(0.16)
A19 -> A18(0.16279069767441862),A21(0.023255813953488372),A19(0.6046511627906976),A20(0.20930232558139536)
A17 -> A16(0.09090909090909091),A18(0.25),A15(0.045454545454545456),A17(0.6136363636363636)
A24 -> A23(0.23863636363636365),A25(0.17045454545454544),A24(0.5909090909090909)
A7 -> A7(0.6296296296296297),A6(0.14814814814814814),A9(0.037037037037037035),A8(0.18518518518518517)
A25 -> A25(0.6052631578947368),A24(0.21052631578947367),A26(0.18421052631578946)
A30 -> A28(0.07407407407407407),A30(0.5185185185185185),A29(0.3333333333333333),A31(0.07407407407407407)
A21 -> A23(0.02857142857142857),A19(0.014285714285714285),A20(0.11428571428571428),A22(0.2571428571428571),A21(0.5857142857142857)
A2 -> A1(0.15384615384615385),A2(0.6923076923076923),A3(0.15384615384615385)
A18 -> A18(0.7361111111111112),A19(0.1111111111111111),A17(0.1527777777777778)
A12 -> A14(0.016666666666666666),A13(0.13333333333333333),A10(0.016666666666666666),A11(0.25),A12(0.5833333333333334)
A34 -> A34(0.75),A33(0.21428571428571427),A32(0.03571428571428571)
A4 -> A4(0.6),A2(0.06666666666666667),A5(0.2),A3(0.13333333333333333)
A27 -> A27(0.5636363636363636),A25(0.01818181818181818),A28(0.10909090909090909),A29(0.03636363636363636),A26(0.2727272727272727)
A15 -> A14(0.1),A16(0.1),A15(0.7875),A17(0.0125)
A5 -> A4(0.1),A6(0.15),A5(0.75)
A26 -> A27(0.2857142857142857),A25(0.23214285714285715),A26(0.48214285714285715)
A33 -> A33(0.3125),A34(0.4375),A32(0.25)
A16 -> A14(0.03333333333333333),A16(0.8),A15(0.08333333333333333),A17(0.08333333333333333)
A28 -> A27(0.15384615384615385),A28(0.6410256410256411),A30(0.02564102564102564),A29(0.1794871794871795)
A22 -> A24(0.022988505747126436),A23(0.14942528735632185),A20(0.022988505747126436),A22(0.6091954022988506),A21(0.19540229885057472)
A23 -> A23(0.52),A25(0.013333333333333334),A24(0.24),A22(0.2),A20(0.02666666666666667)
A20 -> A18(0.017857142857142856),A21(0.19642857142857142),A20(0.625),A22(0.017857142857142856),A19(0.14285714285714285)
A29 -> A27(0.043478260869565216),A28(0.10869565217391304),A30(0.2391304347826087),A29(0.5869565217391305),A31(0.021739130434782608)
A13 -> A14(0.2),A13(0.6),A11(0.01818181818181818),A12(0.18181818181818182)
A11 -> A13(0.015625),A10(0.15625),A9(0.03125),A11(0.5625),A12(0.234375)
A31 -> A30(0.05555555555555555),A28(0.05555555555555555),A32(0.3333333333333333),A31(0.5555555555555556)

References

(Song and Chissom, 1993) Song Qiang and Chissom Brad S, ``Fuzzy time series and its models'', Fuzzy sets and systems, vol. 54, number 3, pp. 269--277, 1993.

(Chen, 1996) Chen Shyi-Ming, ``Forecasting enrollments based on fuzzy time series'', Fuzzy sets and systems, vol. 81, number 3, pp. 311--319, 1996.

(Ismail and Efendi, 2011) Ismail Zuhaimy and Efendi R, ``Enrollment forecasting based on modified weight fuzzy time series'', Journal of Artificial Intelligence, vol. 4, number 1, pp. 110--118, 2011.

(Efendi, Ismail et al., 2013) Efendi Riswan, Ismail Zuhaimy and Deris Mustafa Mat, ``IMPROVED WEIGHT FUZZY TIME SERIES AS USED IN THE EXCHANGE RATES FORECASTING OF US DOLLAR TO RINGGIT MALAYSIA'', International Journal of Computational Intelligence and Applications, vol. 12, number 01, pp. 1350005, 2013.

(Yu, 2005) Yu Hui-Kuang, ``Weighted fuzzy time series models for TAIEX forecasting'', Physica A: Statistical Mechanics and its Applications, vol. 349, number 3, pp. 609--624, 2005.

(Sadaei, Enayatifar et al., 2014) Sadaei Hossein Javedani, Enayatifar Rasul, Abdullah Abdul Hanan et al., ``Short-term load forecasting using a hybrid model with a refined exponentially weighted fuzzy time series and an improved harmony search'', International Journal of Electrical Power \& Energy Systems, vol. 62, number , pp. 118--129, 2014.

(Hwang, Chen et al., 1998) Hwang Jeng-Ren, Chen Shyi-Ming and Lee Chia-Hoang, ``Handling forecasting problems using fuzzy time series'', Fuzzy sets and systems, vol. 100, number 1, pp. 217--228, 1998.

(Chen, 2014) Chen Mu-Yen, ``A high-order fuzzy time series forecasting model for internet stock trading'', Future Generation Computer Systems, vol. 37, number , pp. 461--467, 2014.


In [ ]: