\section{Introduction}

Unsupervised time series modeling with latent states can reveal the underlying processes that generate complex data. In healthcare, for example, we can analyze physiological measures, like heart rate and respiratory rate, to learn a patient's underlying health state. This can then help identify and predict different health conditions.
Unsupervised representation learning methods have successfully encoded time series data to capture underlying states \citep{lorek2022flowhmm, franceschi2019unsupervised, tonekaboni2021unsupervised, zhang2022self, zhou2023deep, yu2022latent}. But these methods often require prior knowledge of the number of states and cannot adapt to evolving conditions. With large datasets, the number of states and their distributions can change over time. A newly emerging disease, for instance, would need representation as a new state. Better models can adapt to these changes and account for a potentially unbounded number of states. 

Bayesian nonparametric (BNP) models offer a solution to this problem \citep{orbanz2010bayesian, hjort2010bayesian, lorek2022flowhmm, }, but often rely on overly simplistic assumptions for real-world time series data. In particular, while allowing for an unbounded number of states, these models assume simple parametric state descriptions. In this paper, we introduce a BNP sequence model called \hdpflow. \hdpflow\ combines nonparametric modeling of state dynamics with the expressivity of deep generative modeling, all while ensuring computational efficiency. 
% This makes \hdpflow\ ideal for unsupervised modeling of complex and evolving states in time series data. 
There are three main components to \hdpflow. 
1) To model state dynamics, \hdpflow\ builds on the hierarchical Dirichlet process hidden Markov model (HDP-HMM) \citep{teh2006hierarchical}. HDP-HMM is a sequence model that enables the number of states to adapt to the complexity of the observed data. More specifically, we use the sticky HDP-HMM \citep{fox2011sticky}, which improves state dynamic modelling by encouraging state persistence.
2) To capture the complex distribution of real-world time series, \hdpflow\ couples the sticky HDP-HMM with conditional normalizing flows \citep{papamakarios2017masked} to model the state-specific emission distributions.
3) \hdpflow\ models non-stationary states by conditioning the distribution of observations in each state on the number of time steps within that state. A deterministic variable counts the number of steps a state has persisted. The distribution of observations is then conditioned on this variable to model states with trend, periodicity, and other non-stationarities. The Markov assumption underlying the HDP-HMM and the static emissions fail to capture such non-stationary states.   



Our goal is to apply \hdpflow\ to large-scale time series, hence, the scalability of inference is key. Most BNP models rely on sampling-based methods for inference, which can become computationally intractable when dealing with long time series samples in large cohorts of data.
Here, we derive an efficient stochastic variational inference (SVI) algorithm based on black-box variational inference (BBVI) \citep{ranganath2014black}. This algorithm allows us to efficiently handle the complex distributions and dependencies of the generative process of \hdpflow.

We evaluate \hdpflow\ using real and simulated datasets, comparing its learned state representations to those of other nonparametric and parametric models. \hdpflow\ consistently outperforms nonparametric models in identifying latent states, demonstrating exceptional accuracy in settings with non-stationary emissions. It also bests other models in approximating the true data distribution within each state. Finally, when applied to a longer time series data of human activities, we demonstrate the superior scalability of \hdpflow's SVI algorithm compared to sampling-based inference methods.








