Closed
Description
Looking to track the logp similar to NUTS in SMC sampler
Hi guys, I'm looking for some guidance on how to track the log-probability (logp) of the trace when using an SMC sampler. I was referred by @eigenfoo who contributed on the post here and the forks (here and here). When I deal with NUTS, I've found that declaring a deterministic variable as pm.Deterministic('logp', model.logpt) works best to track the log-probability of the trace but whenever I try to include it in an SMC based sampler I see a traceback like the Minimal example.
I know the syntax changed in 3.7 from something like
with model:
trace = pm.sample(step=pm.SMC())
to the below in 3.8
with model:
trace = pm.sample_smc(...)
So I tried both versions but neither seem to work.
Minimal example.
model = pm.Model()
with model:
# Priors
mu = pm.Normal('mu', mu=0, sigma=1)
logp_ = pm.Deterministic('logp', model.logpt)
obs = pm.Normal('obs', mu=mu, sigma=1, observed=np.random.randn(100))
with model:
trace = pm.sample(step=pm.SMC(...))
Traceback
Sample initial stage: ...
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-140-6e7754df4da0> in <module>
1 pm.sample(draws=5000,chains=10000,step=pm.SMC(),cores=1,model=HMCmodel, tune_steps=True,
----> 2 progressbar=False)
~/opt/anaconda3/envs/pymc3_37/lib/python3.7/site-packages/pymc3/sampling.py in sample(draws, step, init, n_init, start, trace, chain_idx, chains, cores, tune, progressbar, model, random_seed, discard_tuned_samples, compute_convergence_checks, **kwargs)
338 progressbar=progressbar,
339 model=model,
--> 340 random_seed=random_seed)
341 else:
342 if 'njobs' in kwargs:
~/opt/anaconda3/envs/pymc3_37/lib/python3.7/site-packages/pymc3/step_methods/smc.py in sample_smc(draws, step, cores, progressbar, model, random_seed)
153
154 pm._log.info("Sample initial stage: ...")
--> 155 posterior, var_info = _initial_population(draws, model, variables)
156
157 while beta < 1:
~/opt/anaconda3/envs/pymc3_37/lib/python3.7/site-packages/pymc3/step_methods/smc_utils.py in _initial_population(draws, model, variables)
17 var_info = {}
18 start = model.test_point
---> 19 init_rnd = pm.sample_prior_predictive(draws, model=model)
20 for v in variables:
21 var_info[v.name] = (start[v.name].shape, start[v.name].size)
~/opt/anaconda3/envs/pymc3_37/lib/python3.7/site-packages/pymc3/sampling.py in sample_prior_predictive(samples, model, vars, var_names, random_seed)
1320 names = get_default_varnames(model.named_vars, include_transformed=False)
1321 # draw_values fails with auto-transformed variables. transform them later!
-> 1322 values = draw_values([model[name] for name in names], size=samples)
1323
1324 data = {k: v for k, v in zip(names, values)}
~/opt/anaconda3/envs/pymc3_37/lib/python3.7/site-packages/pymc3/distributions/distribution.py in draw_values(params, point, size)
411 while to_eval or missing_inputs:
412 if to_eval == missing_inputs:
--> 413 raise ValueError('Cannot resolve inputs for {}'.format([str(params[j]) for j in to_eval]))
414 to_eval = set(missing_inputs)
415 missing_inputs = set()
ValueError: Cannot resolve inputs for ['logp']
Any thoughts would be greatly appreciated:)
Versions and main components
- PyMC3 Version: 3.7/3.8
- Theano Version: 1.0.4
- Python Version: Python 3.7.7
- Operating system: macOS Catalina
- How did you install PyMC3: pip
Metadata
Metadata
Assignees
Labels
No labels