Example #1
0
    def __init__(self, **kwargs):
        """
        Even Length Grid Partitioner
        :param seasonality: Time granularity, from pyFTS.models.seasonal.common.DateTime
        :param data: Training data of which the universe of discourse will be extracted. The universe of discourse is the open interval between the minimum and maximum values of the training data.
        :param npart: The number of universe of discourse partitions, i.e., the number of fuzzy sets that will be created
        :param func: Fuzzy membership function (pyFTS.common.Membership)
        """
        super(TimeGridPartitioner, self).__init__(name="TimeGrid",
                                                  preprocess=False,
                                                  **kwargs)

        self.season = kwargs.get('seasonality', DateTime.day_of_year)
        data = kwargs.get('data', None)
        if self.season == DateTime.year:
            ndata = [strip_datepart(k, self.season) for k in data]
            self.min = min(ndata)
            self.max = max(ndata)
        else:
            tmp = (self.season.value / self.partitions) / 2
            self.min = tmp
            self.max = self.season.value + tmp

        self.type = kwargs.get('type', 'seasonal')

        self.sets = self.build(None)

        if self.ordered_sets is None and self.setnames is not None:
            self.ordered_sets = self.setnames
        else:
            self.ordered_sets = FS.set_ordered(self.sets)

        if self.type == 'seasonal':
            self.extractor = lambda x: strip_datepart(x, self.season)
Example #2
0
    def get_season_of_data(self, data):

        ret = []

        if isinstance(data, pd.DataFrame):
            for ix in data.index:
                date = data[self.date_field][ix]
                season = []
                for c, f in enumerate(self.fields, start=0):
                    tmp = common.strip_datepart(date, f)
                    if self.seasons[c] is not None:
                        tmp = tmp // self.seasons[c]
                    season.append(tmp)
                ret.append(season)

        elif isinstance(data, pd.Series):
            date = data[self.date_field]
            season = []
            for c, f in enumerate(self.fields, start=0):
                season.append(common.strip_datepart(date, f, self.seasons[c]))
            ret.append(season)

        return ret
Example #3
0
 def extractor(self, x):
     if self.type == 'seasonal':
         return strip_datepart(x, self.season, self.mask)
     else:
         return x