2017-01-14 03:42:00 +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
|
|
|
|
from pyFTS.partitioners import Grid
|
2017-01-30 03:59:50 +04:00
|
|
|
from pyFTS.common import FLR,FuzzySet,Membership,Transformations
|
2017-02-22 23:18:15 +04:00
|
|
|
from pyFTS import fts,hofts,ifts,pwfts,tree, chen
|
2017-01-14 03:42:00 +04:00
|
|
|
from pyFTS.benchmarks import benchmarks as bchmk
|
2017-02-01 20:54:37 +04:00
|
|
|
from pyFTS.benchmarks import Measures
|
|
|
|
from numpy import random
|
|
|
|
|
2017-02-16 17:54:37 +04:00
|
|
|
#gauss_treino = random.normal(0,1.0,1600)
|
|
|
|
#gauss_teste = random.normal(0,1.0,400)
|
2017-01-14 03:42:00 +04:00
|
|
|
|
|
|
|
|
|
|
|
os.chdir("/home/petronio/dados/Dropbox/Doutorado/Disciplinas/AdvancedFuzzyTimeSeriesModels/")
|
|
|
|
|
2017-02-01 20:54:37 +04:00
|
|
|
#enrollments = pd.read_csv("DataSets/Enrollments.csv", sep=";")
|
|
|
|
#enrollments = np.array(enrollments["Enrollments"])
|
|
|
|
|
2017-02-16 17:54:37 +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-01-14 03:42:00 +04:00
|
|
|
|
2017-02-01 20:54:37 +04:00
|
|
|
#nasdaq = pd.read_csv("DataSets/NASDAQ_IXIC.csv", sep=",")
|
|
|
|
#nasdaq_treino = np.array(nasdaq["avg"][0:1600])
|
|
|
|
#nasdaq_teste = np.array(nasdaq["avg"][1601:2000])
|
2017-01-30 03:59:50 +04:00
|
|
|
|
2017-02-01 20:54:37 +04:00
|
|
|
diff = Transformations.Differential(1)
|
|
|
|
|
2017-02-16 17:54:37 +04:00
|
|
|
fs = Grid.GridPartitionerTrimf(taiex_treino,10)
|
2017-01-24 16:40:48 +04:00
|
|
|
|
|
|
|
#tmp = chen.ConventionalFTS("")
|
2017-01-14 03:42:00 +04:00
|
|
|
|
2017-02-22 23:18:15 +04:00
|
|
|
pfts1 = pwfts.ProbabilisticWeightedFTS("1")
|
2017-01-30 03:59:50 +04:00
|
|
|
#pfts1.appendTransformation(diff)
|
2017-02-16 17:54:37 +04:00
|
|
|
pfts1.train(taiex_treino,fs,1)
|
|
|
|
|
|
|
|
from pyFTS.benchmarks import ProbabilityDistribution as dist
|
|
|
|
|
|
|
|
forecasts = pfts1.forecast(taiex_treino)
|
|
|
|
|
2017-02-19 08:02:59 +04:00
|
|
|
pmf1 = dist.ProbabilityDistribution("Original",100,[min(taiex_treino),max(taiex_treino)],data=taiex_treino)
|
2017-02-16 17:54:37 +04:00
|
|
|
|
2017-02-19 08:02:59 +04:00
|
|
|
#print(pmf1.entropy())
|
|
|
|
|
|
|
|
pmf2 = dist.ProbabilityDistribution("Original",100,[min(taiex_treino),max(taiex_treino)],data=forecasts)
|
|
|
|
|
|
|
|
#print(pmf2.entropy())
|
|
|
|
|
|
|
|
#print(pmf2.kullbackleiblerdivergence(pmf1))
|
|
|
|
|
|
|
|
#print(pmf2.crossentropy(pmf1))
|
|
|
|
|
|
|
|
print(pmf1.averageloglikelihood(taiex_treino))
|
|
|
|
|
|
|
|
print(pmf2.averageloglikelihood(taiex_treino))
|
2017-02-16 17:54:37 +04:00
|
|
|
|
2017-02-22 23:18:15 +04:00
|
|
|
#pfts2 = pfts.ProbabilisticWeightedFTS("n = 2")
|
2017-02-01 20:54:37 +04:00
|
|
|
#pfts2.appendTransformation(diff)
|
2017-02-16 17:54:37 +04:00
|
|
|
#pfts2.train(gauss_treino,fs,2)
|
2017-02-01 20:54:37 +04:00
|
|
|
|
2017-02-22 23:18:15 +04:00
|
|
|
#pfts3 = pfts.ProbabilisticWeightedFTS("n = 3")
|
2017-02-01 20:54:37 +04:00
|
|
|
#pfts3.appendTransformation(diff)
|
2017-02-15 05:01:44 +04:00
|
|
|
#pfts3.train(gauss_treino,fs,3)
|
2017-02-01 20:54:37 +04:00
|
|
|
|
2017-02-15 05:01:44 +04:00
|
|
|
#densities1 = pfts1.forecastAheadDistribution(gauss_teste[:50],2,1.50, parameters=2)
|
2017-02-01 20:54:37 +04:00
|
|
|
|
|
|
|
#print(bchmk.getDistributionStatistics(gauss_teste[:50], [pfts1,pfts2,pfts3], 20, 1.50))
|
|
|
|
|
2017-02-15 05:01:44 +04:00
|
|
|
|
|
|
|
|
2017-01-14 03:42:00 +04:00
|
|
|
|
|
|
|
|