Skip to content

Commit

Permalink
improvements; doFuture
Browse files Browse the repository at this point in the history
  • Loading branch information
kingaa committed Jan 24, 2023
1 parent fb78877 commit 38ea5f3
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 204 deletions.
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ inst/doc/(.+?).md
inst/doc/(.+?).Rmd
man/roxygen
LICENSE\.md$
README\.md$
README\.(.?)$
CRAN\.md$
TODO\.md$
^\.gitignore$
Expand Down
115 changes: 0 additions & 115 deletions .github/workflows/create-release.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/r-cmd-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ jobs:
- uses: actions/[email protected]
with:
name: ${{ matrix.config.os }}-${{ matrix.config.r }}-results
path: check/circumstance.Rcheck
path: check/${{ vars.repo_name }}.Rcheck
11 changes: 6 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
Package: circumstance
Type: Package
Title: pomp parallelized
Version: 0.0.3.0
Date: 2023-01-11
Version: 0.0.4.0
Date: 2023-01-24
Maintainer: Aaron A. King <[email protected]>
Description: Helper functions for parallelizing pomp computations.
Authors@R: c(person(given=c("Aaron","A."),family="King",
role=c("aut","cre"),email="[email protected]"))
URL: https://kingaa.github.io/circumstance/
Depends: R(>= 4.1.0), methods, foreach, pomp(>= 4.5)
Suggests: doParallel, doRNG, tidyr, ggplot2
Depends: R(>= 4.1.0), pomp(>= 4.6)
Imports: methods, foreach
Suggests: doFuture, doRNG, dplyr, tidyr, ggplot2
Remotes: kingaa/pomp
License: GPL-3
LazyData: true
Expand All @@ -19,5 +20,5 @@ Encoding: UTF-8
Roxygen: list(roclets = c("collate", "namespace", "rd"))
RoxygenNote: 7.2.3
Collate:
'circumstance-package.R'
'package.R'
'pfilter.R'
2 changes: 2 additions & 0 deletions R/circumstance-package.R → R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
##' \pkg{circumstance} provides tools for parallelizing certain \pkg{pomp} calculations.
##'
##' @name circumstance-package
##' @aliases circumstance,package
##' @docType package
##' @import methods
##' @importFrom utils globalVariables
##'
Expand Down
32 changes: 8 additions & 24 deletions R/pfilter.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
##' @rdname pfilter
##' @importFrom pomp pfilter
##' @importFrom foreach foreach %dopar%
##' @include circumstance-package.R
##' @include package.R
##'
##' @param data passed to \code{pomp::\link[pomp]{pfilter}}
##' @param data passed to \code{\link[pomp:pfilter]{pomp::pfilter}}
##' @param Nrep number of replicate particle filter computations to run.
##' By default, \code{Nrep = 1}.
##' @param ... all additional arguments are passed to \code{pomp::\link[pomp]{pfilter}}
##' @param ... all additional arguments are passed to \code{\link[pomp:pfilter]{pomp::pfilter}}
##'
##' @seealso \code{pomp::\link[pomp]{pfilter}}.
##' @seealso \code{\link[pomp:pfilter]{pomp::pfilter}}.
##'
##' @example examples/pfilter.R
##'
Expand All @@ -25,8 +25,6 @@ setGeneric(
standardGeneric("pfilter")
)

##' @aliases pfilter
##' @aliases pfilter-ANY,numeric
##' @rdname pfilter
##' @export
setMethod(
Expand All @@ -41,7 +39,6 @@ setMethod(
}
)

##' @aliases pfilter-ANY,missing
##' @rdname pfilter
##' @export
setMethod(
Expand All @@ -50,7 +47,6 @@ setMethod(
definition = pomp::pfilter
)

##' @aliases pfilter-pompList,numeric
##' @rdname pfilter
##' @export
setMethod(
Expand All @@ -64,31 +60,19 @@ setMethod(
rep <- (iter_i-1)%/%npo+1
pomp::pfilter(data[[ipo]],...)
} -> res
if (is.null(names(data))) {
names(res) <- sprintf("%d_%d",seq_len(npo),rep(seq_len(Nrep),each=npo))
} else {
names(res) <- sprintf("%s_%d",names(data),rep(seq_len(Nrep),each=npo))
}
nm <- names(data)
if (is.null(nm)) nm <- seq_len(npo)
names(res) <- sprintf("%s_%d",nm,rep(seq_len(Nrep),each=npo))
res
}
)

