Skip to content

Instantly share code, notes, and snippets.

@keithshep
Created June 14, 2010 19:57
Show Gist options
  • Save keithshep/438217 to your computer and use it in GitHub Desktop.
Save keithshep/438217 to your computer and use it in GitHub Desktop.
Example use of R HMM package
library("RHmm")
sunProb <- c(0.6, 0.2, 0.15, 0.05)
cloudProb <- c(0.25, 0.25, 0.25, 0.25)
rainProb <- c(0.05, 0.10, 0.35, 0.50)
weatherDist <- distributionSet(dis="DISCRETE", proba=list(sunProb, cloudProb, rainProb), labels =c("DRY", "DRYISH", "DAMP", "SOGGY"))
weatherTransitions <- rbind(c(0.5, 0.375, 0.125), c(0.25, 0.125, 0.625), c(0.25, 0.375, 0.375))
weatherHmm <- HMMSet(initProb=c(0.63, 0.17, 0.20), transMat=weatherTransitions, distribution=weatherDist)
weatherPath <- viterbi(HMM=weatherHmm, obs=c("DRY", "DAMP", "SOGGY", "SOGGY", "DRYISH"))
weatherPath
@AankitaDebroy
Copy link

Hi , How do I do the same thing in case I have two hidden columns. For example my Dataset has 1st column X with possible values (a. b, c) and 2nd Column Y with possible values as (d, e, f) and my 3rd column which is the observed column be Z with possible set of values as (g, h, i). How do I create my distribution set in this case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment