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

Go to the source code of this file.

Functions

SEXP systematic_resampling (SEXP weights, SEXP np)
 
void nosort_resamp (int nw, double *w, int np, int *p, int offset)
 

Function Documentation

◆ nosort_resamp()

void nosort_resamp ( int  nw,
double *  w,
int  np,
int *  p,
int  offset 
)

Definition at line 25 of file resample.c.

26{
27 int i, j;
28 double du, u;
29
30 for (j = 1; j < nw; j++) w[j] += w[j-1];
31
32 if (w[nw-1] <= 0.0)
33 err("in 'systematic_resampling': non-positive sum of weights");
34
35 du = w[nw-1] / ((double) np);
36 u = -du*unif_rand();
37
38 for (i = 0, j = 0; j < np; j++) {
39 u += du;
40 // In the following line, the second test is needed to correct
41 // the infamous Bug of St. Patrick, 2017-03-17.
42 while ((u > w[i]) && (i < nw-1)) i++;
43 p[j] = i;
44 }
45 if (offset) // add offset if needed
46 for (j = 0; j < np; j++) p[j] += offset;
47
48}
#define err(...)
Definition pomp.h:21
Here is the caller graph for this function:

◆ systematic_resampling()

SEXP systematic_resampling ( SEXP  weights,
SEXP  np 
)

Definition at line 9 of file resample.c.

10{
11 int m, n;
12 SEXP perm;
13
14 m = *(INTEGER(AS_INTEGER(np)));
15 n = LENGTH(weights);
16 PROTECT(perm = NEW_INTEGER(m));
17 PROTECT(weights = AS_NUMERIC(weights));
18 GetRNGstate();
19 nosort_resamp(n,REAL(weights),m,INTEGER(perm),1);
20 PutRNGstate();
21 UNPROTECT(2);
22 return(perm);
23}
void nosort_resamp(int nw, double *w, int np, int *p, int offset)
Definition resample.c:25
Here is the call graph for this function:
Here is the caller graph for this function: