Pattern Discovery in Time Series, Part I: Theory, Algorithm, Analysis, and Convergence