From ab80c93521b7f77f0e6a09fd25226361b8cc84c9 Mon Sep 17 00:00:00 2001 From: Adam Mantz Date: Thu, 16 Nov 2017 10:00:47 -0800 Subject: [PATCH 1/4] plotting options --- R/rgw/DESCRIPTION | 4 ++-- R/rgw/R/rgw.R | 12 +++++++++++- R/rgw/man/GoodmanWeare.rem.Rd | 31 ++++++++++++++++++++++++++++--- R/rgw/man/rgw-package.Rd | 4 ++-- 4 files changed, 43 insertions(+), 8 deletions(-) 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..e322cc6 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)) 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) Date: Thu, 16 Nov 2017 10:31:51 -0800 Subject: [PATCH 2/4] add history, shields --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ae28d6c..8a54e3c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +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 +48,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 From 0c5d53a46d7b09f3ad55137583e51a4ae8dd76f5 Mon Sep 17 00:00:00 2001 From: Adam Mantz Date: Thu, 16 Nov 2017 10:39:26 -0800 Subject: [PATCH 3/4] typo --- R/rgw/man/GoodmanWeare.rem.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/rgw/man/GoodmanWeare.rem.Rd b/R/rgw/man/GoodmanWeare.rem.Rd index e322cc6..9b4ac85 100644 --- a/R/rgw/man/GoodmanWeare.rem.Rd +++ b/R/rgw/man/GoodmanWeare.rem.Rd @@ -71,7 +71,7 @@ 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)) called on the current graphics +par(mfrow=c(length(show.params), 1)) is called on the current graphics device. } From edba0c7a0d750f2ddc44a75d859c9f9add32de14 Mon Sep 17 00:00:00 2001 From: Adam Mantz Date: Tue, 5 Dec 2017 16:33:46 -0800 Subject: [PATCH 4/4] Added ASCL reference --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8a54e3c..20f9197 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +ascl:1711.006 CRAN MIT License