101 {
102
104 int give_log;
106 SEXP
Snames, Pnames, Cnames;
108 SEXP F, cvec;
110 int *dim;
111
112 dim = INTEGER(GET_DIM(
X));
nvars = dim[0]; nrepsx = dim[1];
113 dim = INTEGER(GET_DIM(
params));
npars = dim[0]; nrepsp = dim[1];
114
115 give_log = *(INTEGER(AS_INTEGER(log)));
116
117
118 if (nrepsx != nrepsp && nrepsx % nrepsp != 0 && nrepsp % nrepsx != 0) {
119 err(
"the larger number of replicates is not a multiple of smaller.");
120 } else {
121 nreps = (nrepsx > nrepsp) ? nrepsx : nrepsp;
122 }
123
124 PROTECT(
Snames = GET_ROWNAMES(GET_DIMNAMES(
X)));
125 PROTECT(Pnames = GET_ROWNAMES(GET_DIMNAMES(
params)));
128
129
131 PROTECT(cvec = NEW_NUMERIC(
ncovars));
133
134
136
137 int nprotect = 6;
138
140
142
143 double *t = REAL(t0);
144 double *ft = REAL(F);
145
147
148
150
151 for (
int j = 0; j <
nreps; j++, ft++) {
152
153 double *xs = REAL(
X)+
nvars*(j%nrepsx);
155
157
158 *ft = *REAL(AS_NUMERIC(ans));
159
160 UNPROTECT(1);
161
162 if (!give_log) *ft = exp(*ft);
163
164 }
165
166
167 }
168
169 break;
170
172
173 int *sidx, *pidx, *cidx;
174 double *t = REAL(t0);
175 double *ft = REAL(F);
177
178 sidx = INTEGER(GET_SLOT(func,install("stateindex")));
179 pidx = INTEGER(GET_SLOT(func,install("paramindex")));
180 cidx = INTEGER(GET_SLOT(func,install("covarindex")));
181
182 *((
void **) (&ff)) = R_ExternalPtrAddr(
fn);
183
184
186
187 for (
int j = 0; j <
nreps; j++, ft++) {
188
189 double *xs = REAL(
X)+
nvars*(j%nrepsx);
191
192 (*ff)(ft,xs,ps,*t,sidx,pidx,cidx,
cov);
193
194 if (!give_log) *ft = exp(*ft);
195
196 }
197
198 }
199
200 break;
201
202 default: {
203 double *ft = REAL(F);
204 int j;
205
206 for (j = 0; j <
nreps; j++, ft++) {
207 *ft = R_NaReal;
208 }
209
210 warn(
"'dinit' unspecified: likelihood undefined.");
211
212 }
213
214 }
215
216 UNPROTECT(nprotect);
217 return F;
218}
lookup_table_t make_covariate_table(SEXP, int *)
SEXP pomp_fun_handler(SEXP, SEXP, pompfunmode *, SEXP, SEXP, SEXP, SEXP)
void table_lookup(lookup_table_t *, double, double *)
SEXP get_covariate_names(SEXP)
static R_INLINE SEXP ret_array(int nreps)
static R_INLINE SEXP eval_call(SEXP fn, SEXP args, double *t0, double *x, int nvar, double *p, int npar, double *c, int ncov)
static R_INLINE SEXP add_args(SEXP args, SEXP Snames, SEXP Pnames, SEXP Cnames)
void pomp_dinit(double *lik, const double *x, const double *p, double t0, const int *stateindex, const int *parindex, const int *covindex, const double *covars)