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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions

inst/NEWS

Lines changed: 4 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 28 additions & 0 deletions
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

Lines changed: 28 additions & 0 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)