Save determinstic variables, don't save original variables

I want to use Deterministic transformations of variables, and then only save these new variables when sampling. For example:

offset = 5
with pm.Model():
    v = pm.Gamma('v', alpha=1.5, beta=2.5)  # don't want to save samples
    v_dash = pm.Deterministic("v_dash", v + offset)  # only want to save these samples
    trace = pm.sample(500)
trace.remove_values("v")  # sub-optimal solution: remove the non-transformed samples after everything

This clearly takes up twice as much space as necessary while sampling. Not a problem in this example, but in general for bigger models it will be a problem.

Is there a way to only save the v_dash and not v samples?

1 Like