rmcgibbo/mixtape — pull request #19 by rmcgibbo (2014-02-21 04:13:24+00:00)
Title: Add a new command for sampling structures from each state in the HMM

I hadn't realized this before, but sampling from the HMM is actually rather complex.

```
Draw iid samples from each state in an Gaussian HMM.

The output is a small CSV file with 3 columns: 'filename', 'index', and 'state'.
Each row gives the path to a trajectory file, the index of a single frame
therein, and the state it was drawn from.

The sampling strategy is as follows: for each state represented by a Gaussian
distribution, we create a discrete distribution over the featurized frames in
the specified trajectory files such that the discrete distribution has the same
mean and variance as the state Gaussian distribution and minimizes the K-L
divergence from the discrete distribution to the continuous Gaussian it's trying
to model. Then, we sample from that discrete distribution and return the
corresponding frames in a CSV file.

The reason for this complexity is that the Gaussian distributions for each state
are continuous distributions over the featurized space. To visualize the
structures corresponding to each state, however, we would need to "invert" the
featurization, and draw raw structures. Alternatively, we can draw from a
discrete distribution over our available structures; but this introduces the
question of what discrete distribution "optimally" represents the continuous
(Gaussian) distribution of interest.

[Reference]: Tanaka, Ken'ichiro, and Alexis Akira Toda. "Discrete approximations
of continuous distributions by maximum entropy." Economics Letters 118.3 (2013):
445-450.
```