Avoiding naming intermediate RVs?

I have a random variable over the interval (-\infty, 0]. I’m using an improper HalfFlat prior and multiplying by -1 to get the variable I want. Is there a way to avoid having _var_name in my model output, since I really only want var_name?

var_name = pm.Deterministic('var_name', -pm.HalfFlat('_var_name'))

I suppose I could write a custom random variable, or maybe use pm.Potential, but I’m hoping for a lighter-weight option. :slight_smile:

I don’t think there’s a way to do this (though I might be wrong!). I think your best bet is to filter out the variables you don’t need after sampling has done. Once you have an ArviZ InferenceData object, you could filter those variables out of the trace with xarray.Dataset.drop_vars.


Hi @ajfriend,
To complete what @tushar_chandra wrote, note that I think dropping vars could make it impossible to compute statistical diagnostics later on, which is a problem if you want to compare models for instance.
So, unless memory space is an issue, I’d advise keeping everything in the trace :vulcan_salute:

1 Like

Figured it out! The variable name just needs to end in two underscores:

beta1 = pm.Deterministic('var_name', -pm.HalfFlat('neg_var_name__'))

Then, when running az.plot_posterior(idata) it’ll skip plotting the distribution for neg_var_name__.

1 Like