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

Go to the source code of this file.

Macros

#define ALPHA1   (p[parindex[0]])
 
#define ALPHA2   (p[parindex[1]])
 
#define ALPHA3   (p[parindex[2]])
 
#define ALPHA4   (p[parindex[3]])
 
#define SIGMA1   (p[parindex[4]])
 
#define SIGMA2   (p[parindex[5]])
 
#define SIGMA3   (p[parindex[6]])
 
#define TAU   (p[parindex[7]])
 
#define X1   (stateindex[0])
 
#define X2   (stateindex[1])
 
#define Y1   (y[obsindex[0]])
 
#define Y2   (y[obsindex[1]])
 
#define V11   (f[vmatindex[0]])
 
#define V21   (f[vmatindex[1]])
 
#define V12   (f[vmatindex[2]])
 
#define V22   (f[vmatindex[3]])
 

Functions

static void sim_ou2 (double *x1, double *x2, double alpha1, double alpha2, double alpha3, double alpha4, double sigma1, double sigma2, double sigma3)
 
static double dens_ou2 (double x1, double x2, double z1, double z2, double alpha1, double alpha2, double alpha3, double alpha4, double sigma1, double sigma2, double sigma3, int give_log)
 
void _ou2_step (double *x, const double *p, const int *stateindex, const int *parindex, const int *covindex, const double *covars, double t, double deltat)
 
void _ou2_pdf (double *f, double *x, double *z, double t1, double t2, const double *p, const int *stateindex, const int *parindex, const int *covindex, const double *covars)
 
void _ou2_skel (double *f, double *x, double *p, int *stateindex, int *parindex, int *covindex, double *covars, double t)
 
void _ou2_dmeasure (double *lik, double *y, double *x, double *p, int give_log, int *obsindex, int *stateindex, int *parindex, int *covindex, double *covar, double t)
 
void _ou2_rmeasure (double *y, double *x, double *p, int *obsindex, int *stateindex, int *parindex, int *covindex, double *covar, double t)
 
void _ou2_emeasure (double *y, double *x, double *p, int *obsindex, int *stateindex, int *parindex, int *covindex, double *covar, double t)
 
void _ou2_vmeasure (double *f, double *x, double *p, int *vmatindex, int *stateindex, int *parindex, int *covindex, double *covar, double t)
 

Macro Definition Documentation

◆ ALPHA1

#define ALPHA1   (p[parindex[0]])

Definition at line 50 of file ou2.c.

◆ ALPHA2

#define ALPHA2   (p[parindex[1]])

Definition at line 51 of file ou2.c.

◆ ALPHA3

#define ALPHA3   (p[parindex[2]])

Definition at line 52 of file ou2.c.

◆ ALPHA4

#define ALPHA4   (p[parindex[3]])

Definition at line 53 of file ou2.c.

◆ SIGMA1

#define SIGMA1   (p[parindex[4]])

Definition at line 54 of file ou2.c.

◆ SIGMA2

#define SIGMA2   (p[parindex[5]])

Definition at line 55 of file ou2.c.

◆ SIGMA3

#define SIGMA3   (p[parindex[6]])

Definition at line 56 of file ou2.c.

◆ TAU

#define TAU   (p[parindex[7]])

Definition at line 57 of file ou2.c.

◆ V11

#define V11   (f[vmatindex[0]])

Definition at line 65 of file ou2.c.

◆ V12

#define V12   (f[vmatindex[2]])

Definition at line 67 of file ou2.c.

◆ V21

#define V21   (f[vmatindex[1]])

Definition at line 66 of file ou2.c.

◆ V22

#define V22   (f[vmatindex[3]])

Definition at line 68 of file ou2.c.

◆ X1

#define X1   (stateindex[0])

Definition at line 59 of file ou2.c.

◆ X2

#define X2   (stateindex[1])

Definition at line 60 of file ou2.c.

◆ Y1

#define Y1   (y[obsindex[0]])

Definition at line 62 of file ou2.c.

◆ Y2

#define Y2   (y[obsindex[1]])

Definition at line 63 of file ou2.c.

Function Documentation

◆ _ou2_dmeasure()

void _ou2_dmeasure ( double *  lik,
double *  y,
double *  x,
double *  p,
int  give_log,
int *  obsindex,
int *  stateindex,
int *  parindex,
int *  covindex,
double *  covar,
double  t 
)

Definition at line 106 of file ou2.c.

111  {
112  double sd = fabs(TAU);
113  double f = 0.0;
114  f += (ISNA(Y1)) ? 0.0 : dnorm(Y1,x[X1],sd,1);
115  f += (ISNA(Y2)) ? 0.0 : dnorm(Y2,x[X2],sd,1);
116  *lik = (give_log) ? f : exp(f);
117 }
#define X1
Definition: ou2.c:59
#define Y1
Definition: ou2.c:62
#define Y2
Definition: ou2.c:63
#define TAU
Definition: ou2.c:57
#define X2
Definition: ou2.c:60

◆ _ou2_emeasure()

void _ou2_emeasure ( double *  y,
double *  x,
double *  p,
int *  obsindex,
int *  stateindex,
int *  parindex,
int *  covindex,
double *  covar,
double  t 
)

