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

Hi,DoYup !Function get_relative_trends has bug when sum delta_trends #8

Closed zhoul14 closed 4 years ago

zhoul14 commented 4 years ago

image

def get_relative_trends(delta_trends):
    init_value = np.array([0])
    idxs = np.arange(len(delta_trends))
    relative_trends = np.array(list(map(lambda idx: np.sum(delta_trends[:idx]), idxs)))
    relative_trends = np.concatenate([init_value, relative_trends])
    return relative_trends

The code:

 relative_trends = np.array(list(map(lambda idx: np.sum(delta_trends[:idx]), idxs)))
np.sum(delta_trends[:idx])

should be

np.sum(delta_trends[:idx+1])

Because idxs is [0,1,2,3,4,5.....] when idxs = 0 , np.sum(delta_trends[:idx]) will be zeros, and relative_trends must be [0,0,.....]

The bug would make trend delay one time.

LeeDoYup commented 4 years ago

The index is aligned by

relative_trends = np.concatenate([init_value, relative_trends])