How can I set the number of tuning samples for custom compound steps?
Running this toy example
import pymc as pm
from pymc.step_methods.arraystep import BlockedStep
from pymc.util import get_value_vars_from_user_vars
from scipy.stats import norm
class CustomStep(BlockedStep):
def __init__(self, vars, model = None):
model = pm.modelcontext(model)
self.vars = get_value_vars_from_user_vars(vars, model)
def step(self, point: dict):
new_point = point.copy()
new_point[self.vars[0].name] = norm.rvs()
stats = [{}]
return new_point, stats
with pm.Model():
x = pm.Flat("x")
custom_step = CustomStep([x])
y = pm.Normal("y")
trace = pm.sample(draws = 500, tune = 100, step = [custom_step])
prints
Multiprocess sampling (4 chains in 4 jobs)
CompoundStep
>CustomStep: [x]
>NUTS: [y]
|████████████| 100.00% [2400/2400 00:01<00:00 Sampling 4 chains, 0 divergences]
Sampling 4 chains for 0 tune and 600 draw iterations (0 + 2_400 draws total) took 15 seconds.
indicating that tune
is added to draws
to yield the correct total number of samples (600); but this number is wrongly split into 0 tuning samples and 600 subsequent draws (instead of 100 and 500, respectively).
This also leads to the wrong number of draws in the trace
object (e.g., trace.posterior.x.values.shape[1] == 600
).