kaskr / adcomp

AD computation with Template Model Builder (TMB)
Other
176 stars 80 forks source link

Importance sampler for mixture models? #24

Open James-Thorson opened 10 years ago

James-Thorson commented 10 years ago

I'm hoping to implement a state-space model that includes Markov-switches between "regimes", which represent different parameter values for the function representing the expected value of changes over time.

This model will almost certainly result in a probability for random effects (states) that is bimodal (conditional on fixed effects), and hence cannot be estimated using the Laplace Approximation. Is the importance sampler working for "small" random effect models? If so, is there an example that would show recommended settings (i.e., how many importance values to use)?

jim

skaug commented 10 years ago

I think the importance sampling is built on top of the Laplace approximation, so it will also fail in the bimodal case.

Maybe you can some HMM type trick to get around bimodality.

Hans

James-Thorson commented 10 years ago

Thanks for the quick response Hans!

I tried implementing the state-space Markov-switching model, on the hypothesis that measurement and process error would "smear" across the two modes for the conditional probability of state-parameters. Comparing with a Bayesian implementation, it appears to work okay with this data set (i.e., process errors are large relative to variance explained by Markov switching).

However, I'd still love to use the Importance Sampler. The problem is that summation in the mixture must be done on probabilities (not log-probabilities), and this causes numerical under/overflow for the Importance Sampler:

  1. Is there any tip or code for summing probabilities (while staying in log-space to prevent numerical problems), perhaps using a joiner function?
  2. Is there a min/max function implemented in TMB for derivative types? The likelihood could remain differentiable despite using min/max functions (given that you would always add back in the log-min/max after doing this summation across state-probabilities), but I don't know how this would affect the derivative "graph".
  3. Is there any way to modify the Importance Sampler function MC() to discard underflow errors? I've experimented a bit with MC() but remain unsure.

cheers, Jim