Bugfixes on nonstationary methods

This commit is contained in:
Petrônio Cândido 2018-04-11 19:07:31 -03:00
parent d980078a8e
commit 858319aca8
5 changed files with 35 additions and 28 deletions

View File

@ -873,6 +873,15 @@ def plot_interval(axis, intervals, order, label, color='red', typeonlegend=False
return [mi, ma]
def plot_point(axis, points, order, label, color='red', ls='-', linewidth=1):
mi = min(points) * 0.95
ma = max(points) * 1.05
for k in np.arange(0, order):
points.insert(0, None)
axis.plot(points, color=color, label=label, ls=ls,linewidth=linewidth)
return [mi, ma]
def plot_compared_series(original, models, colors, typeonlegend=False, save=False, file=None, tam=[20, 5],
points=True, intervals=True, linewidth=1.5):

View File

@ -111,25 +111,17 @@ class NonStationaryFTS(fts.FTS):
tdisp = common.window_index(k + time_displacement, window_size)
if self.method == 'fuzzy':
affected_sets = [[set, set.membership(ndata[k], tdisp)]
for set in self.sets if set.membership(ndata[k], tdisp) > 0.0]
elif self.method == 'maximum':
mv = [set.membership(ndata[k], tdisp) for set in self.sets]
ix = np.ravel(np.argwhere(mv == max(mv)))
affected_sets = [self.sets[x] for x in ix]
affected_sets = [[self.sets[key], self.sets[key].membership(ndata[k], tdisp)]
for key in self.partitioner.ordered_sets
if self.sets[key].membership(ndata[k], tdisp) > 0.0]
if len(affected_sets) == 0:
if self.method == 'fuzzy':
affected_sets.append([common.check_bounds(ndata[k], self.sets, tdisp), 1.0])
else:
affected_sets.append(common.check_bounds(ndata[k], self.sets, tdisp))
affected_sets.append([common.check_bounds(ndata[k], self.partitioner, tdisp), 1.0])
upper = []
lower = []
if len(affected_sets) == 1:
#print(2)
aset = affected_sets[0][0]
if aset.name in self.flrgs:
lower.append(self.flrgs[aset.name].get_lower(tdisp))
@ -139,7 +131,6 @@ class NonStationaryFTS(fts.FTS):
upper.append(aset.get_upper(tdisp))
else:
for aset in affected_sets:
#print(aset)
if aset[0].name in self.flrgs:
lower.append(self.flrgs[aset[0].name].get_lower(tdisp) * aset[1])
upper.append(self.flrgs[aset[0].name].get_upper(tdisp) * aset[1])

View File

@ -15,27 +15,27 @@ def plot_sets(partitioner, start=0, end=10, step=1, tam=[5, 5], colors=None,
fig, axes = plt.subplots(nrows=1, ncols=1, figsize=tam)
for ct, key in enumerate(partitioner.ordered_sets):
set = partitioner.sets[key]
fset = partitioner.sets[key]
if not only_lines:
for t in range:
tdisp = t - (t % window_size)
set.membership(0, tdisp)
param = set.perturbated_parameters[str(tdisp)]
fset.membership(0, tdisp)
param = fset.perturbated_parameters[str(tdisp)]
if set.mf == Membership.trimf:
if fset.mf == Membership.trimf:
if t == start:
line = axes.plot([t, t+1, t], param, label=set.name)
set.metadata['color'] = line[0].get_color()
line = axes.plot([t, t+1, t], param, label=fset.name)
fset.metadata['color'] = line[0].get_color()
else:
axes.plot([t, t + 1, t], param,c=set.metadata['color'])
axes.plot([t, t + 1, t], param,c=fset.metadata['color'])
ticks.extend(["t+"+str(t),""])
else:
tmp = []
for t in range:
tdisp = t - (t % window_size)
set.membership(0, tdisp)
param = set.perturbated_parameters[str(tdisp)]
fset.membership(0, tdisp)
param = fset.perturbated_parameters[str(tdisp)]
tmp.append(np.polyval(param, tdisp))
axes.plot(range, tmp, ls="--", c="blue")

View File

@ -31,25 +31,30 @@ train_split = 2000
test_length = 200
from pyFTS.partitioners import Grid, Util as pUtil
#partitioner = Grid.GridPartitioner(data=dataset[:train_split], npart=30)
partitioner = Grid.GridPartitioner(data=dataset[:train_split], npart=10, transformation=tdiff)
partitioner = Grid.GridPartitioner(data=dataset[:train_split], npart=30)
#partitioner = Grid.GridPartitioner(data=dataset[:train_split], npart=10, transformation=tdiff)
from pyFTS.common import fts,tree
from pyFTS.models import hofts, pwfts
pfts1_taiex = pwfts.ProbabilisticWeightedFTS("1", partitioner=partitioner)
pfts1_taiex.append_transformation(tdiff)
#pfts1_taiex.append_transformation(tdiff)
pfts1_taiex.fit(dataset[:train_split], save_model=True, file_path='pwfts')
pfts1_taiex.shortname = "1st Order"
print(pfts1_taiex)
tmp = pfts1_taiex.predict(dataset[train_split:train_split+20], type='point',
method='heuristic', steps_ahead=10)
tmp = pfts1_taiex.predict(dataset[train_split:train_split+200], type='point',
method='heuristic')
print(tmp)
tmp = pfts1_taiex.predict(dataset[train_split:train_split+200], type='point',
method='expected_value')
print(tmp)
'''

View File

@ -30,3 +30,5 @@ print(fs1)
print(nsfts1.predict(test1))
print(nsfts1)
util.plot_sets(fs1, tam=[10, 5], start=0, end=100, step=2, data=lmv1[:100], window_size=35)