brian-j-smith / Mamba.jl

Markov chain Monte Carlo (MCMC) for Bayesian analysis in julia
Other
253 stars 52 forks source link

How to give samplers access to an object that cannot be deep-copied? #129

Open maximerischard opened 6 years ago

maximerischard commented 6 years ago

I'm implementing a coupled MCMC algorithm, wherein two chains run in parallel but need to communicate with each other. I'm trying to build this on top of Mamba, and have implemented an object that takes care of the communication between the two chains (it provides input and output channels for each chain).

What is the best way to provide access to the communication channels to the samplers?

I've tried putting them inside of the SampleTune objects, but the many calls to deepcopy are thwarting me. The communication channels are deep-copied, so that the two chains no longer share the same channels and can't communicate. It also seems like that's not what SampleTune objects are intended for.

What's a better way to do this? I'd be happy to provide more details if this is too abstract.

bdeonovic commented 6 years ago

Without knowing more about the object I'll make some silly suggestions like would it work to put your object in the data dict or the init dict?

maximerischard commented 6 years ago

Thank you for that suggestion. Each chain needs its own separate channel, so init would make more sense than the data dict. But ultimately, the channels need to be available in the sample! function, which as far as I can tell means they'll have to find their way into a SampleTune object of some sort. I've got this working for a stand-alone sampler now, but still trying to get it to work for a Model specification.