phylopomp
Phylodynamics for POMPs
Loading...
Searching...
No Matches
subsample.cc
Go to the documentation of this file.
1#include "genealogy.h"
2#include "generics.h"
3#include "internal.h"
4
5#include <R.h>
6#include <Rdefines.h>
7
10(double frac)
11{
12 prune();
13 for (node_t *p : *this) {
14 for (auto it = p->begin(); it != p->end(); ) {
15 if ((*it)->is(blue) && unif_rand() > frac) {
16 ball_t *b = *it;
17 it = p->erase(it);
18 delete b;
19 } else {
20 ++it;
21 }
22 }
23 }
24 comb();
25 return *this;
26}
27
28extern "C" {
29
31 SEXP subsample (SEXP State, SEXP Frac) {
32 SEXP S;
33 genealogy_t A = State;
34 PROTECT(S = serial(A.subsample(*REAL(Frac))));
35 SET_ATTR(S,install("class"),mkString("gpgen"));
36 UNPROTECT(1);
37 return S;
38 }
39
40}
@ blue
Definition ball.h:12
Balls function as pointers.
Definition ball.h:27
Encodes a genealogy.
Definition genealogy.h:20
genealogy_t & prune(void)
prune the tree (drop all black balls)
Definition genealogy.h:311
genealogy_t & subsample(double frac)
Definition subsample.cc:10
Encodes a genealogical node.
Definition node.h:23
void comb(void)
Definition nodeseq.h:223
SEXP serial(const TYPE &X)
binary serialization
Definition generics.h:33
#define S
Definition seirs_pomp.c:38
SEXP subsample(SEXP State, SEXP Frac)
extract the bare genealogy
Definition subsample.cc:31