[Depmix-commits] r149 - in trunk: . R man tests
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Jun 10 16:09:26 CEST 2008
Author: ingmarvisser
Date: 2008-06-10 16:09:26 +0200 (Tue, 10 Jun 2008)
New Revision: 149
Added:
trunk/R/forwardbackward.R
trunk/man/forwardbackward.Rd
Modified:
trunk/DESCRIPTION
trunk/NAMESPACE
trunk/R/allGenerics.R
trunk/man/posterior.Rd
trunk/tests/depmixNew-test2.R
Log:
Added forwardbackward, user accessible function to get the forward and backward variables
Modified: trunk/DESCRIPTION
===================================================================
--- trunk/DESCRIPTION 2008-06-10 13:16:50 UTC (rev 148)
+++ trunk/DESCRIPTION 2008-06-10 14:09:26 UTC (rev 149)
@@ -1,6 +1,6 @@
Package: depmixS4
-Version: 0.1-0
-Date: 2008-03-23
+Version: 0.2-0
+Date: 2008-06-09
Title: Dependent Mixture Models
Author: Ingmar Visser <i.visser at uva.nl>, Maarten Speekenbrink <m.speekenbrink at ucl.ac.uk>
Maintainer: Ingmar Visser <i.visser at uva.nl>
Modified: trunk/NAMESPACE
===================================================================
--- trunk/NAMESPACE 2008-06-10 13:16:50 UTC (rev 148)
+++ trunk/NAMESPACE 2008-06-10 14:09:26 UTC (rev 149)
@@ -6,11 +6,11 @@
makeDepmix,
lystig,
fb,
+ forwardbackward,
llratio,
multinomial,
em,
viterbi,
- viterbi.fb,
mlogit
)
Modified: trunk/R/allGenerics.R
===================================================================
--- trunk/R/allGenerics.R 2008-06-10 13:16:50 UTC (rev 148)
+++ trunk/R/allGenerics.R 2008-06-10 14:09:26 UTC (rev 149)
@@ -3,7 +3,7 @@
# Ingmar Visser, 23-3-2008
#
-.First.lib <- function(lib, pkg) {
+.First.lib <- function(lib, pkg) {
require(nnet)
}
@@ -38,6 +38,8 @@
setGeneric("posterior", function(object, ...) standardGeneric("posterior"))
+setGeneric("forwardbackward", function(object, ...) standardGeneric("forwardbackward"))
+
setGeneric("simulate", function(object, ...) standardGeneric("simulate"))
setGeneric("predict", function(object, ...) standardGeneric("predict"))
Added: trunk/R/forwardbackward.R
===================================================================
--- trunk/R/forwardbackward.R (rev 0)
+++ trunk/R/forwardbackward.R 2008-06-10 14:09:26 UTC (rev 149)
@@ -0,0 +1,13 @@
+#
+# Ingmar Visser
+#
+# FORWARD-BACKWARD function, user interface, 10-06-2008
+#
+
+setMethod("forwardbackward","depmix",
+ function(object, return.all=TRUE, ...) {
+ fb(init=object at init,A=object at trDens,B=object at dens,ntimes=ntimes(object),
+ stationary=object at stationary,return.all=return.all)
+}
+
+
Added: trunk/man/forwardbackward.Rd
===================================================================
--- trunk/man/forwardbackward.Rd (rev 0)
+++ trunk/man/forwardbackward.Rd 2008-06-10 14:09:26 UTC (rev 149)
@@ -0,0 +1,67 @@
+\name{forwardbackward}
+
+\alias{forwardbackward}
+
+\alias{forwardbackward,depmix-method}
+
+\title{ Forward and backward variables }
+
+\description{
+
+ Compute the forward and backward variables of a \code{depmix} object.
+
+}
+
+\usage{
+
+ \S4method{posterior}{depmix}(object, return.all=TRUE, ...)
+
+}
+
+\arguments{
+
+ \item{object}{A depmix object.}
+
+ \item{return.all}{If FALSE, only gamma and xi and the log likelihood
+ are returned (which are the only variables needed in using EM).}
+
+ \item{\dots}{Not currently used.}
+
+}
+
+\value{
+
+ \code{forwardbackward} returns a list of the following (the variables
+ are named after the notation from Rabiner (1989).
+
+ \item{alpha}{The forward variables.}
+
+ \item{beta}{The backward variables.}
+
+ \item{gamma}{The smoothed transition probabilities.}
+
+ \item{xi}{The smoothed state probabilities.}
+
+ \item{sca}{The scale factors (called lambda in Rabiner).}
+
+ \item{logLike}{The log likelihood (which is \code{sum(log(sca))}.}
+
+ If return.all=FALSE, only gamma, xi and the log likelihood are returned.
+}
+
+\references{
+
+ Lawrence R. Rabiner (1989). A tutorial on hidden Markov models and
+ selected applications in speech recognition. \emph{Proceedings of
+ IEEE}, 77-2, p. 267-295.
+
+}
+
+\author{ Ingmar Visser }
+
+\examples{
+ # add some later
+}
+
+\keyword{ methods }
+
Modified: trunk/man/posterior.Rd
===================================================================
--- trunk/man/posterior.Rd 2008-06-10 13:16:50 UTC (rev 148)
+++ trunk/man/posterior.Rd 2008-06-10 14:09:26 UTC (rev 149)
@@ -8,7 +8,7 @@
\description{
- Compute the posterior states for a (fitted) depmix object. In the case
+ Return the posterior states for a fitted depmix object. In the case
of a latent class or mixture model these are the class probabilities.
}
Modified: trunk/tests/depmixNew-test2.R
===================================================================
--- trunk/tests/depmixNew-test2.R 2008-06-10 13:16:50 UTC (rev 148)
+++ trunk/tests/depmixNew-test2.R 2008-06-10 14:09:26 UTC (rev 149)
@@ -32,20 +32,14 @@
mod <- depmix(list(rt~1,corr~1),data=speed,transition=~Pacc,nstates=2,family=list(gaussian(),multinomial()),
respstart=resp,trstart=trstart,instart=instart)
-logLik(mod)
+mod2 <- fit(mod,meth="EM")
-mod1 <- fit(mod)
-ll <- logLik(mod1)
+ll <- logLik(mod2)
cat("Test 1: ", ll, "(loglike of speed data with covariate, hopefully better than 300.5701) \n")
-mod2 <- fit(mod,meth="EM")
-
-post <- cbind(viterbi(mod1),speed$Pacc)
-
-
#
-# now constrain the initial state probs to be 0 and 1
+# now constrain the initial state probs to be 0 and 1
# also constrain the guessing probs to be 0.5 and 0.5
#
More information about the depmix-commits
mailing list