time series bottom up segmentation code 