From noreply at r-forge.r-project.org Sun Feb 2 18:11:31 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 2 Feb 2014 18:11:31 +0100 (CET) Subject: [Pomp-commits] r884 - in pkg/pomp: . R inst man tests Message-ID: <20140202171131.A547D184C61@r-forge.r-project.org> Author: kingaa Date: 2014-02-02 18:11:31 +0100 (Sun, 02 Feb 2014) New Revision: 884 Added: pkg/pomp/R/abc-methods.R pkg/pomp/R/abc.R pkg/pomp/man/abc-methods.Rd pkg/pomp/man/abc.Rd pkg/pomp/tests/abc.R pkg/pomp/tests/abc.Rout.save Modified: pkg/pomp/DESCRIPTION pkg/pomp/NAMESPACE pkg/pomp/R/pmcmc-methods.R pkg/pomp/inst/NEWS pkg/pomp/man/mif.Rd pkg/pomp/man/pmcmc.Rd Log: - add ABC method - minor tweaks to documentation for mif, pmcmc Modified: pkg/pomp/DESCRIPTION =================================================================== --- pkg/pomp/DESCRIPTION 2014-01-14 17:48:08 UTC (rev 883) +++ pkg/pomp/DESCRIPTION 2014-02-02 17:11:31 UTC (rev 884) @@ -1,10 +1,9 @@ Package: pomp Type: Package Title: Statistical inference for partially observed Markov processes -Version: 0.46-1 -Date: 2014-01-10 -Authors at R: c( - person(given=c("Aaron","A."),family="King", +Version: 0.47-1 +Date: 2014-02-02 +Authors at R: c(person(given=c("Aaron","A."),family="King", role=c("aut","cre"),email="kingaa at umich.edu"), person(given=c("Edward","L."),family="Ionides",role=c("aut")), person(given=c("Carles"),family="Breto",role=c("aut")), @@ -23,6 +22,7 @@ License: GPL(>= 2) LazyData: true BuildVignettes: true +MailingList: Subscribe to pomp-announce at r-forge.r-project.org for announcements by going to http://lists.r-forge.r-project.org/mailman/listinfo/pomp-announce. Collate: aaa.R authors.R version.R eulermultinom.R plugins.R parmat.R logmeanexp.R slice-design.R profile-design.R sobol.R bsplines.R sannbox.R @@ -35,4 +35,5 @@ pmcmc.R pmcmc-methods.R compare-pmcmc.R nlf-funcs.R nlf-guts.R nlf-objfun.R nlf.R probe.R probe-match.R basic-probes.R spect.R spect-match.R + abc.R abc-methods.R builder.R example.R Modified: pkg/pomp/NAMESPACE =================================================================== --- pkg/pomp/NAMESPACE 2014-01-14 17:48:08 UTC (rev 883) +++ pkg/pomp/NAMESPACE 2014-02-02 17:11:31 UTC (rev 884) @@ -43,7 +43,8 @@ pmcmc, traj.matched.pomp, probed.pomp,probe.matched.pomp, - spect.pomp,spect.matched.pomp + spect.pomp,spect.matched.pomp, + abc ) exportMethods( @@ -58,7 +59,8 @@ bsmc, pmcmc,dprior, spect,probe, - probe.match,traj.match + probe.match,abc, + traj.match ) export( Added: pkg/pomp/R/abc-methods.R =================================================================== --- pkg/pomp/R/abc-methods.R (rev 0) +++ pkg/pomp/R/abc-methods.R 2014-02-02 17:11:31 UTC (rev 884) @@ -0,0 +1,40 @@ +## this file contains short definitions of methods for the 'abc' class + +## extract the convergence record +setMethod( + 'conv.rec', + 'abc', + function (object, pars, ...) { + if (missing(pars)) pars <- colnames(object at conv.rec) + object at conv.rec[,pars] + } + ) + +## plot pmcmc object +setMethod( + "plot", + "abc", + function (x, y, pars, scatter = FALSE, ...) { + if (missing(pars)) pars <- x at pars + if (scatter) { + pairs(conv.rec(x, pars)) + } else { + plot.ts(conv.rec(x,pars),main="Convergence record") + } + } + ) + +setMethod( + "dprior", + signature=signature(object="abc"), + function (object, params, log = FALSE, ...) { + do.call( + object at dprior, + list( + params=params, + hyperparams=object at hyperparams, + log=log + ) + ) + } + ) Added: pkg/pomp/R/abc.R =================================================================== --- pkg/pomp/R/abc.R (rev 0) +++ pkg/pomp/R/abc.R 2014-02-02 17:11:31 UTC (rev 884) @@ -0,0 +1,387 @@ +## define the abc class +setClass( + 'abc', + contains='pomp', + slots=c( + pars = 'character', + transform = 'logical', + Nabc = 'integer', + dprior = 'function', + probes='list', + scale = 'numeric', + epsilon = 'numeric', + hyperparams = 'list', + random.walk.sd = 'numeric', + conv.rec = 'matrix' + ) + ) + +## ABC algorithm functions +setGeneric('abc',function(object,...)standardGeneric("abc")) + +abc.internal <- function (object, Nabc, + start, pars, dprior.fun, + rw.sd, probes, + hyperparams, + epsilon, scale, + verbose, transform, + .ndone, .getnativesymbolinfo = TRUE, + ...) { + + gnsi <- as.logical(.getnativesymbolinfo) + + transform <- as.logical(transform) + + Nabc <- as.integer(Nabc) + + if (length(start)==0) + stop( + "abc error: ",sQuote("start")," must be specified if ", + sQuote("coef(object)")," is NULL", + call.=FALSE + ) + + start.names <- names(start) + if (is.null(start.names)) + stop("abc error: ",sQuote("start")," must be a named vector",call.=FALSE) + + if (missing(rw.sd)) + stop("abc error: ",sQuote("rw.sd")," must be specified",call.=FALSE) + rw.names <- names(rw.sd) + if (is.null(rw.names) || any(rw.sd<0)) + stop("abc error: ",sQuote("rw.sd")," must be a named non-negative numerical vector",call.=FALSE) + if (!all(rw.names%in%start.names)) + stop("abc error: all the names of ",sQuote("rw.sd")," must be names of ",sQuote("start"),call.=FALSE) + rw.names <- names(rw.sd[rw.sd>0]) + if (length(rw.names) == 0) + stop("abc error: ",sQuote("rw.sd")," must have one positive entry for each parameter to be estimated",call.=FALSE) + + if ( + !is.character(pars) || + !all(pars%in%start.names) || + !all(pars%in%rw.names) + ) + stop( + "abc error: ", + sQuote("pars"), + " must be a mutually disjoint subset of ", + sQuote("names(start)"), + " and must correspond to positive random-walk SDs specified in ", + sQuote("rw.sd"), + call.=FALSE + ) + + if (!all(rw.names%in%pars)) { + extra.rws <- rw.names[!(rw.names%in%pars)] + warning( + "abc warning: the variable(s) ", + paste(extra.rws,collapse=", "), + " have positive random-walk SDs specified, but are not included in ", + sQuote("pars"), + ". These random walk SDs are ignored.", + call.=FALSE + ) + } + rw.sd <- rw.sd[pars] + rw.names <- names(rw.sd) + + if (!is.list(probes)) probes <- list(probes) + if (!all(sapply(probes,is.function))) + stop(sQuote("probes")," must be a function or a list of functions") + if (!all(sapply(probes,function(f)length(formals(f))==1))) + stop("each probe must be a function of a single argument") + + ntimes <- length(time(object)) + + if (verbose) { + cat("performing",Nabc,"ABC iteration(s) to estimate parameter(s)", + paste(pars,collapse=", ")) + cat(" using random-walk with SD\n") + print(rw.sd) + } + + theta <- start + log.prior <- dprior.fun(params=theta,hyperparams=hyperparams,log=TRUE) + ## we suppose that theta is a "match", which does the right thing for continue() and + ## should have negligible effect unless doing many short calls to continue() + + conv.rec <- matrix( + data=NA, + nrow=Nabc+1, + ncol=length(theta), + dimnames=list( + rownames=seq(from=0,to=Nabc,by=1), + colnames=names(theta) + ) + ) + + if (!all(is.finite(theta[pars]))) { + stop( + sQuote("abc"), + " error: cannot estimate non-finite parameters: ", + paste( + pars[!is.finite(theta[pars])], + collapse="," + ), + call.=FALSE + ) + } + + po <- as(object,"pomp") + + ## apply probes to data + datval <- try(.Call(apply_probe_data,po,probes),silent=FALSE) + if (inherits(datval,'try-error')) + stop("abc error: error in ",sQuote("apply_probe_data"),call.=FALSE) + + conv.rec[1,names(theta)] <- theta + + for (n in seq_len(Nabc)) { # main loop + + theta.prop <- theta + theta.prop[pars] <- rnorm(n=length(pars),mean=theta.prop[pars],sd=rw.sd) + + ## compute the probes for the proposed new parameter values + + simval <- try( + .Call( + apply_probe_sim, + object=po, + nsim=1, + params=theta.prop, + seed=NULL, + probes=probes, + datval=datval + ), + silent=FALSE + ) + + if (inherits(simval,'try-error')) + stop("abc error: error in ",sQuote("apply_probe_sim"),call.=FALSE) + + ## ABC update rule + distance <- sum(((datval-simval)/scale)^2) + if( (is.finite(distance)) && (distance0] + } + + if (missing(probes)) + stop("abc error: ",sQuote("probes")," must be specified",call.=FALSE) + + if (missing(scale)) + stop("abc error: ",sQuote("scale")," must be specified",call.=FALSE) + + if (missing(epsilon)) + stop("abc error: ",sQuote("abc match criterion, epsilon,")," must be specified",call.=FALSE) + + if (missing(hyperparams)) + stop("abc error: ",sQuote("hyperparams")," must be specified",call.=FALSE) + + if (missing(dprior)) { # use default flat improper prior + dprior <- function (params, hyperparams, log) { + if (log) 0 else 1 + } + } else { + dprior <- match.fun(dprior) + if (!all(c('params','hyperparams','log')%in%names(formals(dprior)))) + stop( + "abc error: ", + sQuote("dprior"), + " must be a function of prototype ", + sQuote("dprior(params,hyperparams,log)"), + call.=FALSE + ) + } + + abc.internal( + object=object, + Nabc=Nabc, + start=start, + pars=pars, + dprior.fun=dprior, + probes=probes, + scale=scale, + epsilon=epsilon, + rw.sd=rw.sd, + hyperparams=hyperparams, + verbose=verbose, + transform=transform, + .ndone=0 + ) + } + ) + +setMethod( + "abc", + signature=signature(object="probed.pomp"), + function (object, Nabc = 1, + start, pars, rw.sd, + dprior, probes, scale, epsilon, hyperparams, + verbose = getOption("verbose"), + transform = FALSE, + ...) { + + transform <- as.logical(transform) + + if (missing(start)) start <- coef(object,transform=transform) + + if (missing(rw.sd)) + stop("abc error: ",sQuote("rw.sd")," must be specified",call.=FALSE) + + if (missing(pars)) { + pars <- names(rw.sd)[rw.sd>0] + } + + if (missing(probes)) probes <- object at probes + if (missing(scale)) probes <- object at scale + if (missing(epsilon)) probes <- object at epsilon + + if (missing(hyperparams)) + stop("abc error: ",sQuote("hyperparams")," must be specified",call.=FALSE) + + if (missing(dprior)) { # use default flat improper prior + dprior <- function (params, hyperparams, log) { + if (log) 0 else 1 + } + } else { + dprior <- match.fun(dprior) + if (!all(c('params','hyperparams','log')%in%names(formals(dprior)))) + stop( + "abc error: ", + sQuote("dprior"), + " must be a function of prototype ", + sQuote("dprior(params,hyperparams,log)"), + call.=FALSE + ) + } + + abc.internal( + object=as(object,"pomp"), + Nabc=Nabc, + start=start, + pars=pars, + dprior.fun=dprior, + probes=probes, + scale=scale, + epsilon=epsilon, + rw.sd=rw.sd, + hyperparams=hyperparams, + verbose=verbose, + transform=transform, + .ndone=0 + ) + } + ) + +setMethod( + "abc", + signature=signature(object="abc"), + function (object, Nabc, + start, pars, rw.sd, + dprior, probes, scale, epsilon, hyperparams, + verbose = getOption("verbose"), + transform, + ...) { + + if (missing(Nabc)) Nabc <- object at Nabc + if (missing(start)) start <- coef(object) + if (missing(pars)) pars <- object at pars + if (missing(rw.sd)) pars <- object at random.walk.sd + if (missing(dprior)) dprior <- object at dprior + if (missing(probes)) probes <- object at probes + if (missing(scale)) probes <- object at scale + if (missing(epsilon)) probes <- object at epsilon + if (missing(hyperparams)) hyperparams <- object at hyperparams + if (missing(transform)) transform <- object at transform + transform <- as.logical(transform) + + abc.internal( + object=as(object,"pomp"), + Nabc=Nabc, + start=start, + pars=pars, + dprior.fun=dprior, + rw.sd=rw.sd, + probes=probes, + scale=scale, + epsilon=epsilon, + hyperparams=hyperparams, + verbose=verbose, + transform=transform, + .ndone=0 + ) + } + ) + +setMethod( + 'continue', + signature=signature(object='abc'), + function (object, Nabc = 1, ...) { + + ndone <- object at Nabc + + obj <- abc( + object=object, + Nabc=Nabc, + .ndone=ndone, + ... + ) + + obj at conv.rec <- rbind( + object at conv.rec[,colnames(obj at conv.rec)], + obj at conv.rec[-1,] + ) + obj at Nabc <- as.integer(ndone+Nabc) + obj + } + ) Modified: pkg/pomp/R/pmcmc-methods.R =================================================================== --- pkg/pomp/R/pmcmc-methods.R 2014-01-14 17:48:08 UTC (rev 883) +++ pkg/pomp/R/pmcmc-methods.R 2014-02-02 17:11:31 UTC (rev 884) @@ -31,4 +31,3 @@ compare.pmcmc(x) } ) - Modified: pkg/pomp/inst/NEWS =================================================================== --- pkg/pomp/inst/NEWS 2014-01-14 17:48:08 UTC (rev 883) +++ pkg/pomp/inst/NEWS 2014-02-02 17:11:31 UTC (rev 884) @@ -1,4 +1,7 @@ NEWS +0.47-1 + o 'abc' implements Approximate Bayesian Computation for pomp models. + 0.46-1 o 'pompExample' now has an optional argument, 'envir', determining which environment the pomp object will be loaded into. Added: pkg/pomp/man/abc-methods.Rd =================================================================== --- pkg/pomp/man/abc-methods.Rd (rev 0) +++ pkg/pomp/man/abc-methods.Rd 2014-02-02 17:11:31 UTC (rev 884) @@ -0,0 +1,43 @@ +\name{abc-methods} +\docType{methods} +\alias{abc-methods} +\alias{dprior,abc-method} +\alias{dprior-abc} +\alias{conv.rec,abc-method} +\alias{conv.rec-abc} +\alias{plot-abc} +\alias{plot,abc-method} +\title{Methods of the "abc" class} +\description{Methods of the "abc" class.} +\usage{ +\S4method{conv.rec}{abc}(object, pars, \dots) +\S4method{plot}{abc}(x, y, pars, scatter = FALSE, \dots) +\S4method{dprior}{abc}(object, params, log = FALSE, \dots) +} +\arguments{ + \item{object, x}{The \code{abc} object.} + \item{pars}{Names of parameters.} + \item{y}{Ignored.} + \item{scatter}{WHAT DOES THIS DO?} + \item{params}{ + Named vector of parameters. + } + \item{log}{if TRUE, log probabilities are returned.} + \item{\dots}{ + Further arguments (either ignored or passed to underlying functions). + } +} +\section{Methods}{ + \describe{ + \item{conv.rec}{ + \code{conv.rec(object, pars = NULL)} returns the columns of the convergence-record matrix corresponding to the names in \code{pars}. + By default, all rows are returned. + } + \item{plot}{ + Plots a series of diagnostic plots. + } + } +} +\author{Edward L. Ionides \email{ionides at umich dot edu}, Aaron A. King \email{kingaa at umich dot edu}} +\seealso{\code{\link{abc}}, \code{\link{pomp}}} +\keyword{ts} Added: pkg/pomp/man/abc.Rd =================================================================== --- pkg/pomp/man/abc.Rd (rev 0) +++ pkg/pomp/man/abc.Rd 2014-02-02 17:11:31 UTC (rev 884) @@ -0,0 +1,124 @@ +\name{abc} +\docType{methods} +\alias{abc} +\alias{abc-abc} +\alias{abc,probed.pomp-method} +\alias{abc-probed.pomp} +\alias{abc,pomp-method} +\alias{abc-pomp} +\alias{abc,abc-method} +\alias{abc-abc} +\alias{continue,abc-method} +\alias{continue-abc} +\alias{abc-class} +\title{The ABC algorithm} +\description{ + The approximate Bayesian computation (ABC) algorithm for estimating the parameters of a partially-observed Markov process. +} +\usage{ +\S4method{abc}{pomp}(object, Nabc = 1, start, pars, + rw.sd, dprior, probes, scale, epsilon, hyperparams, + verbose = getOption("verbose"), transform = FALSE, \dots) +\S4method{abc}{probed.pomp}(object, Nabc = 1, start, pars, + rw.sd, dprior, probes, scale, epsilon, hyperparams, + verbose = getOption("verbose"), transform = FALSE, \dots) +\S4method{abc}{abc}(object, Nabc, start, pars, + rw.sd, dprior, probes, scale, epsilon, hyperparams, + verbose = getOption("verbose"), transform, \dots) +\S4method{continue}{abc}(object, Nabc = 1, \dots) +} +\arguments{ + \item{object}{ + An object of class \code{pomp}. + } + \item{Nabc}{ + The number of ABC iterations to perform. + } + \item{start}{ + named numeric vector; + the starting guess of the parameters. + } + \item{pars}{ + optional character vector naming the ordinary parameters to be estimated. + Every parameter named in \code{pars} must have a positive random-walk standard deviation specified in \code{rw.sd}. + Leaving \code{pars} unspecified is equivalent to setting it equal to the names of all parameters with a positive value of \code{rw.sd}. + } + \item{rw.sd}{ + numeric vector with names; used to parameterize a Gaussian random walk MCMC proposal. + The random walk is only applied to parameters named in \code{pars}. + The algorithm requires that the random walk be nontrivial, so each element in \code{rw.sd[pars]} must be positive. + The following must be satisfied: + \code{names(rw.sd)} must be a subset of \code{names(start)}, + \code{rw.sd} must be non-negative (zeros are simply ignored), + the name of every positive element of \code{rw.sd} must be in \code{pars}. + } + \item{dprior}{ + Function of prototype \code{dprior(params,hyperparams,...,log)} that evaluates the prior density. + This defaults to an improper uniform prior. + } + \item{probes}{ + } + \item{scale}{ + + } + \item{epsilon}{ + + } + \item{hyperparams}{ + optional list; parameters to be passed to \code{dprior}. + } + \item{verbose}{ + logical; if TRUE, print progress reports. + } + \item{transform}{ + logical; + if \code{TRUE}, optimization is performed on the transformed scale. + } + \item{\dots}{ + Additional arguments. + These are currently ignored. + } +} +\value{ + An object of class \code{abc}. + This class inherits from class \code{\link[=probed.pomp-class]{probed.pomp}} and contains the following additional slots: + \describe{ + \item{pars, Nabc, dprior, hyperparams, transform, scale, epsilon}{ + These slots hold the values of the corresponding arguments of the call to \code{abc}. + } + \item{random.walk.sd}{ + a named numeric vector containing the random-walk variances used to parameterize a Gaussian random walk MCMC proposal. + } + \item{probes, conv.rec}{ + } + } +} +\section{Re-running ABC Iterations}{ + To re-run a sequence of ABC iterations, one can use the \code{abc} method on a \code{abc} object. + By default, the same parameters used for the original ABC run are re-used (except for \code{tol}, \code{max.fail}, and \code{verbose}, the defaults of which are shown above). + If one does specify additional arguments, these will override the defaults. +} +\section{Continuing ABC Iterations}{ + One can continue a series of ABC iterations from where one left off using the \code{continue} method. + A call to \code{abc} to perform \code{Nabc=m} iterations followed by a call to \code{continue} to perform \code{Nabc=n} iterations will produce precisely the same effect as a single call to \code{abc} to perform \code{Nabc=m+n} iterations. + By default, all the algorithmic parameters are the same as used in the original call to \code{abc}. + Additional arguments will override the defaults. +} +\section{Details}{ + TO APPEAR. +} +\references{ + T. Toni and M. P. H. Stumpf, + Simulation-based model selection for dynamical systems in systems and population biology, + Bioinformatics 26:104--110, 2010. + + T. Toni, D. Welch, N. Strelkowa, A. Ipsen, and M. P. H. Stumpf, + Approximate Bayesian computation scheme for parameter inference and model selection in dynamical systems + Journal of the Royal Society, Interface 6:187--202, 2009. +} +\author{Edward L. Ionides \email{ionides at umich dot edu}, Aaron A. King \email{kingaa at umich dot edu}} +\seealso{ + \link{abc-methods}, \code{\link{pomp}}, \code{\link{probe}}. + See the \dQuote{intro_to_pomp} vignette for an example +} +\keyword{ts} Modified: pkg/pomp/man/mif.Rd =================================================================== --- pkg/pomp/man/mif.Rd 2014-01-14 17:48:08 UTC (rev 883) +++ pkg/pomp/man/mif.Rd 2014-02-02 17:11:31 UTC (rev 884) @@ -175,5 +175,4 @@ \code{\link{mif-methods}}, \code{\link{pomp}}, \code{\link{pomp-class}}, \code{\link{pfilter}}. See the \dQuote{intro_to_pomp} vignette for examples. } -\keyword{models} \keyword{ts} Modified: pkg/pomp/man/pmcmc.Rd =================================================================== --- pkg/pomp/man/pmcmc.Rd 2014-01-14 17:48:08 UTC (rev 883) +++ pkg/pomp/man/pmcmc.Rd 2014-02-02 17:11:31 UTC (rev 884) @@ -124,5 +124,4 @@ See the \dQuote{intro_to_pomp} vignette for an example [CURRENTLY, ONLY DEMONSTRATING THE MIF ALGORITHM, WHICH IS ALGORITHMICALLY VERY SIMILAR TO PMCMC SINCE THEY BOTH DEPEND CRITICALLY ON A PARTICLE FILTERING STEP]. } -\keyword{models} \keyword{ts} Added: pkg/pomp/tests/abc.R =================================================================== --- pkg/pomp/tests/abc.R (rev 0) +++ pkg/pomp/tests/abc.R 2014-02-02 17:11:31 UTC (rev 884) @@ -0,0 +1,48 @@ +### OU2 test of abc for pomp; nov 2013 + +library(pomp) +pompExample(ou2) +plot(ou2) + +pdf(file='abc.pdf') + +set.seed(2079015564L) + +probes.good <- list( + y1.mean=probe.mean(var="y1"), + y2.mean=probe.mean(var="y2"), + probe.acf(var="y1",lags=c(0,5)), + probe.acf(var="y2",lags=c(0,5)), + probe.ccf(vars=c("y1","y2"),lags=0) + ) +psim <- probe(ou2,probes=probes.good,nsim=200) +plot(psim) +## why do simulations sometimes seem extreme with respect to these probes? + +scale.dat <- apply(psim at simvals,2,sd) + +po <- ou2 + +theta <- coef(ou2) + +abc1 <- abc(po, + Nabc=10000, + start=coef(ou2), + pars=c("alpha.1","alpha.2"), + probes=probes.good, + scale=scale.dat, + epsilon=3, + rw.sd= c(alpha.1=0.01,alpha.2=0.01), + hyperparams=list(junk=0), + verbose=TRUE + ) + +plot(abc1,scatter=TRUE) +plot(abc1) + +## check how sticky the chain is: +runs <- rle(as.vector(conv.rec(abc1)[, "alpha.1"])) +hist(runs$lengths) +mean(runs$length) + +dev.off() Added: pkg/pomp/tests/abc.Rout.save =================================================================== --- pkg/pomp/tests/abc.Rout.save (rev 0) +++ pkg/pomp/tests/abc.Rout.save 2014-02-02 17:11:31 UTC (rev 884) @@ -0,0 +1,2080 @@ + +R version 3.0.2 (2013-09-25) -- "Frisbee Sailing" +Copyright (C) 2013 The R Foundation for Statistical Computing +Platform: x86_64-unknown-linux-gnu (64-bit) + +R is free software and comes with ABSOLUTELY NO WARRANTY. +You are welcome to redistribute it under certain conditions. +Type 'license()' or 'licence()' for distribution details. + +R is a collaborative project with many contributors. +Type 'contributors()' for more information and +'citation()' on how to cite R or R packages in publications. + +Type 'demo()' for some demos, 'help()' for on-line help, or +'help.start()' for an HTML browser interface to help. +Type 'q()' to quit R. + +> ### OU2 test of abc for pomp; nov 2013 +> +> library(pomp) +Loading required package: mvtnorm +Loading required package: subplex +Loading required package: deSolve +> pompExample(ou2) +newly created pomp object(s): + ou2 +> plot(ou2) +> +> pdf(file='abc.pdf') +> +> set.seed(2079015564L) +> +> probes.good <- list( ++ y1.mean=probe.mean(var="y1"), ++ y2.mean=probe.mean(var="y2"), ++ probe.acf(var="y1",lags=c(0,5)), ++ probe.acf(var="y2",lags=c(0,5)), ++ probe.ccf(vars=c("y1","y2"),lags=0) ++ ) +> psim <- probe(ou2,probes=probes.good,nsim=200) +> plot(psim) +> ## why do simulations sometimes seem extreme with respect to these probes? +> +> scale.dat <- apply(psim at simvals,2,sd) +> +> po <- ou2 +> +> theta <- coef(ou2) +> +> abc1 <- abc(po, ++ Nabc=10000, ++ start=coef(ou2), ++ pars=c("alpha.1","alpha.2"), ++ probes=probes.good, ++ scale=scale.dat, ++ epsilon=3, ++ rw.sd= c(alpha.1=0.01,alpha.2=0.01), ++ hyperparams=list(junk=0), ++ verbose=TRUE ++ ) +performing 10000 ABC iteration(s) to estimate parameter(s) alpha.1, alpha.2 using random-walk with SD +alpha.1 alpha.2 + 0.01 0.01 +ABC iteration 5 of 10000 completed +ABC iteration 10 of 10000 completed +ABC iteration 15 of 10000 completed +ABC iteration 20 of 10000 completed +ABC iteration 25 of 10000 completed +ABC iteration 30 of 10000 completed +ABC iteration 35 of 10000 completed +ABC iteration 40 of 10000 completed +ABC iteration 45 of 10000 completed +ABC iteration 50 of 10000 completed +ABC iteration 55 of 10000 completed +ABC iteration 60 of 10000 completed +ABC iteration 65 of 10000 completed +ABC iteration 70 of 10000 completed +ABC iteration 75 of 10000 completed +ABC iteration 80 of 10000 completed +ABC iteration 85 of 10000 completed +ABC iteration 90 of 10000 completed +ABC iteration 95 of 10000 completed +ABC iteration 100 of 10000 completed +ABC iteration 105 of 10000 completed +ABC iteration 110 of 10000 completed +ABC iteration 115 of 10000 completed +ABC iteration 120 of 10000 completed +ABC iteration 125 of 10000 completed +ABC iteration 130 of 10000 completed +ABC iteration 135 of 10000 completed +ABC iteration 140 of 10000 completed +ABC iteration 145 of 10000 completed +ABC iteration 150 of 10000 completed +ABC iteration 155 of 10000 completed +ABC iteration 160 of 10000 completed +ABC iteration 165 of 10000 completed +ABC iteration 170 of 10000 completed +ABC iteration 175 of 10000 completed +ABC iteration 180 of 10000 completed +ABC iteration 185 of 10000 completed +ABC iteration 190 of 10000 completed +ABC iteration 195 of 10000 completed +ABC iteration 200 of 10000 completed +ABC iteration 205 of 10000 completed +ABC iteration 210 of 10000 completed +ABC iteration 215 of 10000 completed +ABC iteration 220 of 10000 completed +ABC iteration 225 of 10000 completed +ABC iteration 230 of 10000 completed +ABC iteration 235 of 10000 completed +ABC iteration 240 of 10000 completed +ABC iteration 245 of 10000 completed +ABC iteration 250 of 10000 completed +ABC iteration 255 of 10000 completed +ABC iteration 260 of 10000 completed +ABC iteration 265 of 10000 completed +ABC iteration 270 of 10000 completed +ABC iteration 275 of 10000 completed +ABC iteration 280 of 10000 completed +ABC iteration 285 of 10000 completed +ABC iteration 290 of 10000 completed +ABC iteration 295 of 10000 completed +ABC iteration 300 of 10000 completed +ABC iteration 305 of 10000 completed +ABC iteration 310 of 10000 completed +ABC iteration 315 of 10000 completed +ABC iteration 320 of 10000 completed +ABC iteration 325 of 10000 completed +ABC iteration 330 of 10000 completed +ABC iteration 335 of 10000 completed +ABC iteration 340 of 10000 completed +ABC iteration 345 of 10000 completed +ABC iteration 350 of 10000 completed +ABC iteration 355 of 10000 completed +ABC iteration 360 of 10000 completed +ABC iteration 365 of 10000 completed +ABC iteration 370 of 10000 completed +ABC iteration 375 of 10000 completed +ABC iteration 380 of 10000 completed +ABC iteration 385 of 10000 completed +ABC iteration 390 of 10000 completed +ABC iteration 395 of 10000 completed +ABC iteration 400 of 10000 completed +ABC iteration 405 of 10000 completed +ABC iteration 410 of 10000 completed +ABC iteration 415 of 10000 completed +ABC iteration 420 of 10000 completed +ABC iteration 425 of 10000 completed +ABC iteration 430 of 10000 completed +ABC iteration 435 of 10000 completed +ABC iteration 440 of 10000 completed +ABC iteration 445 of 10000 completed +ABC iteration 450 of 10000 completed +ABC iteration 455 of 10000 completed +ABC iteration 460 of 10000 completed +ABC iteration 465 of 10000 completed +ABC iteration 470 of 10000 completed +ABC iteration 475 of 10000 completed +ABC iteration 480 of 10000 completed +ABC iteration 485 of 10000 completed +ABC iteration 490 of 10000 completed +ABC iteration 495 of 10000 completed +ABC iteration 500 of 10000 completed +ABC iteration 505 of 10000 completed +ABC iteration 510 of 10000 completed +ABC iteration 515 of 10000 completed +ABC iteration 520 of 10000 completed +ABC iteration 525 of 10000 completed +ABC iteration 530 of 10000 completed +ABC iteration 535 of 10000 completed +ABC iteration 540 of 10000 completed +ABC iteration 545 of 10000 completed +ABC iteration 550 of 10000 completed +ABC iteration 555 of 10000 completed +ABC iteration 560 of 10000 completed +ABC iteration 565 of 10000 completed +ABC iteration 570 of 10000 completed +ABC iteration 575 of 10000 completed [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/pomp -r 884 From noreply at r-forge.r-project.org Mon Feb 3 23:32:56 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 3 Feb 2014 23:32:56 +0100 (CET) Subject: [Pomp-commits] r885 - pkg/pomp/tests Message-ID: <20140203223256.E4C6C1868FF@r-forge.r-project.org> Author: kingaa Date: 2014-02-03 23:32:56 +0100 (Mon, 03 Feb 2014) New Revision: 885 Modified: pkg/pomp/tests/steps.R pkg/pomp/tests/steps.Rout.save Log: - modify this test for compatibility with R/devel Modified: pkg/pomp/tests/steps.R =================================================================== --- pkg/pomp/tests/steps.R 2014-02-02 17:11:31 UTC (rev 884) +++ pkg/pomp/tests/steps.R 2014-02-03 22:32:56 UTC (rev 885) @@ -14,4 +14,4 @@ tm <- sort(runif(n=100,max=1)) x <- trajectory(verhulst,times=tm)["n",,] y <- simulate(verhulst,times=tm,states=TRUE)["n",,] -table(cut(x-y,breaks=10)) +table(cut(x-y,breaks=c(-Inf,seq(-0.2,0.2,by=0.01),Inf),ordered=T)) Modified: pkg/pomp/tests/steps.Rout.save =================================================================== --- pkg/pomp/tests/steps.Rout.save 2014-02-02 17:11:31 UTC (rev 884) +++ pkg/pomp/tests/steps.Rout.save 2014-02-03 22:32:56 UTC (rev 885) @@ -38,15 +38,27 @@ > tm <- sort(runif(n=100,max=1)) > x <- trajectory(verhulst,times=tm)["n",,] > y <- simulate(verhulst,times=tm,states=TRUE)["n",,] -> table(cut(x-y,breaks=10)) +> table(cut(x-y,breaks=c(-Inf,seq(-0.2,0.2,by=0.01),Inf),ordered=T)) -(0.000885,0.0115] (0.0115,0.0222] (0.0222,0.0328] (0.0328,0.0434] - 13 14 16 8 - (0.0434,0.0541] (0.0541,0.0647] (0.0647,0.0753] (0.0753,0.086] - 9 11 7 4 - (0.086,0.0966] (0.0966,0.107] - 10 8 + (-Inf,-0.2] (-0.2,-0.19] (-0.19,-0.18] (-0.18,-0.17] (-0.17,-0.16] + 0 0 0 0 0 +(-0.16,-0.15] (-0.15,-0.14] (-0.14,-0.13] (-0.13,-0.12] (-0.12,-0.11] + 0 0 0 0 0 + (-0.11,-0.1] (-0.1,-0.09] (-0.09,-0.08] (-0.08,-0.07] (-0.07,-0.06] + 0 0 0 0 0 +(-0.06,-0.05] (-0.05,-0.04] (-0.04,-0.03] (-0.03,-0.02] (-0.02,-0.01] + 0 0 0 0 0 + (-0.01,0] (0,0.01] (0.01,0.02] (0.02,0.03] (0.03,0.04] + 0 13 11 11 8 + (0.04,0.05] (0.05,0.06] (0.06,0.07] (0.07,0.08] (0.08,0.09] + 13 13 8 3 3 + (0.09,0.1] (0.1,0.11] (0.11,0.12] (0.12,0.13] (0.13,0.14] + 11 6 0 0 0 + (0.14,0.15] (0.15,0.16] (0.16,0.17] (0.17,0.18] (0.18,0.19] + 0 0 0 0 0 + (0.19,0.2] (0.2, Inf] + 0 0 > > proc.time() user system elapsed - 0.516 0.056 0.583 + 0.516 0.052 0.581 From noreply at r-forge.r-project.org Thu Feb 27 03:20:25 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 27 Feb 2014 03:20:25 +0100 (CET) Subject: [Pomp-commits] r886 - in pkg/pomp: . R inst man Message-ID: <20140227022025.7EB09186946@r-forge.r-project.org> Author: kingaa Date: 2014-02-27 03:20:24 +0100 (Thu, 27 Feb 2014) New Revision: 886 Modified: pkg/pomp/DESCRIPTION pkg/pomp/R/builder.R pkg/pomp/R/mif.R pkg/pomp/inst/NEWS pkg/pomp/man/builder.Rd Log: - pompBuilder now puts files in the temporary directory - fix error with ic.lag in 'mif' Modified: pkg/pomp/DESCRIPTION =================================================================== --- pkg/pomp/DESCRIPTION 2014-02-03 22:32:56 UTC (rev 885) +++ pkg/pomp/DESCRIPTION 2014-02-27 02:20:24 UTC (rev 886) @@ -1,8 +1,8 @@ Package: pomp Type: Package Title: Statistical inference for partially observed Markov processes -Version: 0.47-1 -Date: 2014-02-02 +Version: 0.47-2 +Date: 2014-02-26 Authors at R: c(person(given=c("Aaron","A."),family="King", role=c("aut","cre"),email="kingaa at umich.edu"), person(given=c("Edward","L."),family="Ionides",role=c("aut")), Modified: pkg/pomp/R/builder.R =================================================================== --- pkg/pomp/R/builder.R 2014-02-03 22:32:56 UTC (rev 885) +++ pkg/pomp/R/builder.R 2014-02-27 02:20:24 UTC (rev 886) @@ -24,7 +24,7 @@ rmeasure, dmeasure, step.fn, step.fn.delta.t, skeleton, skeleton.type, skelmap.delta.t = 1, parameter.transform, parameter.inv.transform, - ..., link = TRUE) { + ..., link = TRUE, save = FALSE) { if (!is.data.frame(data)) stop(sQuote("data")," must be a data-frame") obsnames <- names(data) obsnames <- setdiff(obsnames,times) @@ -37,20 +37,27 @@ tcovar <- numeric(0) covarnames <- character(0) } - solib <- pompCBuilder( - name=name, - statenames=statenames, - paramnames=paramnames, - covarnames=covarnames, - obsnames=obsnames, - rmeasure=rmeasure, - dmeasure=dmeasure, - step.fn=step.fn, - skeleton=skeleton, - parameter.transform=parameter.transform, - parameter.inv.transform=parameter.inv.transform - ) - if (link) pompLink(name) + pompCBuilder( + name=name, + statenames=statenames, + paramnames=paramnames, + covarnames=covarnames, + obsnames=obsnames, + rmeasure=rmeasure, + dmeasure=dmeasure, + step.fn=step.fn, + skeleton=skeleton, + parameter.transform=parameter.transform, + parameter.inv.transform=parameter.inv.transform, + save=save + ) + if (link) { + if (save) { + pompLink(name) + } else { + pompLink(file.path(tempdir(),name)) + } + } pomp( data=data,times=times,t0=t0, rprocess=euler.sim( @@ -125,8 +132,10 @@ ) -pompCBuilder <- function (name, statenames, paramnames, covarnames, obsnames, rmeasure, dmeasure, - step.fn, skeleton, parameter.transform, parameter.inv.transform) +pompCBuilder <- function (name, statenames, paramnames, covarnames, obsnames, + rmeasure, dmeasure, step.fn, skeleton, + parameter.transform, parameter.inv.transform, + save = FALSE) { if (missing(name)) stop(sQuote("name")," must be supplied"); if (missing(statenames)) stop(sQuote("statenames")," must be supplied"); @@ -146,8 +155,10 @@ covarnames <- cleanForC(covarnames) obsnames <- cleanForC(obsnames) - modelfile <- paste0(name,".c") - solib <- paste0(name,.Platform$dynlib.ext) + stem <- if (save) name else file.path(tempdir(),name) + modelfile <- paste0(stem,".c") + solib <- paste0(stem,.Platform$dynlib.ext) + if (.Platform$OS.type=="unix") { pompheader <- "pomp.h" } else { @@ -257,7 +268,7 @@ else cat("model codes written to",sQuote(modelfile),"\nlink to shared-object library",sQuote(solib),"\n") - invisible(solib) + invisible(NULL) } cleanForC <- function (text) { Modified: pkg/pomp/R/mif.R =================================================================== --- pkg/pomp/R/mif.R 2014-02-03 22:32:56 UTC (rev 885) +++ pkg/pomp/R/mif.R 2014-02-27 02:20:24 UTC (rev 886) @@ -410,12 +410,14 @@ if (missing(start)) start <- coef(object) if (missing(rw.sd)) stop("mif error: ",sQuote("rw.sd")," must be specified",call.=FALSE) - if (missing(ic.lag) && length(ivps)>0) { - if (method=="mif2") - ic.lag <- length(time(object)) # default mif2 behavior - else - stop("mif error: ",sQuote("ic.lag")," must be specified if ",sQuote("ivps"), + if (missing(ic.lag)) { + if (length(ivps)>0 && (method != "mif2")) { + stop("mif error: ",sQuote("ic.lag"), + " must be specified if ",sQuote("ivps"), " are",call.=FALSE) + } else { + ic.lag <- length(time(object)) + } } if (missing(pars)) { rw.names <- names(rw.sd)[rw.sd>0] Modified: pkg/pomp/inst/NEWS =================================================================== --- pkg/pomp/inst/NEWS 2014-02-03 22:32:56 UTC (rev 885) +++ pkg/pomp/inst/NEWS 2014-02-27 02:20:24 UTC (rev 886) @@ -1,4 +1,7 @@ NEWS +0.47-2 + o By default, 'pompBuilder' now creates all files in the temporary directory. + 0.47-1 o 'abc' implements Approximate Bayesian Computation for pomp models. Modified: pkg/pomp/man/builder.Rd =================================================================== --- pkg/pomp/man/builder.Rd 2014-02-03 22:32:56 UTC (rev 885) +++ pkg/pomp/man/builder.Rd 2014-02-27 02:20:24 UTC (rev 886) @@ -10,7 +10,7 @@ rmeasure, dmeasure, step.fn, step.fn.delta.t, skeleton, skeleton.type, skelmap.delta.t = 1, parameter.transform, parameter.inv.transform, - \dots, link = TRUE) + \dots, link = TRUE, save = FALSE) } \arguments{ \item{data, times, t0}{ @@ -52,6 +52,11 @@ \item{link}{ logical; if TRUE, the resulting code will be linked after compilation. } + \item{save}{ + logical; if TRUE, the resulting C code will be saved in the current working directory. + The shared-object library will also be created in this directory. + If FALSE, the C code and shared-object library will be created in the temporary directory. + } } \value{ The constructed \code{pomp} object.