Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyMC: Taking advantage of sparse model structure in Adaptive Metropolis MCMC

I have a model that is structured as in this diagram:

Model diagram

I have a population of several people (indexed 1...5 in this picture). Population parameters (A and B, but there can be more) determine the distributions for each individual's latent variable L[i]. The latent variable L[i] determines the observation X[i] in a probabilistic way. This model is "sparse" in the sense that most nodes do not have edges directly connecting them.

I am trying to use PyMC to infer the population parameters, as well as each individual's latent variable. (A related question, which describes my specific scenario in more detail, is here.) My question is: should I be using Adaptive Metropolis instead of another method, and if so, is there any "trick" to grouping the stochastic variables correctly?

If I understand Adaptive Metropolis sampling correctly (and I may not...), this algorithm proposes new values for the unknowns (A, B, and all the L[i]) by accounting for how these variables are correlated in the posterior distribution constructed in the run so far. If A and B are negatively correlated, then a proposal that increases A will tend to decrease B, and vice-versa, to increase the chance that the proposal is accepted.

The thing is, in this model, each L[i] is an independent draw from the underlying population distribution determined by A and B. So while they will be seen to correlate in the posterior, these correlations are really due to A and B alone, and so they are somehow "confounds." So when I call the function,

M.use_step_method(pymc.AdaptiveMetropolis, stochastics) 

should all the L[i] be together in the list of stochastics? Or should I call use_step_method multiple times, each time with stochastics=[A, B, L[i]] for just one of the L[i]? My thought was that calling the function multiple times for different groups of stochastics would structure the problem and make it easier for PyMC by telling it to focus on only the correlations that matter. Is this correct?

like image 424
Danny Avatar asked Apr 24 '15 20:04

Danny


1 Answers

This may be an unsatisfying answer, but it appears that PyMC3 has an example for a very similar hierarchical model: https://pymc-devs.github.io/pymc3/GLM-hierarchical/ Migrating your code to PyMC3 would give you access to newer samples, like the No-U-Turn Sampler (NUTS)

like image 65
sjc Avatar answered Sep 19 '22 08:09

sjc