From 55638cbe20035433ab78c2792f9edf08efd8d5cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=C3=B4nio=20C=C3=A2ndido=20de=20Lima=20e=20Silva?= Date: Wed, 19 Apr 2017 19:58:25 -0300 Subject: [PATCH] - Cheng: Trend Weighted FTS --- cheng.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ yu.py | 4 ++-- 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 cheng.py diff --git a/cheng.py b/cheng.py new file mode 100644 index 0000000..5f654ce --- /dev/null +++ b/cheng.py @@ -0,0 +1,47 @@ +import numpy as np +from pyFTS.common import FuzzySet,FLR +from pyFTS import fts, yu + + +class TrendWeightedFLRG(yu.WeightedFTS): + def __init__(self, LHS, **kwargs): + super(TrendWeightedFTS, self).__init__(LHS) + + def weights(self): + count_nochange = 0.0 + count_up = 0.0 + count_down = 0.0 + weights = [] + + for c in self.RHS: + tmp = 0 + if self.RHS.midpoint == c.midpoint: + count_nochange += 1.0 + tmp = count_nochange + elif self.RHS.midpoint > c.midpoint: + count_down += 1.0 + tmp = count_down + else: + count_up += 1.0 + tmp = count_up + weights.append(tmp) + + tot = sum(weights) + return np.array([k / tot for k in weights]) + + +class TrendWeightedFTS(yu.WeightedFTS): + def __init__(self, order, name, **kwargs): + super(TrendWeightedFTS, self).__init__(1, "TWFTS " + name) + self.name = "Trend Weighted FTS" + self.detail = "Cheng" + + def generateFLRG(self, flrs): + flrgs = {} + for flr in flrs: + if flr.LHS.name in flrgs: + flrgs[flr.LHS.name].append(flr.RHS) + else: + flrgs[flr.LHS.name] = TrendWeightedFLRG(flr.LHS); + flrgs[flr.LHS.name].append(flr.RHS) + return (flrgs) \ No newline at end of file diff --git a/yu.py b/yu.py index 11e99f2..ec28296 100644 --- a/yu.py +++ b/yu.py @@ -4,7 +4,7 @@ from pyFTS import fts class WeightedFLRG(fts.FTS): - def __init__(self, order, **kwargs): + def __init__(self, order, LHS, **kwargs): self.LHS = LHS self.RHS = [] self.count = 1.0 @@ -31,7 +31,7 @@ class WeightedFLRG(fts.FTS): class WeightedFTS(fts.FTS): - def __init__(self, order, **kwargs): + def __init__(self, order, name, **kwargs): super(WeightedFTS, self).__init__(1, "WFTS " + name) self.name = "Weighted FTS" self.detail = "Yu"