diff --git a/pyFTS/models/multivariate/common.py b/pyFTS/models/multivariate/common.py index 15475c1..45ca204 100644 --- a/pyFTS/models/multivariate/common.py +++ b/pyFTS/models/multivariate/common.py @@ -43,7 +43,7 @@ class MultivariateFuzzySet(Composite.FuzzySet): def fuzzyfy_instance(data_point, var, tuples=True): - fsets = FuzzySet.fuzzyfy(data_point, var.partitioner, mode='sets', method='fuzzy', alpha_cut=var.alpha_cut) + fsets = var.partitioner(data_point, mode='sets', method='fuzzy', alpha_cut=var.alpha_cut) if tuples: return [(var.name, fs) for fs in fsets] else: diff --git a/pyFTS/partitioners/partitioner.py b/pyFTS/partitioners/partitioner.py index 9c70793..2c25a3c 100644 --- a/pyFTS/partitioners/partitioner.py +++ b/pyFTS/partitioners/partitioner.py @@ -142,6 +142,7 @@ class Partitioner(object): ret = [] for inst in data: mv = self.fuzzyfy(inst, **kwargs) + ret.append(mv) return ret alpha_cut = kwargs.get('alpha_cut', 0.) @@ -157,6 +158,7 @@ class Partitioner(object): mv[ix] = tmp if tmp >= alpha_cut else 0. ix = np.ravel(np.argwhere(mv > 0.)) + if ix.size == 0: mv[self.check_bounds(data)] = 1. @@ -170,6 +172,10 @@ class Partitioner(object): mx = max(mv) ix = np.ravel(np.argwhere(mv == mx)) return self.ordered_sets[ix[0]] + elif mode == 'both': + ix = np.ravel(np.argwhere(mv > 0.)) + sets = [(self.ordered_sets[i], mv[i]) for i in ix] + return sets def check_bounds(self, data): if data < self.min: diff --git a/pyFTS/tests/general.py b/pyFTS/tests/general.py index cc3eac3..2bb39c6 100644 --- a/pyFTS/tests/general.py +++ b/pyFTS/tests/general.py @@ -11,19 +11,20 @@ import pandas as pd from pyFTS.common import Util as cUtil, FuzzySet from pyFTS.partitioners import Grid, Entropy, Util as pUtil, Simple from pyFTS.benchmarks import benchmarks as bchmk, Measures -from pyFTS.models import chen, yu, cheng, ismailefendi, hofts, pwfts +from pyFTS.models import chen, yu, cheng, ismailefendi, hofts, pwfts, tsaur, song, sadaei from pyFTS.common import Transformations, Membership from pyFTS.data import TAIEX -fs = Grid.GridPartitioner(data=TAIEX.get_data(), npart=23) +data = TAIEX.get_data() -print(fs.min, fs.max) +fs = Grid.GridPartitioner(data=data, npart=23) -tmp = fs.search(5500) -print(tmp) - -tmp = fs.fuzzyfy(5500, method='fuzzy', alpha_cut=0.3) -print(tmp) +test = [2000, 5000, 5500, 12000] +for method in [yu.WeightedFTS, tsaur.MarkovWeightedFTS, song.ConventionalFTS, sadaei.ExponentialyWeightedFTS, ismailefendi.ImprovedWeightedFTS, + chen.ConventionalFTS, cheng.TrendWeightedFTS, hofts.HighOrderFTS, pwfts.ProbabilisticWeightedFTS]: + model = method(partitioner=fs) + model.fit(data) + print(model.forecast(test))