hmm-0.2.1.1: A hidden markov model library

Data.HMM

Description

Data.HMM is a library for using Hidden Markov Models (HMMs) with Haskell. HMMs are a common method of machine learning. All of the most frequently used algorithms---the forward and backwards algorithms, Viterbi, and Baum-Welch---are implemented in this library.

Synopsis

# Documentation

data HMM stateType eventType Source

The data types for our HMM.

Constructors

 HMM Fieldsstates :: [stateType] events :: [eventType] initProbs :: stateType -> Prob transMatrix :: stateType -> stateType -> Prob outMatrix :: stateType -> eventType -> Prob

Instances

 (Show stateType, Show eventType) => Show (HMM stateType eventType)

forward :: (Eq eventType, Eq stateType, Show eventType, Show stateType) => HMM stateType eventType -> [eventType] -> ProbSource

forward algorithm determines the probability that a given event array would be emitted by our HMM

backward :: (Eq eventType, Eq stateType, Show eventType, Show stateType) => HMM stateType eventType -> [eventType] -> ProbSource

backwards algorithm does the same thing as the forward algorithm, just a different implementation

viterbi :: (Eq eventType, Eq stateType, Show eventType, Show stateType) => HMM stateType eventType -> Array Int eventType -> [stateType]Source

Viterbi's algorithm calculates the most probable path through our states given an event array

baumWelch :: (Eq eventType, Eq stateType, Show eventType, Show stateType) => HMM stateType eventType -> Array Int eventType -> Int -> HMM stateType eventTypeSource

Baum-Welch is used to train an HMM

baumWelchItr :: (Eq eventType, Eq stateType, Show eventType, Show stateType) => HMM stateType eventType -> Array Int eventType -> HMM stateType eventTypeSource

simpleMM :: (Eq a1, Eq a, Num a, Show a1) => [a1] -> a -> HMM [a1] a1Source

Use simpleMM to create an untrained standard Markov model

simpleHMM :: (Eq stateType, Show eventType, Show stateType) => [stateType] -> [eventType] -> HMM stateType eventTypeSource

Use simpleHMM to create an untrained hidden Markov model

hmmJoin :: (Eq stateType, Eq eventType, Read stateType, Show stateType) => HMM stateType eventType -> HMM stateType eventType -> Prob -> HMM (Int, stateType) eventTypeSource

Joins 2 HMMs by connecting every state in the first HMM to every state in the second, and vice versa, with probabilities based on the join ratio

verifyhmm :: HMM stateType eventType -> IO ()Source

initProbs should always equal 1; the others should equal the number of states

loadHMM :: (Eq eventType, Eq stateType, Read stateType, Read eventType, Show eventType, Show stateType) => FilePath -> IO (HMM stateType eventType)Source

saveHMM :: (Show stateType, Show eventType) => String -> HMM stateType eventType -> IO ()Source

saves the HMM to a file for later retrieval. HMMs can take a long time to calculate, so this is very useful