Early classification of time series based on trend segmentation and optimization cost function