From bd4c0c432e52844e45a09f6b1ed3bd87a27c0870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=C3=B4nio=20C=C3=A2ndido?= Date: Wed, 13 Jun 2018 10:14:18 -0300 Subject: [PATCH] common.Util.plot_rules bugfix --- pyFTS/common/Util.py | 31 +++++++++++++++++-------------- pyFTS/tests/general.py | 10 +++++++--- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/pyFTS/common/Util.py b/pyFTS/common/Util.py index 6fe5469..1c2ca2b 100644 --- a/pyFTS/common/Util.py +++ b/pyFTS/common/Util.py @@ -22,6 +22,9 @@ def plot_rules(model, size=[5, 5], axis=None, rules_by_axis=None, columns=1): for ct, key in enumerate(_lhs): + xticks = [] + xtickslabels = [] + if rules_by_axis is None: ax = axis else: @@ -31,47 +34,47 @@ def plot_rules(model, size=[5, 5], axis=None, rules_by_axis=None, columns=1): ax = axis[rowcount, colcount] if columns > 1 else axis[rowcount] if ct % rules_by_axis == 0: - xticks = [] - xtickslabels = [] draw_sets_on_axis(ax, model, size) if not model.is_high_order: if key in model.flrgs: + x = (ct % rules_by_axis) + 1 flrg = model.flrgs[key] - orig = model.sets[key].centroid - ax.plot([ct+1],[orig],'o') - xticks.append(ct+1) + y = model.sets[key].centroid + ax.plot([x],[y],'o') + xticks.append(x) xtickslabels.append(key) for rhs in flrg.RHS: dest = model.sets[rhs].centroid - ax.arrow(ct+1.1, orig, 0.8, dest - orig, #length_includes_head=True, + ax.arrow(x+.1, y, 0.8, dest - y, #length_includes_head=True, head_width=0.1, head_length=0.1, shape='full', overhang=0, fc='k', ec='k') else: flrg = model.flrgs[key] - disp = (ct%rules_by_axis)*model.order + 1 + x = (ct%rules_by_axis)*model.order + 1 for ct2, lhs in enumerate(flrg.LHS): - orig = model.sets[lhs].centroid - ax.plot([disp+ct2], [orig], 'o') - xticks.append(disp+ct2) + y = model.sets[lhs].centroid + ax.plot([x+ct2], [y], 'o') + xticks.append(x+ct2) xtickslabels.append(lhs) for ct2 in range(1, model.order): fs1 = flrg.LHS[ct2-1] fs2 = flrg.LHS[ct2] - orig = model.sets[fs1].centroid + y = model.sets[fs1].centroid dest = model.sets[fs2].centroid - ax.plot([disp+ct2-1,disp+ct2], [orig,dest],'-') + ax.plot([x+ct2-1,x+ct2], [y,dest],'-') - orig = model.sets[flrg.LHS[-1]].centroid + y = model.sets[flrg.LHS[-1]].centroid for rhs in flrg.RHS: dest = model.sets[rhs].centroid - ax.arrow(disp + model.order -1 + .1, orig, 0.8, dest - orig, # length_includes_head=True, + ax.arrow(x + model.order -1 + .1, y, 0.8, dest - y, # length_includes_head=True, head_width=0.1, head_length=0.1, shape='full', overhang=0, fc='k', ec='k') ax.set_xticks(xticks) ax.set_xticklabels(xtickslabels) + ax.set_xlim([0,rules_by_axis*model.order+1]) plt.tight_layout() plt.show() diff --git a/pyFTS/tests/general.py b/pyFTS/tests/general.py index 7c6a13a..98487c3 100644 --- a/pyFTS/tests/general.py +++ b/pyFTS/tests/general.py @@ -19,7 +19,7 @@ dataset = TAIEX.get_data() #print(len(dataset)) from pyFTS.partitioners import Grid, Util as pUtil -partitioner = Grid.GridPartitioner(data=dataset[:800], npart=10, transformation=tdiff) +partitioner = Grid.GridPartitioner(data=dataset[:800], npart=10)#, transformation=tdiff) from pyFTS.common import Util as cUtil @@ -30,12 +30,16 @@ from pyFTS.models.ensemble import ensemble #model = chen.ConventionalFTS(partitioner=partitioner) model = hofts.HighOrderFTS(partitioner=partitioner,order=2) -model.append_transformation(tdiff) +#model.append_transformation(tdiff) model.fit(dataset[:800]) +cUtil.plot_rules(model, size=[20,20], rules_by_axis=5, columns=1) + print(model) -cUtil.plot_rules(model, size=[20,20], rules_by_axis=6, columns=1) +print("fim") + + ''' model = knn.KNearestNeighbors(order=3)