pomp
Inference for partially observed Markov processes
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mif2.c
Go to the documentation of this file.
1// -*- C++ -*-
2
3#include "internal.h"
4#include <Rdefines.h>
5
6SEXP randwalk_perturbation (SEXP params, SEXP rw_sd)
7{
8 double *xp = 0, *rw, *xrw, *xs;
9 SEXP Pnames, rwnames, pindex;
10 int *dim, *pidx;
11 int nrw = 0, npars, nreps;
12 int j, k;
13
14 PROTECT(params = duplicate(params));
15
16 // unpack parameter matrix
17 xp = REAL(params);
18 dim = INTEGER(GET_DIM(params)); npars = dim[0]; nreps = dim[1];
19 PROTECT(Pnames = GET_ROWNAMES(GET_DIMNAMES(params)));
20
21 // names of parameters undergoing random walk
22 PROTECT(rwnames = GET_NAMES(rw_sd));
23 nrw = LENGTH(rwnames); rw = REAL(rw_sd);
24
25 // indices of parameters undergoing random walk
26 PROTECT(pindex = matchnames(Pnames,rwnames,"parameters"));
27 pidx = INTEGER(pindex);
28
29 GetRNGstate();
30
31 for (j = 0, xrw = rw; j < nrw; j++, pidx++, xrw++) {
32 for (k = 0, xs = xp+(*pidx); k < nreps; k++, xs += npars) {
33 *xs += *xrw * norm_rand();
34 }
35 }
36
37 PutRNGstate();
38
39 UNPROTECT(4);
40 return(params);
41}
SEXP randwalk_perturbation(SEXP params, SEXP rw_sd)
Definition mif2.c:6
static R_INLINE SEXP matchnames(SEXP provided, SEXP needed, const char *where)
int npars
Definition trajectory.c:132
SEXP params
Definition trajectory.c:128
int nreps
Definition trajectory.c:134
SEXP pindex
Definition trajectory.c:145