Skip to content

Commit

Permalink
improve 'repair_lookup_table'
Browse files Browse the repository at this point in the history
  • Loading branch information
kingaa committed May 14, 2024
1 parent 2c90a49 commit 5ca52ea
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: pomp
Type: Package
Title: Statistical Inference for Partially Observed Markov Processes
Version: 5.8.2.0
Date: 2024-05-13
Version: 5.8.2.1
Date: 2024-05-14
Authors@R: c(person(given=c("Aaron","A."),family="King",role=c("aut","cre"),email="[email protected]",comment=c(ORCID="0000-0001-6159-3207")),
person(given=c("Edward","L."),family="Ionides",role="aut",comment=c(ORCID="0000-0002-4190-0174")) ,
person(given="Carles",family="Bretó",role="aut",comment=c(ORCID="0000-0003-4695-4902")),
Expand Down
8 changes: 5 additions & 3 deletions R/lookup.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
##' A numeric vector or matrix of the interpolated values.
##' @inheritSection covariates Extrapolation
##' @export

lookup <- function (table, t) {
d <- .Call(P_lookup_in_table,table,t)
data.frame(t=t,t(d))
Expand All @@ -26,12 +25,15 @@ lookup <- function (table, t) {
##' times at which interpolated values of the covariates in \code{table} are required.
##' @details
##' \code{repair_lookup_table} applies \code{\link{lookup}} at the provided values of \code{t} and returns the resulting lookup table.
##' If \code{order} is unsupplied, the interpolation-order from \code{table} is preserved.
##' \strong{\code{repair_lookup_table} should be considered experimental: its interface may change without notice}.
##' @export
repair_lookup_table <- function (table, t) {
repair_lookup_table <- function (table, t, order) {
if (missing(order))
order <- if (table@order==0L) "constant" else "linear"
covariate_table(
lookup(table,t=t),
order=if (table@order==0L) "constant" else "linear",
order=order,
times="t"
)
}
3 changes: 2 additions & 1 deletion man/covariate_table.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/lookup.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,17 @@ lookup(tab,c(0,2.5,3.6,10,20))
repair_lookup_table(tab,t=c(seq(0,10,by=1),20)) -> tab2
lookup(tab2,c(0,2.5,3.6,10,20))

covariate_table(
x=seq(1,10,by=1),
y=seq(1,10,by=1),
order="const",
times="x"
) -> tab

repair_lookup_table(tab,t=c(seq(0,10,by=1),20),order="lin") -> tab2
lookup(tab2,c(0,2.5,3.6,10,20))

repair_lookup_table(tab,t=c(seq(0,10,by=1),20),order="const") -> tab2
lookup(tab2,c(0,2.5,3.6,10,20))

dev.off()
31 changes: 31 additions & 0 deletions tests/lookup.Rout.save
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,37 @@ Warning messages:
4 10.0 10
5 20.0 10
>
> covariate_table(
+ x=seq(1,10,by=1),
+ y=seq(1,10,by=1),
+ order="const",
+ times="x"
+ ) -> tab
>
> repair_lookup_table(tab,t=c(seq(0,10,by=1),20),order="lin") -> tab2
Warning messages:
1: in 'table_lookup': extrapolating at 0.000000e+00.
2: in 'table_lookup': extrapolating at 2.000000e+01.
> lookup(tab2,c(0,2.5,3.6,10,20))
t y
1 0.0 1.0
2 2.5 2.5
3 3.6 3.6
4 10.0 10.0
5 20.0 10.0
>
> repair_lookup_table(tab,t=c(seq(0,10,by=1),20),order="const") -> tab2
Warning messages:
1: in 'table_lookup': extrapolating at 0.000000e+00.
2: in 'table_lookup': extrapolating at 2.000000e+01.
> lookup(tab2,c(0,2.5,3.6,10,20))
t y
1 0.0 1
2 2.5 2
3 3.6 3
4 10.0 10
5 20.0 10
>
> dev.off()
null device
1
Expand Down

0 comments on commit 5ca52ea

Please sign in to comment.