LeeDoYup / RobustSTL

Unofficial Implementation of RobustSTL: A Robust Seasonal-Trend Decomposition Algorithm for Long Time Series (AAAI 2019)
MIT License
271 stars 53 forks source link

Is there any way currently to deal with trendy only signal ? #3

Closed mamadyonline closed 5 years ago

mamadyonline commented 5 years ago

Not all signals have necessarily a seasonal component, some might be only trendy and in this case how do we go about setting the parameter?

For example, what are the right settings for the classical airline passengers data set? I tried 12 as the seasonal_length, running the robustSTL confounds trend and seasonality !

LeeDoYup commented 5 years ago

(In my opiniton) if you have no seasonality, 1) Set season_len to enough length (about 12 if monthly) 2) Remove seasonal extraction parts (https://github.com/LeeDoYup/RobustSTL/blob/master/RobustSTL.py#L41-L58)

def seasonality_extraction(sample, season_len=10, K=2, H=5, ds1=50., ds2=1.):
    '''
    sample_len = len(sample)
    idx_list = np.arange(sample_len)

    def get_season_value(idx):
        idxs = get_season_idx(sample_len, idx, season_len, K, H)
        if idxs.size == 0:
            return sample[idx]

        weight_sample = sample[idxs]
        #t_idxs = [idx - (int((idx -j)/season_len)+1)*season_len for j in idxs]
        #weights = np.array(list(map(lambda j, t: bilateral_filter(j, t, sample[j], sample[t], ds1, ds2), idxs, t_idxs)))
        weights = np.array(list(map(lambda j: bilateral_filter(j, idx, sample[j], sample[idx], ds1, ds2), idxs)))
        season_value = np.sum(weight_sample * weights)/np.sum(weights)
        return season_value

    seasons_tilda = np.array(list(map(get_season_value, idx_list)))
    '''
    return np.zeros(np.shape(sample))