pomp
Inference for partially observed Markov processes
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mif2.c File Reference
#include "internal.h"
#include <Rdefines.h>
Include dependency graph for mif2.c:

Go to the source code of this file.

Functions

SEXP randwalk_perturbation (SEXP params, SEXP rw_sd)
 

Function Documentation

◆ randwalk_perturbation()

SEXP randwalk_perturbation ( SEXP  params,
SEXP  rw_sd 
)

Definition at line 6 of file mif2.c.

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 }
static R_INLINE SEXP matchnames(SEXP provided, SEXP needed, const char *where)
Definition: pomp_defines.h:60
int npars
Definition: trajectory.c:132
SEXP params
Definition: trajectory.c:128
int nreps
Definition: trajectory.c:134
SEXP pindex
Definition: trajectory.c:145
Here is the call graph for this function:
Here is the caller graph for this function: