diff --git a/pyFTS/ensemble/ensemble.py b/pyFTS/ensemble/ensemble.py index d7814f3..f84d0fd 100644 --- a/pyFTS/ensemble/ensemble.py +++ b/pyFTS/ensemble/ensemble.py @@ -6,12 +6,12 @@ import pandas as pd import math from operator import itemgetter from pyFTS.common import FLR, FuzzySet, SortedCollection -from pyFTS import fts, chen, cheng, hofts, hwang, ismailefendi, sadaei, song, yu, sfts +from pyFTS import fts, chen, cheng, hofts, hwang, ismailefendi, sadaei, song, yu from pyFTS.benchmarks import arima, quantreg from pyFTS.common import Transformations import scipy.stats as st from pyFTS import tree -from pyFTS.models import msfts +from pyFTS.seasonal import sfts, msfts from pyFTS.probabilistic import ProbabilityDistribution, kde def sampler(data, quantiles): @@ -226,7 +226,7 @@ class EnsembleFTS(fts.FTS): class AllMethodEnsembleFTS(EnsembleFTS): - def __init__(self, name, **kwargs): + def __init__(self, **kwargs): super(AllMethodEnsembleFTS, self).__init__(name="Ensemble FTS", **kwargs) self.min_order = 3 @@ -239,7 +239,7 @@ class AllMethodEnsembleFTS(EnsembleFTS): self.original_min = min(data) fo_methods = [song.ConventionalFTS, chen.ConventionalFTS, yu.WeightedFTS, cheng.TrendWeightedFTS, - sadaei.ExponentialyWeightedFTS, ismailefendi.ImprovedWeightedFTS, sfts.SeasonalFTS] + sadaei.ExponentialyWeightedFTS, ismailefendi.ImprovedWeightedFTS] ho_methods = [hofts.HighOrderFTS, hwang.HighOrderFTS] diff --git a/pyFTS/flrg.py b/pyFTS/flrg.py index 6bcbf16..8151bc1 100644 --- a/pyFTS/flrg.py +++ b/pyFTS/flrg.py @@ -17,7 +17,7 @@ class FLRG(object): return self.midpoint def get_midpoints(self): - if isinstance(self.RHS, list): + if isinstance(self.RHS, (list, set)): return np.array([s.centroid for s in self.RHS]) elif isinstance(self.RHS, dict): return np.array([self.RHS[s].centroid for s in self.RHS.keys()]) diff --git a/pyFTS/hofts.py b/pyFTS/hofts.py index 7a12962..892d1de 100644 --- a/pyFTS/hofts.py +++ b/pyFTS/hofts.py @@ -49,7 +49,7 @@ class HighOrderFLRG(flrg.FLRG): class HighOrderFTS(fts.FTS): """Conventional High Order Fuzzy Time Series""" def __init__(self, name, **kwargs): - super(HighOrderFTS, self).__init__(name="HOFTS" + name, **kwargs) + super(HighOrderFTS, self).__init__(1, name="HOFTS" + name, **kwargs) self.name = "High Order FTS" self.shortname = "HOFTS" + name self.detail = "Chen" diff --git a/pyFTS/ismailefendi.py b/pyFTS/ismailefendi.py index 27a49e9..b961bf7 100644 --- a/pyFTS/ismailefendi.py +++ b/pyFTS/ismailefendi.py @@ -16,25 +16,27 @@ class ImprovedWeightedFLRG(flrg.FLRG): super(ImprovedWeightedFLRG, self).__init__(1, **kwargs) self.LHS = LHS self.RHS = {} + self.rhs_counts = {} self.count = 0.0 def append(self, c): if c.name not in self.RHS: - self.RHS[c.name] = 1.0 + self.RHS[c.name] = c + self.rhs_counts[c.name] = 1.0 else: - self.RHS[c.name] = self.RHS[c.name] + 1.0 - self.count = self.count + 1.0 + self.rhs_counts[c.name] += 1.0 + self.count += 1.0 def weights(self): - return np.array([self.RHS[c] / self.count for c in self.RHS.keys()]) + return np.array([self.rhs_counts[c] / self.count for c in self.RHS.keys()]) def __str__(self): tmp = self.LHS.name + " -> " tmp2 = "" - for c in sorted(self.RHS): + for c in sorted(self.RHS.keys()): if len(tmp2) > 0: tmp2 = tmp2 + "," - tmp2 = tmp2 + c + "(" + str(round(self.RHS[c] / self.count, 3)) + ")" + tmp2 = tmp2 + c + "(" + str(round(self.rhs_counts[c] / self.count, 3)) + ")" return tmp + tmp2 def __len__(self): diff --git a/pyFTS/pwfts.py b/pyFTS/pwfts.py index 3412719..382c598 100644 --- a/pyFTS/pwfts.py +++ b/pyFTS/pwfts.py @@ -73,15 +73,15 @@ class ProbabilisticWeightedFLRG(hofts.HighOrderFLRG): return self.Z def get_midpoint(self): - return sum(np.array([self.get_RHSprobability(s.name) * self.RHS[s].centroid + return sum(np.array([self.get_RHSprobability(s) * self.RHS[s].centroid for s in self.RHS.keys()])) def get_upper(self): - return sum(np.array([self.get_RHSprobability(s.name) * self.RHS[s].upper + return sum(np.array([self.get_RHSprobability(s) * self.RHS[s].upper for s in self.RHS.keys()])) def get_lower(self): - return sum(np.array([self.get_RHSprobability(s.name) * self.RHS[s].lower + return sum(np.array([self.get_RHSprobability(s) * self.RHS[s].lower for s in self.RHS.keys()])) def __str__(self): @@ -96,7 +96,7 @@ class ProbabilisticWeightedFLRG(hofts.HighOrderFLRG): class ProbabilisticWeightedFTS(ifts.IntervalFTS): """High Order Probabilistic Weighted Fuzzy Time Series""" def __init__(self, name, **kwargs): - super(ProbabilisticWeightedFTS, self).__init__(order=1, name=name, **kwargs) + super(ProbabilisticWeightedFTS, self).__init__(name=name, **kwargs) self.shortname = "PWFTS " + name self.name = "Probabilistic FTS" self.detail = "Silva, P.; GuimarĂ£es, F.; Sadaei, H." diff --git a/pyFTS/sadaei.py b/pyFTS/sadaei.py index 8deb8c7..b7c393b 100644 --- a/pyFTS/sadaei.py +++ b/pyFTS/sadaei.py @@ -59,7 +59,7 @@ class ExponentialyWeightedFTS(fts.FTS): if flr.LHS.name in flrgs: flrgs[flr.LHS.name].append(flr.RHS) else: - flrgs[flr.LHS.name] = ExponentialyWeightedFLRG(flr.LHS, c); + flrgs[flr.LHS.name] = ExponentialyWeightedFLRG(flr.LHS, c=c); flrgs[flr.LHS.name].append(flr.RHS) return (flrgs) diff --git a/pyFTS/seasonal/msfts.py b/pyFTS/seasonal/msfts.py index 1ca980e..cf32b73 100644 --- a/pyFTS/seasonal/msfts.py +++ b/pyFTS/seasonal/msfts.py @@ -1,6 +1,6 @@ import numpy as np from pyFTS.common import FuzzySet,FLR -from pyFTS import fts, sfts +from pyFTS.seasonal import sfts class MultiSeasonalFTS(sfts.SeasonalFTS): diff --git a/pyFTS/tests/ensemble.py b/pyFTS/tests/ensemble.py index 0787dd7..672bb56 100644 --- a/pyFTS/tests/ensemble.py +++ b/pyFTS/tests/ensemble.py @@ -11,11 +11,12 @@ from mpl_toolkits.mplot3d import Axes3D import pandas as pd from pyFTS.partitioners import Grid, Entropy, FCM, Huarng from pyFTS.common import FLR,FuzzySet,Membership,Transformations -from pyFTS import fts,hofts,ifts,pwfts,tree, chen, ensemble, song, yu, cheng, ismailefendi, sadaei, hwang +from pyFTS import fts,hofts,ifts,pwfts,tree, chen, song, yu, cheng, ismailefendi, sadaei, hwang from pyFTS.benchmarks import naive, arima from numpy import random from pyFTS.benchmarks import benchmarks as bchmk from pyFTS.benchmarks import arima, quantreg, Measures +from pyFTS.ensemble import ensemble os.chdir("/home/petronio/dados/Dropbox/Doutorado/Codigos/") @@ -24,7 +25,6 @@ diff = Transformations.Differential(1) passengers = pd.read_csv("DataSets/AirPassengers.csv", sep=",") passengers = np.array(passengers["Passengers"]) - e = ensemble.AllMethodEnsembleFTS(alpha=0.25, point_method="median", interval_method='quantile') fo_methods = [song.ConventionalFTS, chen.ConventionalFTS, yu.WeightedFTS, cheng.TrendWeightedFTS, sadaei.ExponentialyWeightedFTS, diff --git a/pyFTS/tests/pwfts.py b/pyFTS/tests/pwfts.py index e2c9eaf..eadc68c 100644 --- a/pyFTS/tests/pwfts.py +++ b/pyFTS/tests/pwfts.py @@ -54,6 +54,12 @@ pfts1.shortname = "1st Order" #print(pfts1_enrollments) +tmp = pfts1.forecast(data[3000:3020]) + +tmp = pfts1.forecastInterval(data[3000:3020]) + +tmp = pfts1.forecastAheadInterval(data[3000:3020],20) + tmp = pfts1.forecastAheadDistribution(data[3000:3020],20, method=3, h=0.45, kernel="gaussian") print(tmp[0]) diff --git a/pyFTS/tests/sfts.py b/pyFTS/tests/sfts.py index 87d649d..92d7d63 100644 --- a/pyFTS/tests/sfts.py +++ b/pyFTS/tests/sfts.py @@ -13,12 +13,12 @@ import datetime import pandas as pd from pyFTS.partitioners import Grid, CMeans, FCM, Entropy from pyFTS.common import FLR,FuzzySet,Membership,Transformations,Util -from pyFTS import fts,sfts -from pyFTS.models import msfts +from pyFTS import fts +from pyFTS.seasonal import sfts, msfts from pyFTS.benchmarks import benchmarks as bchmk from pyFTS.benchmarks import Measures -os.chdir("/home/petronio/dados/Dropbox/Doutorado/Disciplinas/AdvancedFuzzyTimeSeriesModels/") +os.chdir("/home/petronio/dados/Dropbox/Doutorado/Codigos/") sonda = pd.read_csv("DataSets/SONDA_BSB_MOD.csv", sep=";")