| Trees | Indices | Help |
|
|---|
|
|
object --+
|
utils.nltk.ngram.model.NgramModel --+
|
ChordClassHmm
Hidden Markov Model based on the model described in the paper. The structure of this model was descibed in my 2nd year review.
States are in the form of a tuple (schema,root) where
schema is the name of a lexical schema from the jazz grammar
and root is a pitch class root.
Emissions are in the form of a list of pairs (pc,r), where pc is a
pitch class (like root above) and r is an onset time
abstraction. The metrical model (the r part) can be disabled.
An additional distribution is stored over the number of notes emitted.
This needs to be included in the computation of the emission probability
for a set of notes for it to form a valid probability distribution. For
simplicity, we don't condition this on the chord class. We also need a
maximum number of possible notes that can be emitted
max_notes so that this is a finite distribution.
Unlike with NgramModel, the emission domain is the domain of values
from which each element of an emission is selected. In other words, the
actual domain of emissions is the infinite set of combinations of the
values in emission_dom (in fact finite because of
max_notes)
As for prior distributions (start state distribution), we ignore the root of the first state - it doesn't make any sense to look at it since the model is pitch-invariant throughout.
Note: mutable distributions: if you use mutable distributions for transition or emission distributions, make sure you invalidate the cache by calling clear_cache after updating the distributions. Various caches are used to speed up retreival of probabilities. If you fail to do this, you'll end up getting some values unpredictably from the old distributions
To Do: Make this inherit from jazzparser.utils.nltk.ngram.DictionaryHmmModel so that we can use a specialization of the jazzparser.utils.nltk.ngram.baumwelch.BaumWelchTrainer with it.
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
Inherited from Inherited from Inherited from |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
Inherited from Inherited from |
|||
|
|||
x.__init__(...) initializes x; see help(type(x)) for signature
|
Initializes or empties probability distribution caches. Make sure to call this if you change or update the distributions. |
We don't train these HMMs using the We train our models by initializing in some way (usually hand-setting of parameters), then using Baum-Welch on unlabelled data. This method will just raise an error.
|
Creates a new model with the distributions initialized naively to favour simple chord-types, in a similar way to what R&S do in the paper. The transition distribution is initialized so that everything is equiprobable.
|
Train the transition distribution parameters in a supervised manner, using chord corpus input. This is used as an initialization step to set transition parameters before running EM on unannotated data.
|
Trains the distribution over the number of notes emitted from a chord class. It's not conditioned on the chord class, so the only training data needed is a segmented MIDI corpus.
|
Gives the probability P(label_i | label_(i-1), ..., label_(i-n)), where the previous labels are given in the sequence label_context. The context should be in reverse order, i.e. with the most recent label at the start. Note that this is the probability of a label given the previous n-1 labels, which is the same as the probability of the n-gram [label_i, ..., label_(i-n+1)] given the ngram [label_(i-1), ..., label_(i-n)], since all but the last element of the ngram overlaps with the condition, so has probability 1. Caches all computed transition probabilities. This is particularly important for backoff models. Many n-grams will back off to the same (n-1)-gram and we don't want to recompute the transition probability for that each time.
|
Gives the probability P(emission | label). Returned as a base 2 log. The emission should be a list of emitted notes. Each note should be given as a tuple (pc,beat), where pc is the pitch class of the note and beat is the beat specifier for the metrical model. If the model is non-metric, you may set to beat always to 0, as it will be ignored and assumed to be 0. |
The standard emission probability is P(emission | state). This instead returns P(emission | chord class). The emission is given in the same way as to emission_log_probability. The root number is also required. For emission_log_probability, this is included in the state label. |
We override this to provide a faster implementation. It might also be possible to speed up the superclass' implementation using numpy, but it's easier here because we know we're using an HMM, not a higher-order ngram. This is based on the fwd prob calculation in NLTK's HMM implementation.
|
We override this to provide a faster implementation.
See Also: forward_log_probability |
If you want the normalized matrix of forward probabilities, it's ok to use normal (non-log) probabilities and these can be computed more quickly, since you don't need to sum logs (which is time consuming). Returns the matrix, and also the vector of values that each timestep was divided by to normalize (i.e. total probability of each timestep over all states). Also returns the total log probability of the sequence.
|
Return the backward probability matrices a Numpy array. This is faster than backward_log_probabilities because it uses Numpy arrays with non-log probabilities and normalizes each timestep.
See Also: normal_forward_probabilities (except that this doesn't return the logprob) |
Computes the gamma matrix used in Baum-Welch. This is the matrix of state occupation probabilities for each timestep. It is computed from the forward and backward matrices. These can be passed in as arguments to avoid recomputing if you need to reuse them, but will be computed from the model if not given. They are assumed to be the matrices computed by normal_forward_probabilities and normal_backward_probabilities (i.e. normalized, non-log probabilities). |
Computes the xi matrix used by Baum-Welch. It is the matrix of joint probabilities of occupation of pairs of conecutive states: P(i_t, j_{t+1} | O). As with compute_gamma forward and backward matrices can optionally be passed in to avoid recomputing. |
Produces a picklable representation of model as a dict. You can't just pickle the object directly because some of the NLTK classes can't be pickled. You can pickle this dict and reconstruct the model using NgramModel.from_picklable_dict(dict). |
Reproduces an n-gram model that was converted to a picklable form using to_picklable_dict. |
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Mon Nov 26 16:04:58 2012 | http://epydoc.sourceforge.net |