From aa721c912fff82826af635d983e2cc5e1e6443a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=C3=B4nio=20C=C3=A2ndido?= Date: Mon, 20 May 2019 11:27:59 -0300 Subject: [PATCH] Split ifts.IntervalFTS(HighOrderFTS) from WeightedIntervalFTS(WeightedHighOrderFTS) --- pyFTS/models/ifts.py | 78 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/pyFTS/models/ifts.py b/pyFTS/models/ifts.py index 0826159..1f1e267 100644 --- a/pyFTS/models/ifts.py +++ b/pyFTS/models/ifts.py @@ -13,7 +13,7 @@ from pyFTS.common import FuzzySet, FLR, fts, tree from pyFTS.models import hofts -class IntervalFTS(hofts.WeightedHighOrderFTS): +class IntervalFTS(hofts.HighOrderFTS): """ High Order Interval Fuzzy Time Series """ @@ -87,3 +87,79 @@ class IntervalFTS(hofts.WeightedHighOrderFTS): ret.append([lo_, up_]) return ret + + +class WeightedIntervalFTS(hofts.WeightedHighOrderFTS): + """ + Weighted High Order Interval Fuzzy Time Series + """ + def __init__(self, **kwargs): + super(IntervalFTS, self).__init__(**kwargs) + self.shortname = "IFTS" + self.name = "Interval FTS" + self.detail = "Silva, P.; GuimarĂ£es, F.; Sadaei, H. (2016)" + self.flrgs = {} + self.has_point_forecasting = False + self.has_interval_forecasting = True + self.is_high_order = True + self.min_order = 1 + + def get_upper(self, flrg): + ret = np.nan + if len(flrg.LHS) > 0: + if flrg.get_key() in self.flrgs: + tmp = self.flrgs[flrg.get_key()] + ret = tmp.get_upper(self.sets) + else: + ret = self.sets[flrg.LHS[-1]].upper + return ret + + def get_lower(self, flrg): + ret = np.nan + if len(flrg.LHS) > 0: + if flrg.get_key() in self.flrgs: + tmp = self.flrgs[flrg.get_key()] + ret = tmp.get_lower(self.partitioner.sets) + else: + ret = self.partitioner.sets[flrg.LHS[-1]].lower + return ret + + def get_sequence_membership(self, data, fuzzySets): + mb = [fuzzySets[k].membership(data[k]) for k in np.arange(0, len(data))] + return mb + + + def forecast_interval(self, ndata, **kwargs): + + ret = [] + + l = len(ndata) + + if l <= self.order: + return ndata + + for k in np.arange(self.max_lag, l+1): + + sample = ndata[k - self.max_lag: k] + + flrgs = self.generate_lhs_flrg(sample) + + up = [] + lo = [] + affected_flrgs_memberships = [] + + for flrg in flrgs: + if len(flrg.LHS) > 0: + + mv = flrg.get_membership(sample, self.sets) + up.append(mv * self.get_upper(flrg)) + lo.append(mv * self.get_lower(flrg)) + affected_flrgs_memberships.append(mv) + + # gerar o intervalo + norm = sum(affected_flrgs_memberships) + lo_ = sum(lo) / norm + up_ = sum(up) / norm + ret.append([lo_, up_]) + + return ret \ No newline at end of file