- Bugfixes caused by FLRG improvements and refactorings on affected classes
This commit is contained in:
parent
04b1ffea85
commit
ce71dc20cb
@ -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]
|
||||
|
||||
|
@ -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()])
|
||||
|
@ -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"
|
||||
|
@ -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):
|
||||
|
@ -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."
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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,
|
||||
|
@ -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])
|
||||
|
||||
|
@ -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=";")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user