# Time Series Segmentation with Hidden Markov Models

## Introduction

This is an interactive demo visualizing algorithms for hidden Markov models on continuous time series. A hidden Markov model is a probabilistic model for time series. In other words, a hidden Markov model is an abstract representation of a time series: X = {x1 ... xT} . The model can be regarded as a probabilistic state machine with a finite number of states: S = {s1 ... 1N} . Transitions are defined by a probabilistic transition function P(s|s') which indicates the probability of switching from state s to state s' . It also defines a observation function P(x|s) that indicates how probable a state is given an observation from the time series. There are two main questions that arise given a model and a time series:
• Decoding: Given my time series what is the most probable path through a hidden Markov model.
• Parameter Estimation: Given a time series (or multiple time series) what is the maximum likelihood parametrization.
Decoding can be solved using the Viterbi recursion and parameter estimation can be solved using the Baum Welch algorithm. Pointers to references can be found below and I encourage the reader to follow at least through half of the Rabiner paper. However, what I want to discuss here is how hidden Markov models can be used to segment a time series, which in turn will give insight in how hidden Markov models work. The high level idea is that we can estimate the parameters of a hidden Markov model for a time series and then find the maximum path through the estimated model for the same time series. If we backtrack the path, will get a sequence of states. Each state on the path indicates an assignment from a sample from the time series X into the state space S. While speech recognition is a supervised task often solved with hidden Markov models, the algorithms underneath solve an unsupervised problem: segmentation. The following interactive demo shows segmentation for continuous time series with a simplified one dimensional hidden Markov model.

## Demo

 Number of training iterations: Number of states: Sequence: 1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3