15.8.3 - MCMC: A worked example - Data set


gmas
01-17-2015, 10:05 AM
I have just bought the NR3 code in the hope that I could have retrieved the routine to create a test data set for "15.8.3 MCMC: A worked example", but it is not there.

I believe that, given the title of the book section, a function to create the data should also be provided.. Did I miss it?
If not, could the authors kindly post it?

I have also attempted to code it by myself, but without luck. :(

gmas
02-03-2015, 11:18 AM
I understand that this is just a forum.. but the authors should be more present.

Saul Teukolsky
02-04-2015, 01:10 PM
The information to create the data is given on p. 833 of the text. It is simple to code this up using the information provided:

#include "nr3.h"
#include "ran.h"
#include "gamma.h"
#include "deviates.h"
#include "mcmc.h"

...

Int k1=1,k2=2,N=1000;
Doub lambda1=3.0,lambda2=2.0,tc=200.0,accept;

Gammadev gdev1(k1,lambda1,17); //17 is a randomly chosen seed
Gammadev gdev2(k2,lambda2,17);
Doub t=0.0;
for (Int i=0;i<N;i++) {
if (t < tc) {
t += gdev1.dev();
} else {
t += gdev2.dev();
}
times[i]=t;
}

This goes where "Fill the vector times here" appears on p.833