def forecast(self, ndata, **kwargs): l = 1 if self.partitioner is not None: ordered_sets = self.partitioner.ordered_sets else: ordered_sets = FuzzySet.set_ordered(self.sets) ndata = np.array(ndata) l = len(ndata) ret = [] for k in np.arange(0, l): actual = FuzzySet.get_maximum_membership_fuzzyset( ndata[k], self.sets, ordered_sets) if actual.name not in self.flrgs: ret.append(actual.centroid) else: flrg = self.flrgs[actual.name] mp = flrg.get_midpoints(self.sets) ret.append(mp.dot(flrg.weights())) return ret
def forecast(self, ndata, **kwargs): explain = kwargs.get('explain',False) l = len(ndata) if not explain else 1 ret = [] for k in np.arange(0, l): actual = FuzzySet.get_maximum_membership_fuzzyset(ndata[k], self.sets) if explain: print("Fuzzyfication:\n\n {} -> {} \n".format(ndata[k], actual.name)) if actual.name not in self.flrgs: ret.append(actual.centroid) if explain: print("Rules:\n\n {} -> {} (Naïve)\t Midpoint: {} \n\n".format(actual.name, actual.name,actual.centroid)) else: _flrg = self.flrgs[actual.name] mp = _flrg.get_midpoint(self.sets) ret.append(mp) if explain: print("Rules:\n\n {} \t Midpoint: {} \n".format(str(_flrg), mp)) print("Deffuzyfied value: {} \n".format(mp)) return ret
def generate_indexed_flrs(sets, indexer, data, transformation=None): """ Create a season-indexed ordered FLR set from a list of fuzzy sets with recurrence :param sets: fuzzy sets :param indexer: seasonality indexer :param data: original data :return: ordered list of FLR """ flrs = [] index = indexer.get_season_of_data(data) ndata = indexer.get_data(data) if transformation is not None: ndata = transformation.apply(ndata) for k in np.arange(1, len(ndata)): lhs = FuzzySet.get_maximum_membership_fuzzyset(ndata[k - 1], sets) rhs = FuzzySet.get_maximum_membership_fuzzyset(ndata[k], sets) season = index[k] flr = IndexedFLR(season, lhs, rhs) flrs.append(flr) return flrs
def forecast(self, ndata, **kwargs): explain = kwargs.get('explain', False) if self.partitioner is not None: ordered_sets = self.partitioner.ordered_sets else: ordered_sets = FuzzySet.set_ordered(self.sets) ndata = np.array(ndata) l = len(ndata) if not explain else 1 ret = [] for k in np.arange(0, l): actual = FuzzySet.get_maximum_membership_fuzzyset( ndata[k], self.sets, ordered_sets) if explain: print("Fuzzyfication:\n\n {} -> {} \n\n".format( ndata[k], actual.name)) if actual.name not in self.flrgs: ret.append(actual.centroid) if explain: print("Rules:\n\n {} -> {} (Naïve)\t Midpoint: {} \n\n". format(actual.name, actual.name, actual.centroid)) else: flrg = self.flrgs[actual.name] mp = flrg.get_midpoints(self.sets) final = mp.dot(flrg.weights(self.sets)) ret.append(final) if explain: print("Rules:\n\n {} \n\n ".format(str(flrg))) print("Midpoints: \n\n {}\n\n".format(mp)) print("Deffuzyfied value: {} \n".format(final)) return ret
def forecast(self, data, **kwargs): ordered_sets = FuzzySet.set_ordered(self.sets) ret = [] index = self.indexer.get_season_of_data(data) ndata = self.indexer.get_data(data) for k in np.arange(0, len(data)): flrg = self.flrgs[str(index[k])] d = FuzzySet.get_maximum_membership_fuzzyset( ndata[k], self.sets, ordered_sets) mp = self.get_midpoints(flrg, d) ret.append(sum(mp) / len(mp)) return ret
def forecast(self, ndata, **kwargs): l = len(ndata) ret = [] for k in np.arange(0, l): mv = FuzzySet.fuzzyfy_instance(ndata[k], self.sets) actual = FuzzySet.get_maximum_membership_fuzzyset( ndata[k], self.sets) #self.sets[np.argwhere(mv == max(mv))[0, 0]] if actual.name not in self.flrgs: ret.append(actual.centroid) else: _flrg = self.flrgs[actual.name] ret.append(_flrg.get_midpoint(self.sets)) return ret