Exclude deterministics from plot

I’ve been using a deterministic to save the prediction of my model, i.e.

        p1 = pm.Normal("p1", mu=0., sd=1.)
        p2 = pm.Normal("p2", mu=0., sd=1.)

        mu = pm.Deterministic("mu_", p1+p2))

It appeared that https://github.com/pymc-devs/pymc3/pull/1215 introduced the convention to hide variables with trailing underscores, but that doesn’t work for me in the example above. The transformed variables are hidden, but the deterministic that I defined with a trailing underscore appears nonetheless.

You can use the varnames to do this manually, as in

def mytraceplot(trace):
  keep = [x for x in trace.varnames if x[-1] != '_']
  pm.traceplot(trace, keep)

with pm.Model() as mod:
    x = pm.Normal('x', 0., 1.)
    y = pm.Normal('y', 0., 1.)
    mu = pm.Deterministic('mu_', x + y)
    tr = pm.sample(500)


Thanks, I’ll use that!