Package jazzparser :: Package formalisms :: Package music_halfspan :: Module pcfg :: Class HalfspanPcfgModel
[hide private]
[frames] | no frames]

Class HalfspanPcfgModel

source code

                  object --+    
                           |    
parsers.pcfg.model.PcfgModel --+
                               |
                              HalfspanPcfgModel

A simple implementation of the PcfgModel interface. The model just uses counts to compute the probabilities, with only very simple smoothing.

By default, unary expansions are fobidden, since our grammar doesn't use them. If you want to allow them, set unary_expansions=True.

Instance Methods [hide private]
 
__init__(self, name, cutoff=0, cat_bins=None, estimator=estimator_name('laplace')(jazzparser.utils.nltk.probability.la..., lexical=True, chordmap=None, parent_counts=None, expansion_type_counts=None, head_expansion_counts=None, non_head_expansion_counts=None, lexical_counts=None, **kwargs)
Creates an empty, untrained model.
source code
 
chord_observation(self, chord)
Returns the string observation counted for a given chord.
source code
 
_get_model_data(self)
Subclasses should implement this method to return the raw data of the model in a form that can be pickled and written out to a file.
source code
 
inside_probability(self, expansion, parent, left, right=None)
Probability of a (non-leaf) subtree, computed from the probability of its expansions.
source code
 
outside_probability(self, parent)
Outer probability of a subtree.
source code
 
description(self) source code
 
_sequence_train(self, sequence)
Adds counts to the model for a single chord sequence.
source code
 
generate(self, logger=None, max_depth=None)
Generate a chord sequence from the model.
source code

Inherited from parsers.pcfg.model.PcfgModel: delete, process_training_options, save

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods [hide private]

Inherited from parsers.pcfg.model.PcfgModel: list_models, load_model

Inherited from parsers.pcfg.model.PcfgModel (private): _get_model_dir

Static Methods [hide private]
 
_load_model(name, data)
Subclasses should implement this method to load up the model data given in the argument data.
source code
 
train(name, training_data, options, grammar=None, logger=None)
Trains a new model using the data in the list of sequences.
source code
Class Variables [hide private]
  MODEL_TYPE = 'halfspan'
hash(x)
  TRAINING_OPTIONS = PcfgModel.TRAINING_OPTIONS+ [ModuleOption('...
  LEX_INPUT_TYPES = [<class 'jazzparser.data.input.DbInput'>, <c...
Properties [hide private]

Inherited from parsers.pcfg.model.PcfgModel: options

Inherited from parsers.pcfg.model.PcfgModel (private): _filename

Inherited from object: __class__

Method Details [hide private]

__init__(self, name, cutoff=0, cat_bins=None, estimator=estimator_name('laplace')(jazzparser.utils.nltk.probability.la..., lexical=True, chordmap=None, parent_counts=None, expansion_type_counts=None, head_expansion_counts=None, non_head_expansion_counts=None, lexical_counts=None, **kwargs)
(Constructor)

source code 

Creates an empty, untrained model. To load a previously stored model, use from_file().

Optionally stores some custom descriptive text. This will be included in the descriptive text that gets stored along with the model.

Overrides: object.__init__
(inherited documentation)

chord_observation(self, chord)

source code 

Returns the string observation counted for a given chord. Note that the chord should already have been made relative to its parent.

_get_model_data(self)

source code 

Subclasses should implement this method to return the raw data of the model in a form that can be pickled and written out to a file.

A default implementation to complement the implementation of _load_model is provided.

Overrides: parsers.pcfg.model.PcfgModel._get_model_data
(inherited documentation)

_load_model(name, data)
Static Method

source code 

Subclasses should implement this method to load up the model data given in the argument data. They should return an instance of themselves. The data will be in the form of a dictionary, as returned by the class' _get_model_data().

A default implementation that just uses simple pickling is provided.

Overrides: parsers.pcfg.model.PcfgModel._load_model
(inherited documentation)

inside_probability(self, expansion, parent, left, right=None)

source code 

Probability of a (non-leaf) subtree, computed from the probability of its expansions. This doesn't include the probabilities of the subtrees of the daughters. To get the full inside probability, multiply the returned value with the daughters' insider probabilities.

Overrides: parsers.pcfg.model.PcfgModel.inside_probability

outside_probability(self, parent)

source code 

Outer probability of a subtree. This is approximated in these models as the prior probability of the parent of the tree.

Prior probability P(parent) is used to approximate the outside probability.

Overrides: parsers.pcfg.model.PcfgModel.outside_probability

description(self)

source code 
Overrides: description

train(name, training_data, options, grammar=None, logger=None)
Static Method

source code 

Trains a new model using the data in the list of sequences.

Overrides: parsers.pcfg.model.PcfgModel.train
(inherited documentation)

generate(self, logger=None, max_depth=None)

source code 

Generate a chord sequence from the model.

Overrides: parsers.pcfg.model.PcfgModel.generate

Class Variable Details [hide private]

TRAINING_OPTIONS

Value:
PcfgModel.TRAINING_OPTIONS+ [ModuleOption('cutoff', filter= int, help_\
text= "In estimating probabilities, treat any counts below " "cutoff a\
s zero", usage= "cutoff=X, where X is an integer", default= 0), Module\
Option('cat_bins', filter= int, help_text= "Number of possible categor\
ies used in estimating " "probabilities. When using smoothing, this wi\
ll determine " "mass reserved for unseen categories. Has no effect if \
using " "mle. Overrides the value given in the grammar definition, " "\
which will be used by default.", usage= "cat_bins=X, where X is an int\
...

LEX_INPUT_TYPES

Value:
[<class 'jazzparser.data.input.DbInput'>,
 <class 'jazzparser.data.input.ChordInput'>]