Documentation ¶
Overview ¶
Package hmm provides an implementation of hidden Markov models. It is designed for applications in temporal pattern recognition.
The package can support any output distribution of type model.Modeler.
Index ¶
- func MakeLeftToRight(ns int, selfProb, skipProb float64) *narray.NArray
- type Assigner
- type DirectAssigner
- type MapAssigner
- type Model
- func (m *Model) Clear()
- func (m *Model) Dim() int
- func (m *Model) Estimate() error
- func (m *Model) LogProb(observation interface{}) float64
- func (m *Model) Name() string
- func (m *Model) Prob(observation interface{}) float64
- func (m *Model) Random(r *rand.Rand) (interface{}, []int, error)
- func (m *Model) SetFlags(useAlignments, updateTP, updateOP bool)
- func (m *Model) String() string
- func (m *Model) ToJSON() (string, error)
- func (m *Model) Update(x model.Observer, w func(model.Obs) float64) error
- func (m *Model) UpdateOne(o model.Obs, w float64)
- func (m *Model) WriteJSON(w io.Writer) error
- func (m *Model) WriteJSONFile(fn string) error
- type Net
- type ObsSlice
- type Option
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MakeLeftToRight ¶
MakeLeftToRight creates a transition probability matrix for a left-to-right HMM.
- ns is the total number of states including entry/exit. Must be 3 or greater.
- selfProb is the prob of the self loop with value between 0 and 1.
- skipProb is the prob of skipping next state. Make it zero for no skips.
- for ns=3, skipProb is set to zero.
Types ¶
type Assigner ¶
Assigner assigns a sequence of hmm model names to a sequence of labels. This interface hides the details of how the assignment is done. For example, a trivial assigner may assign the label name to the model name:
Input labels: []string{"a", "b", "c"} Output model names: []string{"a", "b", "c"}
or it may use a dictionary as is the case in speech recognition:
Input labels: []string{"HELLO","WORLD"} Output model names: []string{"HH","AH0","L","OW1","W","ER1","L","D"}
type DirectAssigner ¶
type DirectAssigner struct{}
DirectAssigner implements the Assigner interface. Model names correspond one-to-one to the label names.
func (DirectAssigner) Assign ¶
func (a DirectAssigner) Assign(labels []string) []string
Assign returns a sequence of model names.
type MapAssigner ¶
MapAssigner implements the Assigner interface. Labes are mapped using a dictionary.
func (MapAssigner) Assign ¶
func (a MapAssigner) Assign(labels []string) []string
Assign returns a sequence of model names.
type Model ¶
type Model struct { // Model type. Type string `json:"type"` // Model name. ModelName string `json:"name"` // Model Set Set *Set `json:"hmm_set"` // contains filtered or unexported fields }
Model is a hidden Markov model.
func ReadJSONFile ¶
ReadJSONFile unmarshals json data from a file.
func (*Model) WriteJSONFile ¶
WriteJSONFile writes to a file.
type Net ¶
type Net struct { // Model name. Name string `json:"name"` // State transition probabilities. (ns x ns matrix) A *narray.NArray `json:"trans_prob"` // Output probabilities. (ns x 1 vector) B []model.Modeler `json:"output_prob"` // Accumulator for transition probabilities. TrAcc *narray.NArray `json:"tr_acc,omitempty"` // Accumulator for global occupation counts. OccAcc *narray.NArray `json:"occ_acc,omitempty"` // contains filtered or unexported fields }
Net is an hmm network with a single non-emmiting entry state (index 0) and a single non-emmiting exit state (index ns-1) where ns is the total number of states. The HMMs must have a left-to-right topology. That is, transitions can only go from state i to state j where j >= i.
type Option ¶
type Option func(*Model)
Option type is used to pass options to NewModel().
func MaxGenLen ¶
MaxGenLen option sets the length of the sequences created by the MODEL generator. Default is 100.
func UseAlignments ¶
UseAlignments option. When true, the output probability densities are estimated using alignment info. The alignment info must be available in the obs object which shoudl implement the model.ALigner interface. Will panic if the alignment data is missing.