Hello
I’m running the following model:
import numpy as np
import pymc as pm
import pytensor.tensor as tt
# simulate some data
np.random.seed(42)
n = 10_000 # number of individuals
group_size = n // 2
t = 12 # number of time intervals
# event probabilites for group 1 and 2
p1 = 0.01
p2 = 0.05
def simulate_group(n, p):
return np.random.choice((0, 1), size=(n, t), p=(1 - p, p))
# observed data
observed = np.vstack((simulate_group(group_size, p1), simulate_group(group_size, p2)))
# group indicators
group = np.hstack((np.zeros(group_size), np.ones(group_size)))
with pm.Model(coords=dict(intervals=range(t))):
lam0 = pm.Gamma(
"lam0",
mu=pm.Gamma("lam0_mu", mu=0.5, sigma=0.5),
sigma=pm.Gamma("lam0_sigma", mu=0.5, sigma=0.1),
dims="intervals",
)
beta = pm.Normal("beta", mu=0, sigma=1)
lam = tt.outer(tt.exp(beta * group), lam0)
pm.Poisson("obs", lam, observed=observed)
pm.sample()
Which generates the following error:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [lam0_mu, lam0_sigma, lam0, beta]
Traceback (most recent call last):-----------------------------------| 0.00% [0/8000 00:00<? Sampling 4 chains, 0 divergences]
File "<path>/test.py", line 38, in <module>
pm.sample()
File "<path>/lib/python3.10/site-packages/pymc/sampling/mcmc.py", line 666, in sample
_mp_sample(**sample_args, **parallel_args)
File "<path>/lib/python3.10/site-packages/pymc/sampling/mcmc.py", line 1055, in _mp_sample
for draw in sampler:
File "<path>/lib/python3.10/site-packages/pymc/sampling/parallel.py", line 448, in __iter__
draw = ProcessAdapter.recv_draw(self._active)
File "<path>/lib/python3.10/site-packages/pymc/sampling/parallel.py", line 320, in recv_draw
msg = ready[0].recv()
File "<path>/.pyenv/versions/3.10.4/lib/python3.10/multiprocessing/connection.py", line 255, in recv
buf = self._recv_bytes()
File "<path>/.pyenv/versions/3.10.4/lib/python3.10/multiprocessing/connection.py", line 419, in _recv_bytes
buf = self._recv(4)
File "<path>/.pyenv/versions/3.10.4/lib/python3.10/multiprocessing/connection.py", line 388, in _recv
raise EOFError
EOFError
Setting n
to something lower (e.g. 1000) resolves the error, and the model samples as expected.
Is there a way to run this with larger n
?
Thanks
David