Bugfixes on seasonal and multivariate models

This commit is contained in:
Petrônio Cândido 2018-10-31 10:51:50 -03:00
parent 3f435222ac
commit f8927fd158
4 changed files with 47 additions and 13 deletions

View File

@ -3,7 +3,8 @@ import pandas as pd
from pyFTS.common import FuzzySet
def fuzzyfy_instance(data_point, var):
return FuzzySet.fuzzyfy(data_point, var.partitioner, mode='sets', method='fuzzy', alpha_cut=var.alpha_cut)
fsets = FuzzySet.fuzzyfy(data_point, var.partitioner, mode='sets', method='fuzzy', alpha_cut=var.alpha_cut)
return [(var.name, fs) for fs in fsets]

View File

@ -88,10 +88,15 @@ class FuzzySet(FuzzySet.FuzzySet):
"""
def __init__(self, datepart, name, mf, parameters, centroid, alpha=1.0, **kwargs):
super(FuzzySet, self).__init__(name, mf, parameters, centroid, alpha, type = 'datetime', **kwargs)
super(FuzzySet, self).__init__(name, mf, parameters, centroid, alpha,
type=kwargs.get('type', 'datetime'),
**kwargs)
self.datepart = datepart
self.type = 'seasonal'
def membership(self, x):
if self.type == 'datetime':
dp = strip_datepart(x, self.datepart)
else:
dp = x
return self.mf(dp, self.parameters) * self.alpha

View File

@ -64,6 +64,17 @@ class TimeGridPartitioner(partitioner.Partitioner):
**kwargs))
tmp.centroid = c
sets[set_name] = tmp
elif c == self.max - partlen:
tmp = Composite(set_name, superset=True)
tmp.append_set(FuzzySet(self.season, set_name, Membership.trimf,
[0.0000001, 0.0,
pl2], 0.0, alpha=.5,
**kwargs))
tmp.append_set(FuzzySet(self.season, set_name, Membership.trimf,
[c - partlen, c, c + partlen], c,
**kwargs))
tmp.centroid = c
sets[set_name] = tmp
else:
sets[set_name] = FuzzySet(self.season, set_name, Membership.trimf,
[c - partlen, c, c + partlen], c,

View File

@ -16,21 +16,38 @@ from pyFTS.common import Transformations
tdiff = Transformations.Differential(1)
data = pd.read_csv('/home/petronio/Downloads/priceHong').values
dataset = pd.read_csv('/home/petronio/Downloads/priceHong')
dataset['hour'] = dataset.index.values % 24
split = 24 * 800
train = data[:split].flatten()
test = data[split:].flatten()
#train = data[:split].flatten()
#test = data[split:].flatten()
print(train)
#print(train)
fs_grid = Grid.GridPartitioner(data=train,npart=25)
#fs_entr.plot(ax[1])
from pyFTS.models.multivariate import common, variable, mvfts
from pyFTS.partitioners import Grid
from pyFTS.models.seasonal.common import DateTime
from pyFTS.models.seasonal import partitioner as seasonal
for method in [hofts.HighOrderFTS, pwfts.ProbabilisticWeightedFTS]:
for order in [2,3]:
model = method(partitioner=fs_grid, order=order)
model.fit(train)
vhour = variable.Variable("Hour", data_label="hour", partitioner=seasonal.TimeGridPartitioner, npart=24,
data=dataset, partitioner_specific={'seasonality': DateTime.hour_of_day, 'type': 'common'})
vprice = variable.Variable("Price", data_label="price", partitioner=Grid.GridPartitioner, npart=25,
data=dataset)
fig, ax = plt.subplots(nrows=2, ncols=1,figsize=[15,5])
vhour.partitioner.plot(ax[0])
vprice.partitioner.plot(ax[1])
model = mvfts.MVFTS()
#model.shortname += ' ' + key
model.append_variable(vhour)
model.append_variable(vprice)
# model.shortname += ' ' + w
model.target_variable = vprice
model.fit(dataset.iloc[:split])
'''
from pyFTS.data import TAIEX, SP500, NASDAQ