Skip to content

Commit d739e0f

Browse files
committed
trap non-finite event-rate error
1 parent 5c66da6 commit d739e0f

File tree

4 files changed

+122
-7
lines changed

4 files changed

+122
-7
lines changed

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
Package: phylopomp
22
Type: Package
33
Title: Phylodynamic Inference for POMP Models
4-
Version: 0.14.9.4
5-
Date: 2025-09-21
4+
Version: 0.14.10.0
5+
Date: 2025-12-16
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("Qianying"),family="Lin",role=c("aut"),comment=c(ORCID="0000-0001-8620-9910"))
88
)
99
Description: Tools for phylodynamic analysis.
10-
biocViews:
1110
Depends: R(>= 4.5)
11+
Remotes: bioc::ggtree
1212
Imports: grid, ggtree(>= 3.16), yaml, ggplot2, scales, ape, dplyr, tibble, foreach, tidyr, pomp(>= 6.1), cowplot
1313
LinkingTo: pomp
1414
Suggests: tidyverse, doFuture, broom

src/popul_proc.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,26 @@ class popul_proc_t {
138138
void update_clocks (void) {
139139
double rate[nevent];
140140
double total_rate = event_rates(rate,nevent);
141-
if (total_rate > 0) {
142-
next = current+rexp(1/total_rate);
141+
if (R_FINITE(total_rate)) {
142+
if (total_rate > 0) {
143+
next = current+rexp(1/total_rate);
144+
} else {
145+
next = R_PosInf;
146+
}
143147
} else {
144-
next = R_PosInf;
148+
for (event = 0; event < nevent; event++) {
149+
if (!R_FINITE(rate[event]))
150+
Rprintf("in '%s' (%s line %d): invalid event rate[%zd]=%lg\n",
151+
__func__,__FILE__,__LINE__,event,rate[event]);
152+
}
153+
err("in '%s' (%s line %d): invalid total event rate=%lg",
154+
__func__,__FILE__,__LINE__,total_rate);
145155
}
146156
double u = runif(0,total_rate);
147157
event = 0;
148158
while (u > rate[event] && event < nevent) {
149159
if (rate[event] < 0)
150-
err("in '%s' (%s line %d): invalid negative rate[%zd]=%lg", // #nocov
160+
err("in '%s' (%s line %d): invalid rate[%zd]=%lg", // #nocov
151161
__func__,__FILE__,__LINE__,event,rate[event]); // #nocov
152162
u -= rate[event];
153163
event++;

tests/twospecies2.R

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
options(tidyverse.quiet=TRUE,digits=3)
2+
library(tidyverse)
3+
library(phylopomp)
4+
5+
try(
6+
simulate(
7+
"TwoSpecies",
8+
t0=0,time=3,
9+
iota1=0,iota2=0,
10+
Beta11=10,Beta12=0,
11+
Beta21=0,Beta22=0,
12+
gamma1=1,gamma2=1,
13+
c1=1,c2=1,
14+
psi1=1,psi2=1,
15+
S1_0=1000,I1_0=2,R1_0=0,
16+
S2_0=0,I2_0=0,R2_0=0,
17+
b1=0,b2=0,
18+
d1=0,d2=0,
19+
omega1=0.5,omega2=0.5
20+
)
21+
)
22+
23+
simulate(
24+
"TwoSpecies",
25+
t0=0,time=3,
26+
iota1=0,iota2=0,
27+
Beta11=10,Beta12=0,
28+
Beta21=0,Beta22=0,
29+
gamma1=1,gamma2=1,
30+
c1=1,c2=1,
31+
psi1=1,psi2=1,
32+
S1_0=1000,I1_0=2,R1_0=0,
33+
S2_0=1,I2_0=0,R2_0=0,
34+
b1=0,b2=0,
35+
d1=0,d2=0,
36+
omega1=0.5,omega2=0.5
37+
)

tests/twospecies2.Rout.save

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
R version 4.5.2 (2025-10-31) -- "[Not] Part in a Rumble"
3+
Copyright (C) 2025 The R Foundation for Statistical Computing
4+
Platform: x86_64-pc-linux-gnu
5+
6+
R is free software and comes with ABSOLUTELY NO WARRANTY.
7+
You are welcome to redistribute it under certain conditions.
8+
Type 'license()' or 'licence()' for distribution details.
9+
10+
Natural language support but running in an English locale
11+
12+
R is a collaborative project with many contributors.
13+
Type 'contributors()' for more information and
14+
'citation()' on how to cite R or R packages in publications.
15+
16+
Type 'demo()' for some demos, 'help()' for on-line help, or
17+
'help.start()' for an HTML browser interface to help.
18+
Type 'q()' to quit R.
19+
20+
> options(tidyverse.quiet=TRUE,digits=3)
21+
> library(tidyverse)
22+
> library(phylopomp)
23+
24+
Attaching package: 'phylopomp'
25+
26+
The following object is masked from 'package:stats':
27+
28+
simulate
29+
30+
>
31+
> try(
32+
+ simulate(
33+
+ "TwoSpecies",
34+
+ t0=0,time=3,
35+
+ iota1=0,iota2=0,
36+
+ Beta11=10,Beta12=0,
37+
+ Beta21=0,Beta22=0,
38+
+ gamma1=1,gamma2=1,
39+
+ c1=1,c2=1,
40+
+ psi1=1,psi2=1,
41+
+ S1_0=1000,I1_0=2,R1_0=0,
42+
+ S2_0=0,I2_0=0,R2_0=0,
43+
+ b1=0,b2=0,
44+
+ d1=0,d2=0,
45+
+ omega1=0.5,omega2=0.5
46+
+ )
47+
+ )
48+
in 'update_clocks' (popul_proc.h line 151): invalid event rate[1]=-nan
49+
in 'update_clocks' (popul_proc.h line 151): invalid event rate[2]=-nan
50+
Error : in 'update_clocks' (popul_proc.h line 154): invalid total event rate=-nan
51+
>
52+
> simulate(
53+
+ "TwoSpecies",
54+
+ t0=0,time=3,
55+
+ iota1=0,iota2=0,
56+
+ Beta11=10,Beta12=0,
57+
+ Beta21=0,Beta22=0,
58+
+ gamma1=1,gamma2=1,
59+
+ c1=1,c2=1,
60+
+ psi1=1,psi2=1,
61+
+ S1_0=1000,I1_0=2,R1_0=0,
62+
+ S2_0=1,I2_0=0,R2_0=0,
63+
+ b1=0,b2=0,
64+
+ d1=0,d2=0,
65+
+ omega1=0.5,omega2=0.5
66+
+ )
67+
<gpsim for TwoSpecies model>
68+
>

0 commit comments

Comments
 (0)