2017-02-24 20:29:55 +04:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf8 -*-
|
|
|
|
|
|
|
|
import os
|
|
|
|
import numpy as np
|
|
|
|
import pandas as pd
|
|
|
|
import matplotlib as plt
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
from mpl_toolkits.mplot3d import Axes3D
|
|
|
|
|
|
|
|
import pandas as pd
|
2017-02-27 22:53:29 +04:00
|
|
|
from pyFTS.partitioners import Grid, Entropy, FCM, Huarng
|
2017-02-24 20:29:55 +04:00
|
|
|
from pyFTS.common import FLR,FuzzySet,Membership,Transformations
|
2017-03-03 15:53:55 +04:00
|
|
|
from pyFTS import fts,hofts,ifts,pwfts,tree, chen
|
2017-05-03 00:16:49 +04:00
|
|
|
#from pyFTS.benchmarks import benchmarks as bchmk
|
2017-03-03 15:53:55 +04:00
|
|
|
from pyFTS.benchmarks import naive, arima
|
2017-02-24 20:29:55 +04:00
|
|
|
from pyFTS.benchmarks import Measures
|
|
|
|
from numpy import random
|
|
|
|
|
2017-05-07 00:04:37 +04:00
|
|
|
os.chdir("/home/petronio/dados/Dropbox/Doutorado/Codigos/")
|
|
|
|
|
2017-05-07 18:41:31 +04:00
|
|
|
#enrollments = pd.read_csv("DataSets/Enrollments.csv", sep=";")
|
|
|
|
#enrollments = np.array(enrollments["Enrollments"])
|
2017-05-07 00:04:37 +04:00
|
|
|
|
2017-05-07 18:41:31 +04:00
|
|
|
#from pyFTS import song
|
2017-05-07 00:04:37 +04:00
|
|
|
|
2017-05-07 18:41:31 +04:00
|
|
|
#enrollments_fs = Grid.GridPartitioner(enrollments, 10).sets
|
2017-05-07 00:04:37 +04:00
|
|
|
|
2017-05-07 18:41:31 +04:00
|
|
|
#model = song.ConventionalFTS('')
|
|
|
|
#model.train(enrollments,enrollments_fs)
|
|
|
|
#teste = model.forecast(enrollments)
|
2017-05-07 00:04:37 +04:00
|
|
|
|
2017-05-07 18:41:31 +04:00
|
|
|
#print(teste)
|
2017-05-07 00:04:37 +04:00
|
|
|
|
|
|
|
|
2017-02-24 20:29:55 +04:00
|
|
|
#print(FCM.FCMPartitionerTrimf.__module__)
|
|
|
|
|
2017-05-08 20:12:08 +04:00
|
|
|
#gauss = random.normal(0,1.0,5000)
|
2017-02-24 20:29:55 +04:00
|
|
|
#gauss_teste = random.normal(0,1.0,400)
|
|
|
|
|
2017-05-08 21:49:45 +04:00
|
|
|
taiexpd = pd.read_csv("DataSets/TAIEX.csv", sep=",")
|
|
|
|
taiex = np.array(taiexpd["avg"][:5000])
|
2017-05-08 20:12:08 +04:00
|
|
|
|
|
|
|
#nasdaqpd = pd.read_csv("DataSets/NASDAQ_IXIC.csv", sep=",")
|
|
|
|
#nasdaq = np.array(nasdaqpd["avg"][0:5000])
|
2017-02-27 22:53:29 +04:00
|
|
|
|
2017-04-14 00:27:38 +04:00
|
|
|
#from statsmodels.tsa.arima_model import ARIMA as stats_arima
|
|
|
|
from statsmodels.tsa.tsatools import lagmat
|
2017-04-13 19:36:22 +04:00
|
|
|
|
2017-05-03 00:16:49 +04:00
|
|
|
#tmp = np.arange(10)
|
2017-04-13 19:36:22 +04:00
|
|
|
|
2017-05-03 00:16:49 +04:00
|
|
|
#lag, a = lagmat(tmp, maxlag=2, trim="both", original='sep')
|
2017-04-13 19:36:22 +04:00
|
|
|
|
2017-05-03 00:16:49 +04:00
|
|
|
#print(lag)
|
|
|
|
#print(a)
|
2017-04-13 19:36:22 +04:00
|
|
|
|
2017-05-07 18:41:31 +04:00
|
|
|
from pyFTS.benchmarks import distributed_benchmarks as bchmk
|
2017-04-06 06:45:11 +04:00
|
|
|
#from pyFTS.benchmarks import parallel_benchmarks as bchmk
|
2017-05-08 20:12:08 +04:00
|
|
|
from pyFTS.benchmarks import Util
|
2017-05-08 22:20:16 +04:00
|
|
|
from pyFTS.benchmarks import arima, quantreg
|
2017-04-13 19:36:22 +04:00
|
|
|
|
2017-05-08 20:12:08 +04:00
|
|
|
#Util.cast_dataframe_to_sintetic_point("experiments/taiex_point_analitic.csv","experiments/taiex_point_sintetic.csv",11)
|
|
|
|
|
2017-05-08 21:49:45 +04:00
|
|
|
#Util.plot_dataframe_point("experiments/taiex_point_sintetic.csv","experiments/taiex_point_analitic.csv",11)
|
2017-04-13 19:36:22 +04:00
|
|
|
|
2017-04-14 00:27:38 +04:00
|
|
|
#tmp = arima.ARIMA("")
|
2017-05-09 00:50:35 +04:00
|
|
|
#tmp.train(taiex[:1600], None, order=(1,0,1))
|
|
|
|
#teste = tmp.forecast(taiex[1600:1610])
|
2017-04-13 19:36:22 +04:00
|
|
|
|
2017-05-09 00:50:35 +04:00
|
|
|
#tmp = quantreg.QuantileRegression("")
|
|
|
|
#tmp.train(taiex[:1600], None, order=1)
|
|
|
|
#teste = tmp.forecast(taiex[1600:1610])
|
|
|
|
|
|
|
|
#print(taiex[1600:1610])
|
2017-04-14 00:27:38 +04:00
|
|
|
#print(teste)
|
2017-04-01 03:34:12 +04:00
|
|
|
|
2017-04-06 06:45:11 +04:00
|
|
|
#bchmk.teste(taiex,['192.168.0.109', '192.168.0.101'])
|
|
|
|
|
2017-05-08 21:49:45 +04:00
|
|
|
bchmk.point_sliding_window(taiex,2000,train=0.8, #models=[yu.WeightedFTS], # #
|
|
|
|
partitioners=[Grid.GridPartitioner], #Entropy.EntropyPartitioner], # FCM.FCMPartitioner, ],
|
|
|
|
partitions= np.arange(10,200,step=10), #transformation=diff,
|
|
|
|
dump=True, save=True, file="experiments/taiex_point_analytic.csv",
|
2017-05-09 00:50:35 +04:00
|
|
|
nodes=['192.168.0.102', '192.168.0.109', '192.168.0.106']) #, depends=[hofts, ifts])
|
2017-04-06 06:45:11 +04:00
|
|
|
|
2017-05-09 17:27:47 +04:00
|
|
|
diff = Transformations.Differential(1)
|
|
|
|
|
|
|
|
bchmk.point_sliding_window(taiex,2000,train=0.8, #models=[yu.WeightedFTS], # #
|
|
|
|
partitioners=[Grid.GridPartitioner], #Entropy.EntropyPartitioner], # FCM.FCMPartitioner, ],
|
|
|
|
partitions= np.arange(10,200,step=10), transformation=diff,
|
|
|
|
dump=True, save=True, file="experiments/taiex_point_analytic_diff.csv",
|
|
|
|
nodes=['192.168.0.102', '192.168.0.109', '192.168.0.106']) #, depends=[hofts, ifts])
|
|
|
|
|
2017-04-06 06:45:11 +04:00
|
|
|
#bchmk.testa(taiex,[10,20],partitioners=[Grid.GridPartitioner], nodes=['192.168.0.109', '192.168.0.101'])
|
2017-04-01 19:19:37 +04:00
|
|
|
|
|
|
|
#parallel_util.explore_partitioners(taiex,20)
|
2017-04-01 03:34:12 +04:00
|
|
|
|
|
|
|
#nasdaqpd = pd.read_csv("DataSets/NASDAQ_IXIC.csv", sep=",")
|
|
|
|
#nasdaq = np.array(nasdaqpd["avg"][:5000])
|
2017-03-03 15:53:55 +04:00
|
|
|
|
|
|
|
#taiex = pd.read_csv("DataSets/TAIEX.csv", sep=",")
|
|
|
|
#taiex_treino = np.array(taiex["avg"][2500:3900])
|
|
|
|
#taiex_teste = np.array(taiex["avg"][3901:4500])
|
2017-02-27 22:53:29 +04:00
|
|
|
|
|
|
|
#print(len(taiex))
|
|
|
|
|
2017-02-24 20:29:55 +04:00
|
|
|
#from pyFTS.common import Util
|
|
|
|
|
2017-02-27 22:53:29 +04:00
|
|
|
#, ,
|
|
|
|
|
2017-04-06 06:45:11 +04:00
|
|
|
#diff = Transformations.Differential(1)
|
2017-03-03 15:53:55 +04:00
|
|
|
|
|
|
|
|
2017-03-22 06:17:06 +04:00
|
|
|
#bchmk.external_point_sliding_window([naive.Naive, arima.ARIMA, arima.ARIMA, arima.ARIMA, arima.ARIMA, arima.ARIMA, arima.ARIMA],
|
|
|
|
# [None, (1,0,0),(1,1,0),(2,0,0), (2,1,0), (1,1,1), (1,0,1)],
|
|
|
|
# gauss,2000,train=0.8, dump=True, save=True, file="experiments/arima_gauss.csv")
|
2017-03-03 15:53:55 +04:00
|
|
|
|
2017-02-27 22:53:29 +04:00
|
|
|
|
2017-05-07 00:04:37 +04:00
|
|
|
#bchmk.interval_sliding_window(gauss,2000,train=0.8, #transformation=diff, #models=[pwfts.ProbabilisticWeightedFTS], # #
|
|
|
|
# partitioners=[Grid.GridPartitioner], #Entropy.EntropyPartitioner], # FCM.FCMPartitioner, ],
|
|
|
|
# partitions= np.arange(10,200,step=5), #
|
|
|
|
# dump=True, save=False, file="experiments/nasdaq_interval.csv")
|
2017-03-22 06:17:06 +04:00
|
|
|
|
|
|
|
#3bchmk.ahead_sliding_window(taiex,2000,train=0.8, steps=20, resolution=250, #transformation=diff, #models=[pwfts.ProbabilisticWeightedFTS], # #
|
|
|
|
# partitioners=[Grid.GridPartitioner], #Entropy.EntropyPartitioner], # FCM.FCMPartitioner, ],
|
|
|
|
# partitions= np.arange(10,200,step=10), #
|
|
|
|
# dump=True, save=True, file="experiments/taiex_ahead.csv")
|
2017-02-27 22:53:29 +04:00
|
|
|
|
|
|
|
|
2017-03-03 15:53:55 +04:00
|
|
|
#bchmk.allPointForecasters(taiex_treino, taiex_treino, 95, #transformation=diff,
|
|
|
|
# models=[ naive.Naive, pfts.ProbabilisticFTS, pwfts.ProbabilisticWeightedFTS],
|
|
|
|
# statistics=True, residuals=False, series=False)
|
2017-02-27 22:53:29 +04:00
|
|
|
|
2017-03-22 06:17:06 +04:00
|
|
|
#data_train_fs = Grid.GridPartitioner(nasdaq[:1600], 95).sets
|
2017-02-27 22:53:29 +04:00
|
|
|
|
2017-03-22 06:17:06 +04:00
|
|
|
#fts1 = pwfts.ProbabilisticWeightedFTS("")
|
2017-03-03 15:53:55 +04:00
|
|
|
#fts1.appendTransformation(diff)
|
2017-03-22 06:17:06 +04:00
|
|
|
#fts1.train(nasdaq[:1600], data_train_fs, order=1)
|
|
|
|
|
|
|
|
#_crps1, _crps2, _t1, _t2 = bchmk.get_distribution_statistics(nasdaq[1600:2000], fts1, steps=20, resolution=200)
|
|
|
|
|
|
|
|
#print(_crps1, _crps2, _t1, _t2)
|
2017-02-27 22:53:29 +04:00
|
|
|
|
2017-03-03 15:53:55 +04:00
|
|
|
#print(fts1.forecast([5000, 5000]))
|
2017-02-27 22:53:29 +04:00
|
|
|
|
2017-03-03 15:53:55 +04:00
|
|
|
#fts2 = pwfts.ProbabilisticWeightedFTS("")
|
|
|
|
#fts2.appendTransformation(diff)
|
|
|
|
#fts2.train(taiex_treino, data_train_fs, order=1)
|
2017-02-27 22:53:29 +04:00
|
|
|
|
2017-03-03 15:53:55 +04:00
|
|
|
#print(fts2.forecast([5000, 5000]))
|
2017-02-27 22:53:29 +04:00
|
|
|
|
2017-02-24 20:29:55 +04:00
|
|
|
|
2017-02-27 22:53:29 +04:00
|
|
|
#tmp = Grid.GridPartitioner(taiex_treino,7,transformation=diff)
|
2017-02-24 20:29:55 +04:00
|
|
|
|
2017-02-27 22:53:29 +04:00
|
|
|
#for s in tmp.sets: print(s)
|