JuliaStats / Klara.jl

MCMC inference in Julia
Other
167 stars 38 forks source link

Truncated normal RWM and Metropolis-within-Gibbs? #11

Closed sdwfrost closed 8 years ago

sdwfrost commented 11 years ago

@scidom and @fredo-dedup - Great job so far on MCMC.jl. I had already tweaked RWM.jl to accept a vector of scale parameters, but it looks as though you're already on top of this. A few requests (that I am happy to help with):

  1. Using a truncated normal distribution rather than a normal in RWM.jl (with the appropriate Hastings ratio adjustment)
  2. An integer random walk sampler (sampled from +/- 1:K), again with the choice of bounds.
  3. Some means of collecting individual samplers together to perform Metropolis-within-Gibbs (or componentwise Metropolis, etc.), either with a fixed or random order.
papamarkou commented 11 years ago

Feel free to contribute @sdwfrost, these are useful extensions to RWM. A couple of comments:

  1. It may be the case that we want to add several proposals other than the Normal or truncated Normal. Maybe we could approach this in a systematic way by adding Proposal and RWMProposal as abstract types, then define specific types for each proposal distribution. Alternatively we would use only a wrapper function called proposal() to point to the user-chosen proposal mechanism. If the RWM definition changes drastically, we can define it then as a separate type RWMx(), which is sth that @fredo-dedup has already started doing on the basis of the employed RWM tuning methods.
  2. The integer random walk sampler would probably be a separate RWM type for example.
  3. Adding Gibbs sampling capabilities is certainly a great addition, though it will take quite a lot of work so feel free to contribute. BUGS/WinBUGS is the reference point when it comes to simulation using Gibbs algorithms, so we may want to draw some ideas from there.
fredo-dedup commented 11 years ago

Thanks for your participation @sdwfrost !

  1. Another solution that would change less existing types : extend the scale parameter to accept not only scalars but also distributions, i.e. a vector [ Normal(0,1) , Cauchy(0,1), ...]
  2. Following that idea, a DiscreteDistribution would signal to the sampler that RWM should use an integer random walk. But that may not be such a good idea, that information is best associated with the model definition, not the sampler's
  3. Another sampler field describing a partition of the parameter vector ? Using the PMap type ?
papamarkou commented 11 years ago
  1. It is true that by allowing scale to accept distributions the code may be more compact, yet at the same time it won't be conceptually clear. In general, the distribution is naturally part of the proposal mechanism, not so directly implicated to scaling, so it may be more transparent not to fuse these two different aspects of the MCMC samplers...
  2. I agree that integer/continuous variable definition is part of the model definition, not the sampler's.
  3. That's probably a good idea, not clear in my mind yet.
fredo-dedup commented 11 years ago

(3). has some conceptual similarity with sequential MC : run in succession different samplers on the same model; but with only a subset of parameters active on each sampler. It may be a good idea to follow that idea (generalize seq MC).

papamarkou commented 11 years ago

Yes, that makes more sense, and it is probably in your coding realm, since you have done the seqMC coding :)

sdwfrost commented 11 years ago

@scidom - for Metropolis-within-Gibbs, I was really thinking more of attaching different samplers to different parameters of a model, then having a sampler that would go through each component of the model and update them separately.

How about 'IRWM' for an integer random walk sampler as a separate type?

For truncation, it would be nice to have a macro to truncate a distribution from Distributions.jl, in a similar way to what gen.trun does in the R library gamlss.tr; then, having a mechanism to specify the proposal distribution would be the same regardless of whether the distribution was truncated or not, whether a random walk sampler or an independence sampler, etc. was used.

papamarkou commented 11 years ago

@sdwfrost, assuming different samplers for different parameters is sth that we haven't considered before and it is important to update the package to include such functionality; please feel free to contribute any time as it would be great help. @fredo-dedup, what is your opinion on this?

IRWM sounds good to me.

