Skip to content

Commit

Permalink
add unit tests for iubf updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ionides committed Aug 19, 2024
1 parent bc34025 commit bb41d65
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
14 changes: 14 additions & 0 deletions tests/bm.R
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,20 @@ try(iubf(b_model,Nubf=2,Nrep_per_param=1,rw.sd=b_rw.sd,cooling.fraction.50=1000,
## max_lookback is not triggered for b_model with N=2
iubf(b_model5,Nubf=2, Nparam = 3,Nrep_per_param=3,nbhd=b_bag_nbhd,rw.sd=b_rw.sd,cooling.fraction.50=0.5,prop=0.8)

set.seed(98)

## trigger special case when Nrep_per_param=1
b_iubf_npp1 <- iubf(b_model,Nubf=2, Nparam = 3,Nrep_per_param=1,nbhd=b_bag_nbhd,rw.sd=b_rw.sd,cooling.fraction.50=0.5,prop=0.8)
paste("bm iubf loglik with Nrep_per_param = 1 : ",round(logLik(b_iubf_npp1),10))

## trigger special cases when length(def_resample)==0
b_iubf_np1 <- iubf(b_model,Nubf=2, Nparam = 3, Nrep_per_param=1,nbhd=b_bag_nbhd,rw.sd=b_rw.sd,cooling.fraction.50=0.5,prop=0)
paste("bm iubf loglik with length(def_resample)==0: ",round(logLik(b_iubf_np1),10))

## trigger special cases when length(def_resample)==Nparam*prop=1
b_iubf_dr1 <- iubf(b_model,Nubf=2, Nparam = 3,Nrep_per_param=1,nbhd=b_bag_nbhd,rw.sd=b_rw.sd,cooling.fraction.50=0.5,prop=0.25)
paste("bm iubf loglik with length(def_resample)==Nparam*prop=1 : ",round(logLik(b_iubf_dr1),10))

## trigger situations where neighborhood is not contemporaneous
iubf(b_model5,Nubf=2, Nparam = 3,Nrep_per_param=3,nbhd=b_bag_nbhd_lookback1,rw.sd=b_rw.sd,cooling.fraction.50=0.5,prop=0.8)
iubf(b_model5,Nubf=2, Nparam = 3,Nrep_per_param=3,nbhd=b_bag_nbhd_lookback2,rw.sd=b_rw.sd,cooling.fraction.50=0.5,prop=0.8)
Expand Down
19 changes: 18 additions & 1 deletion tests/bm.Rout.save
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

R version 4.4.0 (2024-04-24) -- "Puppy Cup"
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin20

Expand Down Expand Up @@ -746,6 +746,23 @@ Error : in ‘iubf’: ‘cooling.fraction.50’ must be in (0,1]
> iubf(b_model5,Nubf=2, Nparam = 3,Nrep_per_param=3,nbhd=b_bag_nbhd,rw.sd=b_rw.sd,cooling.fraction.50=0.5,prop=0.8)
<object of class ‘iubfd_spatPomp’>
>
> set.seed(98)
>
> ## trigger special case when Nrep_per_param=1
> b_iubf_npp1 <- iubf(b_model,Nubf=2, Nparam = 3,Nrep_per_param=1,nbhd=b_bag_nbhd,rw.sd=b_rw.sd,cooling.fraction.50=0.5,prop=0.8)
> paste("bm iubf loglik with Nrep_per_param = 1 : ",round(logLik(b_iubf_npp1),10))
[1] "bm iubf loglik with Nrep_per_param = 1 : -25.8317474406"
>
> ## trigger special cases when length(def_resample)==0
> b_iubf_np1 <- iubf(b_model,Nubf=2, Nparam = 3, Nrep_per_param=1,nbhd=b_bag_nbhd,rw.sd=b_rw.sd,cooling.fraction.50=0.5,prop=0)
> paste("bm iubf loglik with length(def_resample)==0: ",round(logLik(b_iubf_np1),10))
[1] "bm iubf loglik with length(def_resample)==0: -16.4452178406"
>
> ## trigger special cases when length(def_resample)==Nparam*prop=1
> b_iubf_dr1 <- iubf(b_model,Nubf=2, Nparam = 3,Nrep_per_param=1,nbhd=b_bag_nbhd,rw.sd=b_rw.sd,cooling.fraction.50=0.5,prop=0.25)
> paste("bm iubf loglik with length(def_resample)==Nparam*prop=1 : ",round(logLik(b_iubf_dr1),10))
[1] "bm iubf loglik with length(def_resample)==Nparam*prop=1 : -12.1300071488"
>
> ## trigger situations where neighborhood is not contemporaneous
> iubf(b_model5,Nubf=2, Nparam = 3,Nrep_per_param=3,nbhd=b_bag_nbhd_lookback1,rw.sd=b_rw.sd,cooling.fraction.50=0.5,prop=0.8)
<object of class ‘iubfd_spatPomp’>
Expand Down

0 comments on commit bb41d65

Please sign in to comment.