A fast and memory-efficient algorithm for learning and retrieval of phenotypic dynamics in multivariate cohort time series