From a0468d0feddf12aac07ffc1a950dc7249a35d0b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=C3=B4nio=20C=C3=A2ndido?= Date: Sun, 23 Jun 2019 11:51:40 -0300 Subject: [PATCH] Several bugfixes and improvements in pwfts and ProbabilityDistribution --- pyFTS/common/flrg.py | 10 +++------- pyFTS/models/pwfts.py | 2 +- pyFTS/probabilistic/ProbabilityDistribution.py | 3 ++- pyFTS/tests/general.py | 7 +++---- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/pyFTS/common/flrg.py b/pyFTS/common/flrg.py index 93b2788..a40d037 100644 --- a/pyFTS/common/flrg.py +++ b/pyFTS/common/flrg.py @@ -37,13 +37,9 @@ class FLRG(object): self.key = "" for n in names: - try: - if len(self.key) > 0: - self.key += "," - self.key += n - except Exception as ex: - print(self.key, n) - raise ex + if len(self.key) > 0: + self.key += "," + self.key += n return self.key def get_membership(self, data, sets): diff --git a/pyFTS/models/pwfts.py b/pyFTS/models/pwfts.py index a7ddbda..2f706bf 100644 --- a/pyFTS/models/pwfts.py +++ b/pyFTS/models/pwfts.py @@ -171,7 +171,7 @@ class ProbabilisticWeightedFTS(ifts.IntervalFTS): return np.nanprod(vals) def generate_lhs_flrg(self, sample, explain=False): - if not isinstance(sample, (list, np.ndarray)): + if not isinstance(sample, (tuple, list, np.ndarray)): sample = [sample] nsample = [self.partitioner.fuzzyfy(k, mode="sets", alpha_cut=self.alpha_cut) diff --git a/pyFTS/probabilistic/ProbabilityDistribution.py b/pyFTS/probabilistic/ProbabilityDistribution.py index 51e0854..452c6cb 100644 --- a/pyFTS/probabilistic/ProbabilityDistribution.py +++ b/pyFTS/probabilistic/ProbabilityDistribution.py @@ -211,7 +211,8 @@ class ProbabilityDistribution(object): for val in values: try: k = self.bin_index.find_ge(val) - ret.append(self.cdf[k]) + #ret.append(self.cdf[k]) + ret.append(self.cdf[val]) except: ret.append(np.nan) else: diff --git a/pyFTS/tests/general.py b/pyFTS/tests/general.py index daab88f..69a96c7 100644 --- a/pyFTS/tests/general.py +++ b/pyFTS/tests/general.py @@ -32,16 +32,15 @@ fs = Grid.GridPartitioner(data=train, npart=45) model = pwfts.ProbabilisticWeightedFTS(partitioner=fs, order=1) model.fit(train) - +horizon = 10 +''' forecasts = model.predict(test[9:20], type='point') intervals = model.predict(test[9:20], type='interval') distributions = model.predict(test[9:20], type='distribution') - -horizon = 10 - forecasts = model.predict(test[9:20], type='point', steps_ahead=horizon) intervals = model.predict(test[9:20], type='interval', steps_ahead=horizon) +''' distributions = model.predict(test[9:20], type='distribution', steps_ahead=horizon)