##' @aliases pfilter-pompList,missing
##' @rdname pfilter
##' @export
setMethod(
"pfilter",
signature=signature(data = "pompList", Nrep = "missing"),
definition = function (data, ...) {
jobs <- seq_len(length(data))
foreach (iter_i=jobs,.combine=c) %dopar% {
pomp::pfilter(data[[iter_i]],...)
} -> res
if (is.null(names(data))) {
names(res) <- jobs
} else {
names(res) <- names(data)
}
res
circumstance::pfilter(data,Nrep=1L,...)
}
)
11 changes: 10 additions & 1 deletion examples/pfilter.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
library(circumstance)
library(doFuture)
library(doRNG)
registerDoFuture()
registerDoRNG()

ou2() -> ou2
ou2 |> pfilter(Np=1000,Nrep=6) -> pfs

plan(sequential)
system.time(ou2 |> pfilter(Np=10000,Nrep=6) -> pfs)

plan(multicore)
system.time(ou2 |> pfilter(Np=10000,Nrep=6) -> pfs)
12 changes: 12 additions & 0 deletions inst/NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
_N_e_w_s _f_o_r _p_a_c_k_a_g_e '_c_i_r_c_u_m_s_t_a_n_c_e'

_C_h_a_n_g_e_s _i_n '_c_i_r_c_u_m_s_t_a_n_c_e' _v_e_r_s_i_o_n _0._0._4:

• Use with ‘doFuture’ is intended.

• Streamline some of the definitions.

• Improve coverage.

_C_h_a_n_g_e_s _i_n '_c_i_r_c_u_m_s_t_a_n_c_e' _v_e_r_s_i_o_n _0._0._3:

• Updates for new version of ‘pomp’.

_C_h_a_n_g_e_s _i_n '_c_i_r_c_u_m_s_t_a_n_c_e' _v_e_r_s_i_o_n _0._0._1:

• Improved the parallel ‘pfilter’ facility.
Expand Down
12 changes: 12 additions & 0 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
\name{NEWS}
\title{News for package `circumstance'}
\section{Changes in \pkg{circumstance} version 0.0.4}{
\itemize{
\item Use with \pkg{doFuture} is intended.
\item Streamline some of the definitions.
\item Improve coverage.
}
}
\section{Changes in \pkg{circumstance} version 0.0.3}{
\itemize{
\item Updates for new version of \pkg{pomp}.
}
}
\section{Changes in \pkg{circumstance} version 0.0.1}{
\itemize{
\item Improved the parallel \code{pfilter} facility.
Expand Down
4 changes: 3 additions & 1 deletion man/circumstance-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 13 additions & 8 deletions man/pfilter.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SOURCE = $(sort $(wildcard R/*R src/*.c src/*.h data/* examples/*))
CSOURCE = $(sort $(wildcard src/*.c))
TESTS = $(sort $(wildcard tests/*R))
INSTDOCS = $(sort $(wildcard inst/doc/*))
SESSION_PKGS = datasets,utils,grDevices,graphics,stats,methods,tidyverse,$(PKG)
SESSION_PKGS = datasets,utils,grDevices,graphics,stats,methods,tidyverse,doFuture,doRNG,$(PKG)

.PHONY: .check check clean covr debug default fresh \
htmlhelp manual publish qcheck qqcheck \
Expand All @@ -38,7 +38,7 @@ session: RSESSION = emacs -f R
debug: RSESSION = R -d gdb
rsession: RSESSION = R

default:
default: .roxy .NEWS .instdocs .source .includes .headers
@echo $(PKGVERS)

roxy: .roxy
Expand Down
Binary file modified tests/pfilter-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 38ea5f3

Please sign in to comment.