pomp
Inference for partially observed Markov processes
Toggle main menu visibility
Main Page
Data Structures
Data Structures
Data Structure Index
Data Fields
All
Variables
Files
File List
Globals
All
_
a
b
c
d
e
f
g
i
k
l
m
n
o
p
r
s
t
u
v
w
x
y
Functions
_
a
b
d
e
f
g
i
l
m
n
o
p
r
s
t
w
Variables
_
a
c
f
m
n
o
p
r
s
Typedefs
a
b
g
l
m
n
p
s
t
u
Enumerations
Enumerator
Macros
a
c
e
f
k
m
n
r
s
t
u
v
w
x
y
•
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
Loading...
Searching...
No Matches
lookup_table.c
Go to the documentation of this file.
1
#include <R.h>
2
#include <Rmath.h>
3
#include <Rdefines.h>
4
5
#include "
internal.h
"
6
7
SEXP
get_covariate_names
(SEXP
object
) {
8
return
GET_ROWNAMES(GET_DIMNAMES(GET_SLOT(
object
,install(
"table"
))));
9
}
7
SEXP
get_covariate_names
(SEXP
object
) {
…
}
10
11
lookup_table_t
make_covariate_table
(SEXP
object
,
int
*ncovar) {
12
lookup_table_t
tab;
13
int
*dim;
14
dim = INTEGER(GET_DIM(GET_SLOT(
object
,install(
"table"
))));
15
*ncovar = tab.
width
= dim[0];
16
tab.
length
= dim[1];
17
tab.
index
= 0;
18
tab.
x
= REAL(GET_SLOT(
object
,install(
"times"
)));
19
tab.
y
= REAL(GET_SLOT(
object
,install(
"table"
)));
20
tab.
order
= *(INTEGER(GET_SLOT(
object
,install(
"order"
))));
21
return
tab;
22
}
11
lookup_table_t
make_covariate_table
(SEXP
object
,
int
*ncovar) {
…
}
23
24
SEXP
lookup_in_table
(SEXP covar, SEXP t) {
25
int
xdim[2], nvar;
26
int
j, nt;
27
double
*tp, *xp;
28
SEXP Cnames,
X
;
29
30
PROTECT(t = AS_NUMERIC(t));
31
nt = LENGTH(t);
32
PROTECT(Cnames =
get_covariate_names
(covar));
33
34
lookup_table_t
tab =
make_covariate_table
(covar,&nvar);
35
36
if
(nt > 1) {
37
xdim[0] = nvar; xdim[1] = nt;
38
PROTECT(
X
=
makearray
(2,xdim));
39
setrownames
(
X
,Cnames,2);
40
}
else
{
41
PROTECT(
X
= NEW_NUMERIC(nvar));
42
SET_NAMES(
X
,Cnames);
43
}
44
45
for
(j = 0, tp = REAL(t), xp = REAL(
X
); j < nt; j++, tp++, xp += nvar)
46
table_lookup
(&tab,*tp,xp);
47
48
UNPROTECT(3);
49
return
X
;
50
}
24
SEXP
lookup_in_table
(SEXP covar, SEXP t) {
…
}
51
52
// linear interpolation on a lookup table
53
void
table_lookup
(
lookup_table_t
*tab,
double
x,
double
*y)
54
{
55
int
flag = 0;
56
int
j, k, n;
57
double
e;
58
if
((tab == 0) || (tab->
length
< 1) || (tab->
width
< 1))
return
;
59
tab->
index
= findInterval(tab->
x
,tab->
length
,x,1,1,tab->
index
,&flag);
60
// warn only if we are *outside* the interval
61
if
((x < tab->x[0]) || (x > tab->
x
[tab->
length
-1]))
62
warn
(
"in 'table_lookup': extrapolating at %le."
, x);
63
switch
(tab->
order
) {
64
case
1:
default
:
// linear interpolation
65
e = (x - tab->
x
[tab->
index
-1]) / (tab->
x
[tab->
index
] - tab->
x
[tab->
index
-1]);
66
for
(j = 0, k = tab->
index
*tab->
width
, n = k-tab->
width
; j < tab->
width
; j++, k++, n++) {
67
y[j] = e*(tab->
y
[k])+(1-e)*(tab->
y
[n]);
68
}
69
break
;
70
case
0:
// piecewise constant
71
if
(flag < 0) n = 0;
72
else
if
(flag > 0) n = tab->
index
;
73
else
n = tab->
index
-1;
74
for
(j = 0, k = n*tab->
width
; j < tab->
width
; j++, k++) {
75
y[j] = tab->
y
[k];
76
}
77
break
;
78
}
79
}
53
void
table_lookup
(
lookup_table_t
*tab,
double
x,
double
*y) {
…
}
X
#define X
Definition
gompertz.c:14
internal.h
table_lookup
void table_lookup(lookup_table_t *tab, double x, double *y)
Definition
lookup_table.c:53
make_covariate_table
lookup_table_t make_covariate_table(SEXP object, int *ncovar)
Definition
lookup_table.c:11
get_covariate_names
SEXP get_covariate_names(SEXP object)
Definition
lookup_table.c:7
lookup_in_table
SEXP lookup_in_table(SEXP covar, SEXP t)
Definition
lookup_table.c:24
warn
#define warn(...)
Definition
pomp.h:22
setrownames
static R_INLINE void setrownames(SEXP x, SEXP names, int rank)
Definition
pomp_defines.h:110
makearray
static R_INLINE SEXP makearray(int rank, const int *dim)
Definition
pomp_defines.h:40
lookup_table_t
Definition
pomp_defines.h:20
lookup_table_t::index
int index
Definition
pomp_defines.h:22
lookup_table_t::width
int width
Definition
pomp_defines.h:21
lookup_table_t::order
int order
Definition
pomp_defines.h:23
lookup_table_t::length
int length
Definition
pomp_defines.h:21
lookup_table_t::x
double * x
Definition
pomp_defines.h:24
lookup_table_t::y
double * y
Definition
pomp_defines.h:25
src
lookup_table.c
Generated by
1.9.8