Skip to content

Commit e25844e

Browse files
committed
add eeulermultinom
1 parent 5af2a3d commit e25844e

File tree

103 files changed

+335
-116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+335
-116
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.11.0.3
5-
Date: 2024-11-08
4+
Version: 5.11.1.0
5+
Date: 2024-12-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")),

TODO.md

+1

inst/NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ _N_e_w_s _f_o_r _p_a_c_k_a_g_e '_p_o_m_p'
22

33
_C_h_a_n_g_e_s _i_n '_p_o_m_p' _v_e_r_s_i_o_n _5._1_1._1:
44

5+
• A new addition to the C API allows one to easily compute the
6+
expectation of the Euler-multinomial. The function is
7+
‘eeulermultinom’.
8+
59
• The help-page discussion of accumulator variables has been
610
expanded and clarified.
711

inst/NEWS.Rd

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
\title{News for package `pomp'}
33
\section{Changes in \pkg{pomp} version 5.11.1}{
44
\itemize{
5+
\item A new addition to the C API allows one to easily compute the expectation of the Euler-multinomial.
6+
The function is \code{eeulermultinom}.
57
\item The help-page discussion of accumulator variables has been expanded and clarified.
68
}
79
}

inst/include/pomp.h

+28
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,34 @@ double rgammawn
125125
return (sigmasq > 0) ? rgamma(dt/sigmasq,sigmasq) : dt;
126126
}
127127

128+
static R_INLINE
129+
void eeulermultinom
130+
(int m, double size, const double *rate, double dt, double *trans)
131+
{
132+
double lambda = 0.0;
133+
int j, k;
134+
if ( !R_FINITE(size) || size < 0.0 || !R_FINITE(dt) || dt < 0.0) {
135+
for (k = 0; k < m; k++) trans[k] = R_NaReal;
136+
warn("in 'eeulermultinom': NAs produced.");
137+
return;
138+
}
139+
for (k = 0; k < m; k++) {
140+
if (!R_FINITE(rate[k]) || rate[k] < 0.0) {
141+
for (j = 0; j < m; j++) trans[j] = R_NaReal;
142+
warn("in 'eeulermultinom': NAs produced.");
143+
return;
144+
}
145+
lambda += rate[k];
146+
}
147+
if (lambda > 0.0) {
148+
size = size*(1-exp(-lambda*dt));
149+
for (k = 0; k < m; k++)
150+
trans[k] = size*rate[k]/lambda;
151+
} else {
152+
for (k = 0; k < m; k++) trans[k] = 0.0;
153+
}
154+
}
155+
128156
static R_INLINE
129157
void reulermultinom
130158
(int m, double size, const double *rate, double dt, double *trans)

src/pomp.h

+28
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,34 @@ double rgammawn
133133
return (sigmasq > 0) ? rgamma(dt/sigmasq,sigmasq) : dt;
134134
}
135135

136+
static R_INLINE
137+
void eeulermultinom
138+
(int m, double size, const double *rate, double dt, double *trans)
139+
{
140+
double lambda = 0.0;
141+
int j, k;
142+
if ( !R_FINITE(size) || size < 0.0 || !R_FINITE(dt) || dt < 0.0) {
143+
for (k = 0; k < m; k++) trans[k] = R_NaReal;
144+
warn("in 'eeulermultinom': NAs produced.");
145+
return;
146+
}
147+
for (k = 0; k < m; k++) {
148+
if (!R_FINITE(rate[k]) || rate[k] < 0.0) {
149+
for (j = 0; j < m; j++) trans[j] = R_NaReal;
150+
warn("in 'eeulermultinom': NAs produced.");
151+
return;
152+
}
153+
lambda += rate[k];
154+
}
155+
if (lambda > 0.0) {
156+
size = size*(1-exp(-lambda*dt));
157+
for (k = 0; k < m; k++)
158+
trans[k] = size*rate[k]/lambda;
159+
} else {
160+
for (k = 0; k < m; k++) trans[k] = 0.0;
161+
}
162+
}
163+
136164
static R_INLINE
137165
void reulermultinom
138166
(int m, double size, const double *rate, double dt, double *trans)

tests/R_v_C.Rout

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

@@ -109,16 +109,16 @@ Type 'q()' to quit R.
109109
> ## ----comparison----------------------------------------------------------
110110
> system.time(simulate(gompertz,nsim=10000,format="arrays"))
111111
user system elapsed
112-
5.415 0.114 5.530
112+
5.480 0.064 5.544
113113
> system.time(simulate(Gompertz,nsim=10000,format="arrays"))
114114
user system elapsed
115-
0.155 0.004 0.160
115+
0.156 0.005 0.161
116116
> system.time(pfilter(gompertz,Np=1000))
117117
user system elapsed
118-
0.547 0.003 0.549
118+
0.554 0.000 0.554
119119
> system.time(pfilter(Gompertz,Np=1000))
120120
user system elapsed
121-
0.028 0.000 0.029
121+
0.027 0.001 0.028
122122
>
123123
> dev.off()
124124
null device

tests/abc.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/baddm.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/bake.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/basic_probes.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/betabinom.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/blowflies.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/bsmc2.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/bsplines1.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/bsplines2.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/concat.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/covmat.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/csnippet.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/dacca-02.png

-8 Bytes

tests/dacca.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/dinit.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/dp-01.png

-990 Bytes

tests/dp-02.png

-931 Bytes

tests/dp-03.png

185 Bytes

tests/dp-04.png

-187 Bytes

tests/dp-05.png

-250 Bytes

tests/dp-06.png

-228 Bytes

tests/dp.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/dprocess.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/ebola.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/emeasure.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/eulermultinom.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/flow.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/gillespie.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/gompertz.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/helpers.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/hitch.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/issue109.Rout.save

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
2+
R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

tests/issue222-01.png

50.4 KB

tests/issue222.R

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
library(pomp)
2+
3+
png(filename="issue222-%02d.png",res=100)
4+
5+
set.seed(974650257)
6+
7+
simulate(
8+
t0=-1/52,
9+
times=seq(0,10,by=1/52),
10+
params=c(
11+
gamma = 26, mu = 0.02, iota = 0.1,
12+
Beta = 400, Beta_sd = 0.01,
13+
rho = 0.6, k = 10,
14+
pop = 1e6,
15+
S_0 = 25/400, I_0 = 0.001, R_0 = 375/400
16+
),
17+
rprocess = euler(
18+
step.fun=Csnippet(r"{
19+
double dW = rgammawn(Beta_sd,dt);
20+
double rate[6];
21+
double trans[6];
22+
rate[0] = mu*pop;
23+
rate[1] = Beta*(I+iota)/pop*dW/dt;
24+
rate[2] = mu;
25+
rate[3] = gamma;
26+
rate[4] = mu;
27+
rate[5] = mu;
28+
trans[0] = rate[0]*dt;
29+
eeulermultinom(2,S,&rate[1],dt,&trans[1]);
30+
eeulermultinom(2,I,&rate[3],dt,&trans[3]);
31+
eeulermultinom(1,R,&rate[5],dt,&trans[5]);
32+
// balance equations
33+
S += trans[0] - trans[1] - trans[2];
34+
I += trans[1] - trans[3] - trans[4];
35+
R += trans[3] - trans[5];
36+
C += trans[3];
37+
W += (dW-dt)/Beta_sd;}"
38+
),
39+
delta.t=1/365
40+
),
41+
rmeasure = Csnippet(r"{
42+
reports = rnbinom_mu(k,rho*C);}"
43+
),
44+
rinit=initlz_pf <- Csnippet(r"{
45+
double m = pop/(S_0+I_0+R_0);
46+
S = m*S_0;
47+
I = m*I_0;
48+
R = m*R_0;
49+
C = 0;
50+
W = 0;}"
51+
),
52+
partrans=parameter_trans(
53+
logit=c("rho"),
54+
log=c("gamma","mu","k","Beta","Beta_sd","iota"),
55+
barycentric=c("S_0","I_0","R_0")
56+
),
57+
obsnames = "reports",
58+
accumvars = c("W","C"),
59+
statenames = c("S","I","R","C","W"),
60+
paramnames = c(
61+
"pop","rho","k","gamma","mu","Beta","Beta_sd","iota",
62+
"S_0","I_0","R_0"
63+
)
64+
) |>
65+
plot()
66+
67+
dev.off()

0 commit comments

Comments
 (0)