Hi again. Thanks for your help. I have a follow up question about the MCMC method. Suppose I have a hierarchical model with the following form:
-Parameter alpha is sampled from a prior P(alpha);
-An initial hidden state g_0 is sampled from a distribution
g_0 ~ gDist(g|alpha)
-An initial observable state s_0 is sampled from a distribution
s_0~sDist(s|g_0)
For each subsequent step, a hidden state g_t is sampled from gDist(g_t|g_(t-1), s_(t-1), alpha) (i.e. g_t depends on g_(t-1), s_(t-1), and alpha),
then an observable state s_t is sample from sDist(s_t|s_(t-1), g_t) (i.e. s_t depends on s_(t-1) and g_t);
This continues until a terminal state is reached, resulting in the trial data s_0, s_1,....s_T (since the g-states are hidden);
Now, I want to write a program that will infer the value of parameter alpha, given data from multiple trials T_0, ..., T_N, where each T_i is a sequence of observable states.
My program has the following form:
var inferAlpha=function(trials){
return Infer({method: 'MCMC', samples: 1000}, function(){
var alpha=sample(alphaPrior);
//recursively iterate through a trial and add factors
var observe_trial=function(s_states, g_states, trial){
if (s_states.length==trial.length){return true}
else{
//load current state values
var current_s=s_states[s_states.length-1];
var current_g=g_states[g_states.length-1];
//sample next hidden value
var next_g=sample(gDist(current_g, current_s, alpha));
//compute distribution over state values for next observable state
var stateDist=sDist(next_g, current_s);
//add factor for next observable state
var next_s=trial[s_states.length];
factor(stateDist.score(next_s));
return observe_trial(s_states.concat(next_s), g_states.concat(next_g), trial)
}
var addFactors=map(function(x){return observe_trial([x[0]], [sample(gDist(alpha))], x)}, trials);
return alpha
})
}
The inner loop iterates through a single trial, fills in the hidden states by sampling from the appropriate gDist distribution, and adds the likelihood of observing the given observable state, given the sampled hidden state.
The addFactors command maps the inner loop to each trial in the data.
So here's my question: from the previous discussion, my understanding is that each step of MCMC will choose a single sample statement to resample, in order to generate the next proposal. But in this case, most of the sample statements aren't actually included in the return value. The first sample statement generates a sample of the parameter alpha, but the remaining sample statements are just involved in filling in the hidden states. So, in this program, will each step of MCMC resample all of the hidden states AND the parameter, or will it just choose one of the sample statements (either the one associated with alpha, or one of the hidden states) and resample that one?
Thanks again
-Isaac