Yes, I agree with your suggestion about having a macro for truncating distributions - I think this should become part of the Distributions package, and then we can invoke it from MCMC. Would you like to file an issue in Distributions about truncation and see what the rest of people think about it?

johnmyleswhite commented 11 years ago

There was a truncate macro in Distributions, which we replaced with a Truncated type.

-- John

On Aug 27, 2013, at 9:27 AM, Theodore Papamarkou notifications@github.com wrote:

@sdwfrost, assuming different samplers for different parameters is sth that we haven't considered before and it is important to update the package to include such functionality; please feel free to contribute any time as it would be great help. @fredo-dedup, what is your opinion on this?

IRWM sounds good to me.

Yes, I agree with your suggestion about having a macro for truncating distributions - I think this should become part of the Distributions package, and then we can invoke it from MCMC. Would you like to file an issue in Distributions about truncation and see what the rest of people think about it?

— Reply to this email directly or view it on GitHub.

johnmyleswhite commented 11 years ago

Regarding different samplers for each parameter, this is what WinBUGS and JAGS both do. The BUGS book has a nice description of how this is handled: sampler algorithms go through nodes in the graphical model looking for subgraphs to which they apply.

-- John

On Aug 27, 2013, at 9:27 AM, Theodore Papamarkou notifications@github.com wrote:

@sdwfrost, assuming different samplers for different parameters is sth that we haven't considered before and it is important to update the package to include such functionality; please feel free to contribute any time as it would be great help. @fredo-dedup, what is your opinion on this?

IRWM sounds good to me.

Yes, I agree with your suggestion about having a macro for truncating distributions - I think this should become part of the Distributions package, and then we can invoke it from MCMC. Would you like to file an issue in Distributions about truncation and see what the rest of people think about it?

— Reply to this email directly or view it on GitHub.

papamarkou commented 11 years ago

That's a very useful reference, didn't know about this book (it came out last year as it seems). If MCMC is going to allow different samplers for each parameter, I think we should do it the BUGS way (ie using graphical models). By the way, is there any Julia code for graphical models?

johnmyleswhite commented 11 years ago

I agree. I think we'll want to have a proper graphical model representation. I spent some time at Hacker School on this, but it needs a lot more work.

I'll write something up later this week so that others can see if anything I've done would be useful.

-- John

On Aug 27, 2013, at 10:05 AM, Theodore Papamarkou notifications@github.com wrote:

That's a very useful reference, didn't know about this book (it came out last year as it seems). If MCMC is going to allow different samplers for each parameter, I think we should do it the BUGS way (ie using graphical models). By the way, is there any Julia code for graphical models?

— Reply to this email directly or view it on GitHub.

papamarkou commented 11 years ago

Great, keep us posted about the graphical model coding.

gragusa commented 10 years ago

Is there somebody working on extending RWM along the lines mentioned in the subject line of this issue? I am very interested to work on it. Especially the block-wise RWM. @johnmyleswhite I know of your package dealing with graphical models. Can you point me to the BUGS book where it is explained how they deal with component-wise RWM?

johnmyleswhite commented 10 years ago

Chapter 12 of this book is a good start: http://www.amazon.com/The-BUGS-Book-Introduction-Statistical/dp/1584888490

fredo-dedup commented 10 years ago

You're most welcome to work on this @gragusa and we will happily integrate your contributions !

Do you have already a plan ? Are you thinking of an automated choice of sampler depending on the kind of parameters (like BUGS) or user supplied information ?

gragusa commented 10 years ago

@fredo-dedup thank you. I think I should have some free time in the next couple of week and i will start working on it. I am leaning toward user supplied information since the problem I am thinking are non-standard enough that any automatic choice will result (generally) in poor results. But I have to carefully think this through though. We will see.

papamarkou commented 8 years ago

The new graph-based model is now ready to accommodate Gibbs and Metropolis-within-Gibbs relatively easily. I will only need to set up a Gibbs-related job over the next few weeks (which has been logged already as an issue). As for the truncated normal, we haven't added this functionality yet. I will close this issue and will split it into sub-issues to track it better.