-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37ff4cf
commit bc0405f
Showing
13 changed files
with
363 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
Package: hmm.discnp | ||
Version: 0.1-9 | ||
Date: 2013-04-17 | ||
Version: 0.2-0 | ||
Date: 2013-09-30 | ||
Title: Hidden Markov models with discrete non-parametric observation | ||
distributions. | ||
Author: Rolf Turner <r.turner@auckland.ac.nz> and Limin Liu. | ||
Maintainer: Rolf Turner <r.turner@auckland.ac.nz> | ||
Depends: R (>= 0.99) | ||
Description: Fits hidden Markov models with discrete non-parametric | ||
observation distributions to data sets. Simulates data from | ||
such models. Finds most probable underlying hidden states, the | ||
most probable sequences of such states, and the log likelihood | ||
of a collection of observations given the parameters of the | ||
model. | ||
Description: Fits hidden Markov models with discrete non-parametric | ||
observation distributions to data sets. Simulates data | ||
from such models. Finds most probable underlying hidden | ||
states, the most probable sequences of such states, and the | ||
log likelihood of a collection of observations given the | ||
parameters of the model. | ||
License: GPL (>= 2) | ||
URL: http://www.math.unb.ca/~rolf/ | ||
Packaged: 2013-04-18 02:02:12 UTC; rolf | ||
Packaged: 2013-09-30 21:51:42 UTC; rolf | ||
NeedsCompilation: yes | ||
Repository: CRAN | ||
Date/Publication: 2013-04-18 07:29:04 | ||
Date/Publication: 2013-10-01 07:42:59 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,47 @@ | ||
revise.ispd <- function(tpm=NULL,gamma=NULL,lns=NULL) { | ||
revise.ispd <- function(tpm=NULL,gamma=NULL,lns=NULL,cis=TRUE) { | ||
# Function revise.ispd. To revise the initial state probability | ||
# distribution | ||
|
||
if(is.null(tpm) + (is.null(gamma) & is.null(lns)) != 1) | ||
stop(paste("Either \"tpm\" should be given OR\n", | ||
"\"gamma\" and \"lns\" should be given.\n")) | ||
|
||
if(cis) { | ||
if(is.null(tpm) + (is.null(gamma) & is.null(lns)) != 1) | ||
stop(paste("When \"cis\" is TRUE either \"tpm\" should be given\n", | ||
"OR \"gamma\" and \"lns\" should be given.\n")) | ||
|
||
# If ispd is taken to be the steady state distribution: | ||
if(!is.null(tpm)) { | ||
eee <- eigen(t(tpm)) | ||
k <- match(1,round(eee$values,6)) | ||
if(length(k) != 1) { | ||
cat('Problems with eigenvalues:\n') | ||
print(eee$values) | ||
stop() | ||
} | ||
v <- Re(eee$vectors[,k]) | ||
return(v/sum(v)) | ||
} | ||
|
||
if(!is.null(tpm)) { | ||
eee <- eigen(t(tpm)) | ||
k <- match(1,round(eee$values,6)) | ||
if(length(k) != 1) { | ||
cat('Problems with eigenvalues:\n') | ||
print(eee$values) | ||
stop() | ||
} | ||
v <- Re(eee$vectors[,k]) | ||
ispd <- v/sum(v) | ||
} else { | ||
# Steady state not assumed: | ||
v <- 0 | ||
j <- 1 | ||
nseq <- length(lns) | ||
for(i in 1:nseq) { | ||
v <- v + gamma[,j] | ||
j <- j + lns[i] | ||
v <- 0 | ||
j <- 1 | ||
nseq <- length(lns) | ||
for(i in 1:nseq) { | ||
v <- v + gamma[,j] | ||
j <- j + lns[i] | ||
} | ||
ispd <- v/nseq | ||
} | ||
} else { | ||
if(is.null(gamma) | is.null(lns)) | ||
stop(paste("When \"cis\" is FALSE \"gamma\" and \"lns\"\n", | ||
"must be given.\n")) | ||
jg <- 1 | ||
nseq <- length(lns) | ||
K <- nrow(gamma) | ||
ispd <- matrix(0,K,nseq) | ||
for(j in 1:nseq) { | ||
ispd[which.max(gamma[,jg]),j] <- 1 | ||
jg <- jg + lns[j] | ||
} | ||
} | ||
v/nseq | ||
return(ispd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.