[Depmix-commits] r549 - in pkg/depmixS4: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Jul 26 15:24:47 CEST 2012
Author: ingmarvisser
Date: 2012-07-26 15:24:47 +0200 (Thu, 26 Jul 2012)
New Revision: 549
Modified:
pkg/depmixS4/R/EM.R
pkg/depmixS4/R/allGenerics.R
pkg/depmixS4/R/depmixfit.R
pkg/depmixS4/R/em.control.R
pkg/depmixS4/README
pkg/depmixS4/man/depmix.fit.Rd
Log:
Added solnp and donlp control arguments to the fit function.
Modified: pkg/depmixS4/R/EM.R
===================================================================
--- pkg/depmixS4/R/EM.R 2012-07-26 11:41:54 UTC (rev 548)
+++ pkg/depmixS4/R/EM.R 2012-07-26 13:24:47 UTC (rev 549)
@@ -3,7 +3,7 @@
#
rdirichlet <- function(n, alpha) {
- # taken from gtools...
+ # taken from gtools
l <- length(alpha)
x <- matrix(rgamma(l * n, alpha), ncol = l, byrow = TRUE)
sm <- x %*% rep(1, l)
@@ -128,12 +128,10 @@
LL <- sum(log(rowSums(gamma)))
# normalize
gamma <- gamma/rowSums(gamma)
- }
- #gamma <- object at init*B
+ }
+
+ # gamma <- object at init*B
-
-
-
# print stuff
if(verbose&((j%%5)==0)) {
cat("iteration",j,"logLik:",LL,"\n")
Modified: pkg/depmixS4/R/allGenerics.R
===================================================================
--- pkg/depmixS4/R/allGenerics.R 2012-07-26 11:41:54 UTC (rev 548)
+++ pkg/depmixS4/R/allGenerics.R 2012-07-26 13:24:47 UTC (rev 549)
@@ -28,7 +28,6 @@
pstart = NULL, fixed = NULL, prob=TRUE, ...) standardGeneric("transInit"))
# extractors/set functions
-
setGeneric("npar", function(object, ...) standardGeneric("npar"))
setGeneric("ntimes", function(object, ...) standardGeneric("ntimes"))
@@ -69,8 +68,6 @@
setGeneric("predict", function(object, ...) standardGeneric("predict"))
-# setGeneric("getModel", function(object, ...) standardGeneric("getModel"))
-
# these are imported from stats4
# setGeneric("nobs", function(object, ...) standardGeneric("nobs"))
# setGeneric("logLik", function(object, ...) standardGeneric("logLik"))
Modified: pkg/depmixS4/R/depmixfit.R
===================================================================
--- pkg/depmixS4/R/depmixfit.R 2012-07-26 11:41:54 UTC (rev 548)
+++ pkg/depmixS4/R/depmixfit.R 2012-07-26 13:24:47 UTC (rev 549)
@@ -2,7 +2,18 @@
setMethod("fit",
signature(object="mix"),
- function(object,fixed=NULL,equal=NULL,conrows=NULL,conrows.upper=0,conrows.lower=0,method=NULL,emcontrol=em.control(),verbose=TRUE,...) {
+ function(object,fixed=NULL,equal=NULL,
+ conrows=NULL,conrows.upper=0,conrows.lower=0,
+ method=NULL,verbose=TRUE,
+ emcontrol=em.control(),
+ solnpcntrl=list(rho = 1, outer.iter = 400, inner.iter = 800, delta = 1e-5, tol = 1e-6),
+ donlpcntrl=list(iterma = 4000, nstep = 20, fnscale = 1, report = TRUE,
+ rep.freq = 1, tau0 = 1, tau = 0.1, del0 = 1, epsx = 1e-06,
+ delmin = 0.1, epsdif = 1e-08, nreset.multiplier = 1,
+ difftype = 2, epsfcn = 1e-16, taubnd = 1, hessian = FALSE,
+ te0 = TRUE, te1 = FALSE, te2 = FALSE, te3 = FALSE, silent = TRUE,
+ intakt = TRUE),
+ ...) {
fi <- !is.null(fixed)
cr <- !is.null(conrows)
@@ -28,7 +39,6 @@
}
if(method=="EM") {
- if(!(emcontrol$crit %in% c("absolute","relative"))) stop("'crit' argument to em.control not recognized")
object <- em(object,maxit=emcontrol$maxit,tol=emcontrol$tol,crit=emcontrol$crit,random.start=emcontrol$random.start,classification=emcontrol$classification,verbose=verbose,...)
}
@@ -122,9 +132,6 @@
if(!reqdon) stop("Rdonlp2 not available.")
- # set donlp2 control parameters
- cntrl <- donlp2.control(hessian=FALSE,difftype=2,report=TRUE,epsx=1e-6)
-
mycontrol <- function(info) {
return(TRUE)
}
@@ -136,7 +143,7 @@
A=lincon,
lin.upper=lin.u,
lin.lower=lin.l,
- control=cntrl,
+ control=donlpcntrl,
control.fun=mycontrol,
...
)
@@ -196,7 +203,7 @@
ineqUB = ineqUB,
LB = par.l[!fixed],
UB = par.u[!fixed],
- control = list(delta = 1e-5, tol = 1e-6, trace = 1),
+ control = solnpcntrl,
...
)
Modified: pkg/depmixS4/R/em.control.R
===================================================================
--- pkg/depmixS4/R/em.control.R 2012-07-26 11:41:54 UTC (rev 548)
+++ pkg/depmixS4/R/em.control.R 2012-07-26 13:24:47 UTC (rev 549)
@@ -1,5 +1,5 @@
-em.control <-
-function(maxit=500,tol=1e-8,crit=c("relative","absolute"),random.start=TRUE,classification=c("soft","hard")) {
- crit <- match.arg(crit)
- classification <- match.arg(classification)
- return(list(maxit=maxit,tol=tol,crit=crit,random.start=random.start,classification=classification))}
+em.control <- function(maxit=500,tol=1e-8,crit=c("relative","absolute"),random.start=TRUE,classification=c("soft","hard")) {
+ crit <- match.arg(crit)
+ classification <- match.arg(classification)
+ return(list(maxit=maxit,tol=tol,crit=crit,random.start=random.start,classification=classification))
+}
Modified: pkg/depmixS4/README
===================================================================
--- pkg/depmixS4/README 2012-07-26 11:41:54 UTC (rev 548)
+++ pkg/depmixS4/README 2012-07-26 13:24:47 UTC (rev 549)
@@ -45,5 +45,9 @@
Optimization of models with (general) linear (in-)equality constraint is
done using Rsolnp (available from CRAN). Optionally the Rdonlp2 package
can be used; Rdonlp2 was written by Ryuichi Tamura(ry.tamura @ gmail.com),
-and used to be available from: http://arumat.net/Rdonlp2/ The present
-status of Rdonlp2 is unclear.
+and can currently be installed using:
+
+install.packages("Rdonlp2", repos= c("http://R-Forge.R-project.org", getOption("repos")))
+
+Note the licence information which says, among other things: "The free use
+of donlp2 and parts of it is restricted for research purposes ..."
Modified: pkg/depmixS4/man/depmix.fit.Rd
===================================================================
--- pkg/depmixS4/man/depmix.fit.Rd 2012-07-26 11:41:54 UTC (rev 548)
+++ pkg/depmixS4/man/depmix.fit.Rd 2012-07-26 13:24:47 UTC (rev 549)
@@ -30,8 +30,18 @@
\S4method{summary}{depmix.fitted}(object,which="all")
- \S4method{fit}{mix}(object, fixed=NULL, equal=NULL, conrows=NULL,
- conrows.upper=0, conrows.lower=0, method=NULL, emcontrol=em.control(), verbose=TRUE,...)
+ \S4method{fit}{mix}(object, fixed=NULL, equal=NULL,
+ conrows=NULL, conrows.upper=0, conrows.lower=0,
+ method=NULL, verbose=TRUE,
+ emcontrol=em.control(),
+ solnpcntrl=list(rho = 1, outer.iter = 400, inner.iter = 800, delta = 1e-5, tol = 1e-6),
+ donlpcntrl=list(iterma = 4000, nstep = 20, fnscale = 1, report = FALSE,
+ rep.freq = 1, tau0 = 1, tau = 0.1, del0 = 1, epsx = 1e-05,
+ delmin = 0.1, epsdif = 1e-08, nreset.multiplier = 1,
+ difftype = 3, epsfcn = 1e-16, taubnd = 1, hessian = FALSE,
+ te0 = TRUE, te1 = FALSE, te2 = FALSE, te3 = FALSE, silent = TRUE,
+ intakt = TRUE),
+ ...)
\S4method{summary}{mix.fitted}(object,which="all")
@@ -53,12 +63,18 @@
\item{method}{The optimization method; mostly determined by
constraints.}
+
+ \item{verbose}{Should optimization information be displayed on screen?}
\item{emcontrol}{Named list with control parameters for the EM
algorithm (see \code{\link{em.control}}).}
- \item{verbose}{Should optimization information be displayed on screen?}
+ \item{solnpcntrl}{Control parameters passed to the 'rsolnp' optimizer;
+ see \code{\link{solnp}} for explanation and defaults used there.}
+ \item{donlpcntrl}{Control parameters passed to 'donlp' optimizer; see
+ \code{\link{donlp2Control}} for explanation and defaults used there.}
+
\item{which}{Should summaries be provided for "all" submodels? Options
are "prior", "response", and for fitted depmix models also "transition".}
@@ -68,13 +84,13 @@
\details{
- Models are fitted by the EM algorithm if there are no constraints on
- the parameters. Aspects of the EM algorithm can be controlled through
- the \code{emcontrol} argument; see details in \code{\link{em.control}}.
- Otherwise the general optimizers \code{solnp}, the
- default (from package \code{Rsolnp}) or \code{donlp2} (from package
- \code{Rdonlp2}) are used which handle general linear (in-)equality
- constraints.
+ Models are fitted by the EM algorithm if there are no constraints on the
+ parameters. Aspects of the EM algorithm can be controlled through the
+ \code{emcontrol} argument; see details in \code{\link{em.control}}.
+ Otherwise the general optimizers \code{solnp}, the default (from package
+ \code{Rsolnp}) or \code{donlp2} (from package \code{Rdonlp2}) are used
+ which handle general linear (in-)equality constraints. These optimizers
+ are selected by setting method='rsolnp' or method='donlp' respectively.
Three types of constraints can be specified on the parameters: fixed,
equality, and general linear (in-)equality constraints. Constraint
More information about the depmix-commits
mailing list