pm.MCMC in pymc3 or in an other library?

I am currently using the pymc library with python 3.6 to use the very useful function pm.MCMC.
I have not found its equivalent in pymc3, does the library exist in pymc3?

Many thanks in advance

You’re probably looking for pm.sample(). Note that things work quite differently in pymc3, but all sampling is done by calls to this and related these methods (described at that link).

1 Like

Thank you Christian,

I am currently looking for transfering a pymc2 code to pymc3 or another library compatible with python 3.8
In pymc2, I have :
U_pymc_model = pm.stochastic(logp=U_law_Logp, random=U_law_rand,
doc=‘Vit’, name=‘Vit’, parents={}, trace=True)

sampler = pm.MCMC([U_pymc_model, Hs_pymc_model, Tp_pymc_model, WdDr_pymc_model, WvDr_pymc_model,sigU_pymc_model, metamodel_response, refinement_criterion])

And I don’t know how to make them compatible with python 3.8
Many thanks in advance

Someone who is more well-versed in pymc2 should weigh in (@twiecki maybe? @junpenglao ?), but the pymc3 snippet below might get you in the vicinity. I will also mention that a “straight” pymc3 port of your pymc2 code may not be the most efficient/natural way to go. But if you have loads of pymc2 code, it might make sense.

Note that pymc3 will automatically a select a sampler based on your model, so you aren’t required to specify this before calling pm.sample() (though you can if you wish).

with pm.Model() as my_model:
    Vit = pm.DensityDist(
    trace = pm.sample()

Hi everybody,
Thank you Christian for your answer. I But have an issue with the solution you suggested.
1- I have also trouble installing pymc3. Which version should I install easely and without dependancy with python 3.8 ?
2- I would like to rewrite these lines :
U_pymc_model = pm.stochastic(logp=U_law_Logp, random=U_law_rand, doc=‘Vit’, name=‘Vit’, parents={}, trace=True)
sampler = pm.MCMC([U_pymc_model, metamodel_response, refinement_criterion])
in a python version 3.8, is it possible ? And if yes, how can I do it ?
Many thanks in advance

Installation instructions can be found on the main documentation page. Dependencies can be found here.

Regarding a rewrite, I suspect that a pymc3 version will not simply replace those 2 old lines of code with 2 new lines of code. As I said, pymc3 does not work in the same way that pymc2 does and so a line-by-line translation may not be possible.

1 Like

Hi Nicolas,

I think you should abandon PyMC2 completely and embrace PyMC3. Besides using up-to-date samplers, the code base of PyMC3 is just so much better. It’s a joy to work with compared to PyMC2.

Unfortunately though, this does mean throwing out your old code.

Thanks you Sammosummo, but it is not simple for me to to transform a pm.stochastic object into a pymc3 object. Is it possible to habve some help?
Many thanks in avance

Could you post a complete minimal example of your PyMC2 code, with a subset of or simulated data?

1 Like

Hi, thank you very much for your reply. Below a minimal example of a code that I want to convert into pymc3.
Many thanks in advance
Nicolas (2.5 KB)

Hi again, I can add a more simplified example if necessary. Just let me know.