How to try multiple circuits in PyMC3

I am trying to try multiple circuits in PyMC3. In PyMC2, I would do something like this:

for i in range(N): model.sample(iter=iter, burn=burn, thin = thin) 

How do I do the same in PyMC3? I have seen that the njobs argument is in the sample method, but it throws an error when I set the value for it. I want to use custom chains to get the output "pymc.gelman_rubin".

+6
source share
2 answers

To run them sequentially, you can use a similar approach to your PyMC 2 example. The main difference is that each sample call returns a multipurpose trace instance (containing only one chain in this case). merge_traces will take a list of multipurpose instances and create a single instance with all the chains.

 #!/usr/bin/env python3 import pymc as pm import numpy as np from pymc.backends.base import merge_traces xobs = 4 + np.random.randn(20) model = pm.Model() with model: mu = pm.Normal('mu', mu=0, sd=20) x = pm.Normal('x', mu=mu, sd=1., observed=xobs) step = pm.NUTS() with model: trace = merge_traces([pm.sample(1000, step, chain=i) for i in range(2)]) 
+4
source

It is better to use njobs for parallel operation of chains:

 #!/usr/bin/env python3 import pymc3 as pm import numpy as np from pymc3.backends.base import merge_traces xobs = 4 + np.random.randn(20) model = pm.Model() with model: mu = pm.Normal('mu', mu=0, sd=20) x = pm.Normal('x', mu=mu, sd=1., observed=xobs) step = pm.NUTS() with model: trace = pm.sample(1000, step, njobs=2) 
+9
source

Source: https://habr.com/ru/post/979512/


All Articles