Definition at line 132 of file ou2.c.

137  {
138  Y1 = x[X1];
139  Y2 = x[X2];
140 }

◆ _ou2_pdf()

void _ou2_pdf ( double *  f,
double *  x,
double *  z,
double  t1,
double  t2,
const double *  p,
const int *  stateindex,
const int *  parindex,
const int *  covindex,
const double *  covars 
)

Definition at line 82 of file ou2.c.

88  {
89  if (t2-t1 != 1)
90  err("ou2_pdf error: transitions must be consecutive");
91  f[0] = dens_ou2(x[X1],x[X2],z[X1],z[X2],ALPHA1,ALPHA2,ALPHA3,ALPHA4,
92  SIGMA1,SIGMA2,SIGMA3,1);
93 }
#define SIGMA3
Definition: ou2.c:56
#define ALPHA2
Definition: ou2.c:51
static double dens_ou2(double x1, double x2, double z1, double z2, double alpha1, double alpha2, double alpha3, double alpha4, double sigma1, double sigma2, double sigma3, int give_log)
Definition: ou2.c:30
#define SIGMA1
Definition: ou2.c:54
#define SIGMA2
Definition: ou2.c:55
#define ALPHA3
Definition: ou2.c:52
#define ALPHA4
Definition: ou2.c:53
#define ALPHA1
Definition: ou2.c:50
#define err(...)
Definition: pomp.h:21
Here is the call graph for this function:

◆ _ou2_rmeasure()

void _ou2_rmeasure ( double *  y,
double *  x,
double *  p,
int *  obsindex,
int *  stateindex,
int *  parindex,
int *  covindex,
double *  covar,
double  t 
)

Definition at line 120 of file ou2.c.

125  {
126  double sd = fabs(TAU);
127  Y1 = rnorm(x[X1],sd);
128  Y2 = rnorm(x[X2],sd);
129 }

◆ _ou2_skel()

void _ou2_skel ( double *  f,
double *  x,
double *  p,
int *  stateindex,
int *  parindex,
int *  covindex,
double *  covars,
double  t 
)

Definition at line 95 of file ou2.c.

100  {
101  f[X1] = ALPHA1*x[X1]+ALPHA3*x[X2];
102  f[X2] = ALPHA2*x[X1]+ALPHA4*x[X2];
103 }

◆ _ou2_step()

void _ou2_step ( double *  x,
const double *  p,
const int *  stateindex,
const int *  parindex,
const int *  covindex,
const double *  covars,
double  t,
double  deltat 
)

Definition at line 71 of file ou2.c.

76  {
78 }
static void sim_ou2(double *x1, double *x2, double alpha1, double alpha2, double alpha3, double alpha4, double sigma1, double sigma2, double sigma3)
Definition: ou2.c:10
Here is the call graph for this function:

◆ _ou2_vmeasure()

void _ou2_vmeasure ( double *  f,
double *  x,
double *  p,
int *  vmatindex,
int *  stateindex,
int *  parindex,
int *  covindex,
double *  covar,
double  t 
)

Definition at line 143 of file ou2.c.

148  {
149  double sd = fabs(TAU);
150  V11 = V22 = sd*sd;
151  V12 = V21 = 0;
152 }
#define V12
Definition: ou2.c:67
#define V21
Definition: ou2.c:66
#define V22
Definition: ou2.c:68
#define V11
Definition: ou2.c:65

◆ dens_ou2()

static double dens_ou2 ( double  x1,
double  x2,
double  z1,
double  z2,
double  alpha1,
double  alpha2,
double  alpha3,
double  alpha4,
double  sigma1,
double  sigma2,
double  sigma3,
int  give_log 
)
static

Definition at line 29 of file ou2.c.

34  {
35  double eps[2], val;
36 
37  // compute residuals
38  eps[0] = z1-alpha1*x1-alpha3*x2;
39  eps[1] = z2-alpha2*x1-alpha4*x2;
40 
41  // backsolve
42  eps[0] /= sigma1;
43  eps[1] -= sigma2*eps[0];
44  eps[1] /= sigma3;
45 
46  val = dnorm(eps[0],0.0,1.0,1)+dnorm(eps[1],0.0,1.0,1)-log(sigma1)-log(sigma3);
47  return ((give_log) ? val : exp(val));
48 }
Here is the caller graph for this function:

◆ sim_ou2()

static void sim_ou2 ( double *  x1,
double *  x2,
double  alpha1,
double  alpha2,
double  alpha3,
double  alpha4,
double  sigma1,
double  sigma2,
double  sigma3 
)
static

Definition at line 9 of file ou2.c.

14  {
15  double eps[2], xnew[2];
16 
17  eps[0] = rnorm(0,1);
18  eps[1] = rnorm(0,1);
19 
20  xnew[0] = alpha1*(*x1)+alpha3*(*x2)+sigma1*eps[0];
21  xnew[1] = alpha2*(*x1)+alpha4*(*x2)+sigma2*eps[0]+sigma3*eps[1];
22 
23  *x1 = xnew[0];
24  *x2 = xnew[1];
25 }
Here is the caller graph for this function: