choderalab / assaytools

Modeling and Bayesian analysis of fluorescence and absorbance assays.
http://assaytools.readthedocs.org
GNU Lesser General Public License v2.1
18 stars 11 forks source link

[WIP] Adding emcee to pymc sampler #79

Closed sonyahanson closed 7 years ago

sonyahanson commented 7 years ago

Added a function in pymcmodels.py for now. Added an ipynb where I'm trying to test this. There is currently an error at the end that I think is due to the dimension of the samples being somewhat complicated.

I am following this link, which is for a considerably simpler model: http://twiecki.github.io/blog/2013/09/23/emcee-pymc/

Additionally, I realize I am not using the same sampling scheme as in the original run_mcmc function, which has all of the samplers for each parameter defined separately (I believe) with:

    mcmc.use_step_method(pymc.Metropolis, getattr(pymc_model, 'DeltaG'), proposal_sd=1.0, proposal_distribution='Normal')
    mcmc.use_step_method(pymc.Metropolis, getattr(pymc_model, 'F_PL'), proposal_sd=10.0, proposal_distribution='Normal')
    mcmc.use_step_method(pymc.Metropolis, getattr(pymc_model, 'F_P'), proposal_sd=10.0, proposal_distribution='Normal')
    mcmc.use_step_method(pymc.Metropolis, getattr(pymc_model, 'F_L'), proposal_sd=10.0, proposal_distribution='Normal')
    mcmc.use_step_method(pymc.Metropolis, getattr(pymc_model, 'F_plate'), proposal_sd=10.0, proposal_distribution='Normal')
    mcmc.use_step_method(pymc.Metropolis, getattr(pymc_model, 'F_buffer'), proposal_sd=10.0, proposal_distribution='Normal')

Any suggestions welcome!

jchodera commented 7 years ago

Similar to this?

https://github.com/choderalab/assaytools/blob/master/examples/autoprotocol/single-wavelength-competition-assay-emcee.py#L34-L84

sonyahanson commented 7 years ago

Ahh, very similar, indeed, but I'd like to use this to improve our current Bayesian methods. My understanding (and experience) is this autoprotocol branch is not currently working. The structure of the model itself is somewhat different, but maybe this will be useful to look at.

jchodera commented 7 years ago

Yes, just hoped it could be a useful template!

Haven't had a chance to return to the autoprotocol branch to debug yet.

gregoryross commented 7 years ago

@sonyahanson I've re-written the function to sample the pymc model with emcee. As several of the pymc parameters were vectors and not single values, this required a little extra packing and re-packing. To accompany the new tool, I've written a notebook that compares sampling with emcee and pymc. Please let me know if you're happy for me to merge.

sonyahanson commented 7 years ago

Looks good to me!