Early Classification of Time Series. Cost-based Optimization Criterion and Algorithms