Skip to content

Commit e54d45a

Browse files
committed
onestep takes one step
1 parent d07a082 commit e54d45a

11 files changed

+112
-9
lines changed

DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: pomp
22
Type: Package
33
Title: Statistical Inference for Partially Observed Markov Processes
4-
Version: 5.9.0.0
5-
Date: 2024-06-02
4+
Version: 5.9.1.0
5+
Date: 2024-06-07
66
Authors@R: c(person(given=c("Aaron","A."),family="King",role=c("aut","cre"),email="kingaa@umich.edu",comment=c(ORCID="0000-0001-6159-3207")),
77
person(given=c("Edward","L."),family="Ionides",role="aut",comment=c(ORCID="0000-0002-4190-0174")) ,
88
person(given="Carles",family="Bretó",role="aut",comment=c(ORCID="0000-0003-4695-4902")),

R/rprocess_spec.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
##' They differ as to how this is done.
5353
##' Specifically,
5454
##' \enumerate{
55-
##' \item \code{onestep} takes a single step to go from any given time \code{t1} to any later time \code{t2} (\code{t1 < t2}).
55+
##' \item \code{onestep} takes a single step to go from any given time \code{t1} to any later time \code{t2} (\code{t1 <= t2}).
5656
##' Thus, this plug-in is designed for use in situations where a closed-form solution to the process exists.
5757
##' \item To go from \code{t1} to \code{t2}, \code{euler} takes \code{n} steps of equal size, where
5858
##' \preformatted{

inst/NEWS

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
_N_e_w_s _f_o_r _p_a_c_k_a_g_e '_p_o_m_p'
22

3+
_C_h_a_n_g_e_s _i_n '_p_o_m_p' _v_e_r_s_i_o_n _5._9._1:
4+
5+
• The rprocess plugin ‘onestep’ now always takes exactly one
6+
step to get from one observation time to the next, even when
7+
the interval between them is zero. That is, if ‘P’ is a
8+
‘pomp’ object with an rprocess built using
9+
‘rprocess=onestep(f)’, ‘t0=timezero(P)’, and ‘t=time(P)’,
10+
then ‘f’ will be called exactly once for the interval
11+
(‘t0’,‘t[1]’) and once for each of the intervals
12+
(‘t[i-1]’,‘t[i]’), ‘i=2,...,length(t)’.
13+
314
_C_h_a_n_g_e_s _i_n '_p_o_m_p' _v_e_r_s_i_o_n _5._8._4:
415

516
• To add additional elements for use by the basic model

inst/NEWS.Rd

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
\name{NEWS}
22
\title{News for package `pomp'}
3+
\section{Changes in \pkg{pomp} version 5.9.1}{
4+
\itemize{
5+
\item The rprocess plugin \code{onestep} now always takes exactly one step to get from one observation time to the next, even when the interval between them is zero.
6+
That is, if \code{P} is a \sQuote{pomp} object with an rprocess built using \code{rprocess=onestep(f)}, \code{t0=timezero(P)}, and \code{t=time(P)}, then \code{f} will be called exactly once for the interval (\code{t0},\code{t[1]}) and once for each of the intervals (\code{t[i-1]},\code{t[i]}), \code{i=2,...,length(t)}.
7+
}
8+
}
39
\section{Changes in \pkg{pomp} version 5.8.4}{
410
\itemize{
511
\item To add additional elements for use by the basic model components (i.e., \dQuote{userdata}), the \code{userdata} argument should now be used.

man/rprocess_spec.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/euler.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ SEXP euler_simulator
208208
switch (method) {
209209
case onestep: default: // one step
210210
dt = time[step]-t;
211-
nstep = (dt > 0) ? 1 : 0;
211+
nstep = 1;
212212
break;
213213
case discrete: // fixed step
214214
dt = deltat;

src/rprocess.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ SEXP do_rprocess (SEXP object, SEXP xstart, SEXP tstart, SEXP times, SEXP params
111111
double deltat = 1.0;
112112
PROTECT(fn = GET_SLOT(rproc,install("step.fn")));
113113
PROTECT(X = euler_simulator(fn,xstart,tstart,times,params,deltat,type,
114-
accumvars,covar,args,gnsi));
114+
accumvars,covar,args,gnsi));
115115
nprotect += 2;
116116
}
117117
break;
@@ -122,7 +122,7 @@ SEXP do_rprocess (SEXP object, SEXP xstart, SEXP tstart, SEXP times, SEXP params
122122
PROTECT(fn = GET_SLOT(rproc,install("step.fn")));
123123
deltat = *(REAL(AS_NUMERIC(GET_SLOT(rproc,install("delta.t")))));
124124
PROTECT(X = euler_simulator(fn,xstart,tstart,times,params,deltat,type,
125-
accumvars,covar,args,gnsi));
125+
accumvars,covar,args,gnsi));
126126
nprotect += 2;
127127
}
128128
break;

tests/steps-01.png

-29.4 KB
Binary file not shown.

tests/steps-02.png

-19.1 KB
Binary file not shown.

tests/steps.R

+44-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
options(digits=3)
22

3-
library(pomp)
43
suppressPackageStartupMessages({
4+
library(tidyr)
55
library(dplyr)
66
})
7+
library(pomp)
78

89
tm <- freeze(sort(runif(n=20,max=50)),seed=1930502785L)
910
simulate(
@@ -98,3 +99,45 @@ stopifnot(
9899
as.numeric(states(sm,"steps"))
99100
)
100101
)
102+
103+
simulate(
104+
t0=0,
105+
times=c(0,0,0,1,3,3,7),
106+
rinit=\(t0,...)c(x=t0,n=0),
107+
rprocess=onestep(\(t,x,n,delta.t,...) c(x=t+delta.t,n=n+1)),
108+
rmeasure=\(x,n,...) c(y1=x,y2=n),
109+
dmeasure=\(...,log) if (log) 0 else 1
110+
) -> s1
111+
112+
simulate(
113+
t0=0,
114+
times=c(0,0,0,1,3,3,7),
115+
rinit=Csnippet("x=t; n=0;"),
116+
rprocess=onestep(Csnippet("x=t+dt; n=n+1;")),
117+
rmeasure=Csnippet("y1 = x; y2 = n;"),
118+
dmeasure=Csnippet("lik = (give_log) ? 0 : 1;"),
119+
statenames=c("x","n"),
120+
obsnames=c("y1","y2")
121+
) -> s2
122+
123+
s1 |>
124+
as.data.frame() |>
125+
with(
126+
stopifnot(
127+
time==x,
128+
n==seq_along(time)
129+
)
130+
)
131+
132+
s2 |>
133+
pfilter(Np=1,save.states=TRUE) |>
134+
saved_states(format="list") |>
135+
melt() |>
136+
pivot_wider() |>
137+
mutate(time=time(s2)[.L1]) |>
138+
with(
139+
stopifnot(
140+
time==x,
141+
n==seq_along(time)
142+
)
143+
)

tests/steps.Rout.save

+44-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ Type 'q()' to quit R.
1919

2020
> options(digits=3)
2121
>
22-
> library(pomp)
2322
> suppressPackageStartupMessages({
23+
+ library(tidyr)
2424
+ library(dplyr)
2525
+ })
26+
> library(pomp)
2627
>
2728
> tm <- freeze(sort(runif(n=20,max=50)),seed=1930502785L)
2829
> simulate(
@@ -120,3 +121,45 @@ Warning message:
120121
+ )
121122
+ )
122123
>
124+
> simulate(
125+
+ t0=0,
126+
+ times=c(0,0,0,1,3,3,7),
127+
+ rinit=\(t0,...)c(x=t0,n=0),
128+
+ rprocess=onestep(\(t,x,n,delta.t,...) c(x=t+delta.t,n=n+1)),
129+
+ rmeasure=\(x,n,...) c(y1=x,y2=n),
130+
+ dmeasure=\(...,log) if (log) 0 else 1
131+
+ ) -> s1
132+
>
133+
> simulate(
134+
+ t0=0,
135+
+ times=c(0,0,0,1,3,3,7),
136+
+ rinit=Csnippet("x=t; n=0;"),
137+
+ rprocess=onestep(Csnippet("x=t+dt; n=n+1;")),
138+
+ rmeasure=Csnippet("y1 = x; y2 = n;"),
139+
+ dmeasure=Csnippet("lik = (give_log) ? 0 : 1;"),
140+
+ statenames=c("x","n"),
141+
+ obsnames=c("y1","y2")
142+
+ ) -> s2
143+
>
144+
> s1 |>
145+
+ as.data.frame() |>
146+
+ with(
147+
+ stopifnot(
148+
+ time==x,
149+
+ n==seq_along(time)
150+
+ )
151+
+ )
152+
>
153+
> s2 |>
154+
+ pfilter(Np=1,save.states=TRUE) |>
155+
+ saved_states(format="list") |>
156+
+ melt() |>
157+
+ pivot_wider() |>
158+
+ mutate(time=time(s2)[.L1]) |>
159+
+ with(
160+
+ stopifnot(
161+
+ time==x,
162+
+ n==seq_along(time)
163+
+ )
164+
+ )
165+
>

0 commit comments

Comments
 (0)