Replacing references to FuzzySet.fuzzyfy to Partitioner.fuzzyfy

This commit is contained in:
Petrônio Cândido 2019-04-09 16:06:04 -03:00
parent d3fa1ea534
commit 0e67b7bc61
3 changed files with 16 additions and 9 deletions

View File

@ -43,7 +43,7 @@ class MultivariateFuzzySet(Composite.FuzzySet):
def fuzzyfy_instance(data_point, var, tuples=True): 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: if tuples:
return [(var.name, fs) for fs in fsets] return [(var.name, fs) for fs in fsets]
else: else:

View File

@ -142,6 +142,7 @@ class Partitioner(object):
ret = [] ret = []
for inst in data: for inst in data:
mv = self.fuzzyfy(inst, **kwargs) mv = self.fuzzyfy(inst, **kwargs)
ret.append(mv)
return ret return ret
alpha_cut = kwargs.get('alpha_cut', 0.) alpha_cut = kwargs.get('alpha_cut', 0.)
@ -157,6 +158,7 @@ class Partitioner(object):
mv[ix] = tmp if tmp >= alpha_cut else 0. mv[ix] = tmp if tmp >= alpha_cut else 0.
ix = np.ravel(np.argwhere(mv > 0.)) ix = np.ravel(np.argwhere(mv > 0.))
if ix.size == 0: if ix.size == 0:
mv[self.check_bounds(data)] = 1. mv[self.check_bounds(data)] = 1.
@ -170,6 +172,10 @@ class Partitioner(object):
mx = max(mv) mx = max(mv)
ix = np.ravel(np.argwhere(mv == mx)) ix = np.ravel(np.argwhere(mv == mx))
return self.ordered_sets[ix[0]] 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): def check_bounds(self, data):
if data < self.min: if data < self.min:

View File

@ -11,19 +11,20 @@ import pandas as pd
from pyFTS.common import Util as cUtil, FuzzySet from pyFTS.common import Util as cUtil, FuzzySet
from pyFTS.partitioners import Grid, Entropy, Util as pUtil, Simple from pyFTS.partitioners import Grid, Entropy, Util as pUtil, Simple
from pyFTS.benchmarks import benchmarks as bchmk, Measures 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.common import Transformations, Membership
from pyFTS.data import TAIEX 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) test = [2000, 5000, 5500, 12000]
print(tmp)
tmp = fs.fuzzyfy(5500, method='fuzzy', alpha_cut=0.3)
print(tmp)
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))