{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Deep Markov Model \n",
"\n",
"## Introduction\n",
"\n",
"We're going to build a deep probabilistic model for sequential data: the deep markov model. The particular dataset we want to model is composed of snippets of polyphonic music. Each time slice in a sequence spans a quarter note and is represented by an 88-dimensional binary vector that encodes the notes at that time step. \n",
"\n",
"Since music is (obviously) temporally coherent, we need a model that can represent complex time dependencies in the observed data. It would not, for example, be appropriate to consider a model in which the notes at a particular time step are independent of the notes at previous time steps. One way to do this is to build a latent variable model in which the variability and temporal structure of the observations is controlled by the dynamics of the latent variables. \n",
"\n",
"One particular realization of this idea is a markov model, in which we have a chain of latent variables, with each latent variable in the chain conditioned on the previous latent variable. This is a powerful approach, but if we want to represent complex data with complex (and in this case unknown) dynamics, we would like our model to be sufficiently flexible to accommodate dynamics that are potentially highly non-linear. Thus a deep markov model: we allow for the transition probabilities governing the dynamics of the latent variables as well as the the emission probabilities that govern how the observations are generated by the latent dynamics to be parameterized by (non-linear) neural networks.\n",
"\n",
"The specific model we're going to implement is based on the following reference:\n",
"\n",
"[1] `Structured Inference Networks for Nonlinear State Space Models`,
\n",
" Rahul G. Krishnan, Uri Shalit, David Sontag\n",
" \n",
"Please note that while we do not assume that the reader of this tutorial has read the reference, it's definitely a good place to look for a more comprehensive discussion of the deep markov model in the context of other time series models.\n",
"\n",
"We've described the model, but how do we go about training it? The inference strategy we're going to use is variational inference, which requires specifying a parameterized family of distributions that can be used to approximate the posterior distribution over the latent random variables. Given the non-linearities and complex time-dependencies inherent in our model and data, we expect the exact posterior to be highly non-trivial. So we're going to need a flexible family of variational distributions if we hope to learn a good model. Happily, together PyTorch and Pyro provide all the necessary ingredients. As we will see, assembling them will be straightforward. Let's get to work."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The Model\n",
" \n",
"A convenient way to describe the high-level structure of the model is with a graphical model."
]
},
{
"cell_type": "raw",
"metadata": {
"raw_mimetype": "text/html"
},
"source": [
"
" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/html" }, "source": [ "