From c8f4513f5e82ba12d547c270657f6da5ee3ff471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=C3=B4nio=20C=C3=A2ndido=20de=20Lima=20e=20Silva?= Date: Thu, 27 Jan 2022 10:24:32 -0300 Subject: [PATCH] Improvement: New function highorder_fuzzy_markov_chain that return the fuzzy markov chain (prior probability vector and transition matrix) of a PWFTS model --- pyFTS/models/pwfts.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/pyFTS/models/pwfts.py b/pyFTS/models/pwfts.py index 26d68bd..2882dc9 100644 --- a/pyFTS/models/pwfts.py +++ b/pyFTS/models/pwfts.py @@ -661,22 +661,29 @@ class ProbabilisticWeightedFTS(ifts.IntervalFTS): return tmp -def visualize_distributions(model, **kwargs): - import matplotlib.pyplot as plt - from matplotlib import gridspec - import seaborn as sns - +def highorder_fuzzy_markov_chain(model): ordered_sets = model.partitioner.ordered_sets + ftpg_keys = sorted(model.flrgs.keys(), key=lambda x: model.flrgs[x].get_midpoint(model.sets)) - - lhs_probs = [model.flrg_lhs_unconditional_probability(model.flrgs[k]) - for k in ftpg_keys] + + lhs_probs = np.array([model.flrg_lhs_unconditional_probability(model.flrgs[k]) + for k in ftpg_keys]) mat = np.zeros((len(ftpg_keys), len(ordered_sets))) for row, w in enumerate(ftpg_keys): for col, k in enumerate(ordered_sets): if k in model.flrgs[w].RHS: mat[row, col] = model.flrgs[w].rhs_unconditional_probability(k) + + return ftpg_keys, ordered_sets, lhs_probs, mat + + +def visualize_distributions(model, **kwargs): + import matplotlib.pyplot as plt + from matplotlib import gridspec + import seaborn as sns + + ftpg_keys, ordered_sets, lhs_probs, mat = highorder_fuzzy_markov_chain(model) size = kwargs.get('size', (5,10)) @@ -695,3 +702,5 @@ def visualize_distributions(model, **kwargs): ax.set_xticklabels(ordered_sets) ax.grid(True) ax.xaxis.set_tick_params(rotation=90) + +