diff --git a/R/rgw/DESCRIPTION b/R/rgw/DESCRIPTION index 65d3d4b..020ae3c 100644 --- a/R/rgw/DESCRIPTION +++ b/R/rgw/DESCRIPTION @@ -1,8 +1,8 @@ Package: rgw Type: Package Title: Goodman-Weare Affine-Invariant Sampling -Version: 0.1.0 -Date: 2016-10-10 +Version: 0.2.0 +Date: 2017-11-16 Author: Adam Mantz Maintainer: Adam Mantz Description: Implementation of the affine-invariant method of Goodman & Weare (2010) , a method of producing Monte-Carlo samples from a target distribution. diff --git a/R/rgw/R/rgw.R b/R/rgw/R/rgw.R index 6554627..0ae1f2f 100644 --- a/R/rgw/R/rgw.R +++ b/R/rgw/R/rgw.R @@ -41,16 +41,26 @@ GoodmanWeare = function(ensemble, lnpost, Nsteps, current.lnP=NULL, mc.cores=get list(ensemble=ensemble, current.lnP=current.lnP) } -GoodmanWeare.rem = function(post, lnpost, thin=1, mention.every=NA, save.every=NA, save.file=NA, ...) { +GoodmanWeare.rem = function(post, lnpost, thin=1, mention.every=NA, save.every=NA, save.file=NA, show.every=NA, show.params=1:dim(post)[1], show.walkers=min(dim(post)[2],8), show.pch1=1, show.pch2='.', show.pch.switch=500, ...) { ## post should be an Nparam*Nwalkers*Nsteps array with the initial walker positions ## set in post[,,1]. The ensemble will be saved in post[,,i] every thin ## iterations until post is filled. res = list() + if (!is.na(show.every)) { + par(mfrow=c(length(show.params), 1)) + } for (i in 2:dim(post)[3]) { res = GoodmanWeare(post[,,i-1], lnpost, thin, res$current.lnP, ...) post[,,i] = res$ensemble if (!is.na(mention.every) & i %% mention.every == 0) message(paste('Finished iteration', i)) if (!is.na(save.every) & !is.na(save.file) & i %% save.every == 0) save(post, file=save.file) + if (!is.na(show.every) & i %% show.every == 0) { + if (i < show.pch.switch) pch = show.pch1 else pch = show.pch2 + for (j in show.params) { + plot(post[j,1,1:i], ylab=paste('parameter', j), pch=pch, col=1+1) + if (show.walkers > 1) for (k in 2:show.walkers) points(post[j,k,1:i], pch=pch, col=1+k) + } + } } post } diff --git a/R/rgw/man/GoodmanWeare.rem.Rd b/R/rgw/man/GoodmanWeare.rem.Rd index 847477c..9b4ac85 100644 --- a/R/rgw/man/GoodmanWeare.rem.Rd +++ b/R/rgw/man/GoodmanWeare.rem.Rd @@ -9,7 +9,9 @@ Produces a Monte-Carlo Markov ensemble using the affine-invariant method of Good } \usage{ GoodmanWeare.rem(post, lnpost, thin=1, mention.every=NA, - save.every=NA, save.file=NA, ...) + save.every=NA, save.file=NA, show.every=NA, + show.params=1:dim(post)[1], show.walkers=min(dim(post)[2],8), + show.pch1=1, show.pch2='.', show.pch.switch=500, ...) } %- maybe also 'usage' for other objects documented here. \arguments{ @@ -30,9 +32,27 @@ save the accumulated Markov ensemble to disk every time this many iterations are } \item{save.file}{ filename for saving progress. +} + \item{show.every}{ +plot parameter traces so far to the active graphics device periodically. +} + \item{show.params}{ +(sub)set of parameter traces to plot (default is to show all). +} + \item{show.walkers}{ +which walkers to plot traces of (default is first 8). +} + \item{show.pch1}{ +plot symbol to use for short chains. +} + \item{show.pch2}{ +plot symbol to use for long chains. +} + \item{show.pch.switch}{ +chain length that distinguishes "short" and "long" chains for plotting purposes. } \item{...}{ -additional arguments to pass to GoodmanWeare or lnpost. +additional named arguments to pass to GoodmanWeare or lnpost. } } %\details{ @@ -47,7 +67,12 @@ See help for GoodmanWeare. Adam Mantz } \note{ -By default, the code will attempt to run in parallel (see the `parallel' package). To prevent this, pass mc.cores=1. +By default, the code will attempt to run in parallel (see the `parallel' +package). To prevent this, pass mc.cores=1. + +If traces are being plotted (show.every not NA), +par(mfrow=c(length(show.params), 1)) is called on the current graphics +device. } %% ~Make other sections like Warning with \section{Warning }{....} ~ diff --git a/R/rgw/man/rgw-package.Rd b/R/rgw/man/rgw-package.Rd index 5bccc7f..d2c3e9b 100644 --- a/R/rgw/man/rgw-package.Rd +++ b/R/rgw/man/rgw-package.Rd @@ -12,8 +12,8 @@ This package implements the affine-invariant method of Goodman & Weare (2010) ascl:1711.006 +CRAN +MIT License + # rgw This package implements in [R](https://www.r-project.org/) the affine-invariant sampling method of [Goodman & Weare (2010)](http://dx.doi.org/10.2140/camcos.2010.5.65). This is a way of producing Monte-Carlo samples from a target distribution, which can be used for statistical inference. @@ -45,4 +49,11 @@ plot(post[2,1,]) ## Help -Use the [issues](https://github.com/abmantz/rgw/issues). +Open an [issue](https://github.com/abmantz/rgw/issues). + +## History + +Version | Comments +:-----: | -------- +0.2.0 | Added options for plotting traces periodically during the run +0.1.0 | First release --> CRAN