Noob: Algebra on chains?

I have looked through the docs but have not seem what I am looking for, so apologies up front if this is simply me missing something.

My model will run and converge without issues. Due to my specific application, I want to perform algebraic ops on the chains themselves, both in terms of viewing via arviz and more importantly for my workflow. I cannot seem to figure out how to do this though, short of accessing the data in the undrlying xarray objects which seems like too much brute force.

For example, I would like to do something like:

with pm.Model():
    # stuff
    idata = pm.sample(5_000)

# assume `idata` has variables `a` and `b` so that this will
# display the trace for `a` and `b` as expected
az.plot_trace(idata)

# I want to look at the trace for, say `exp(a + b)`
???

Thank you very much in advance!

np.exp(idata.posterior["a"] + idata.posterior["b”])

2 Likes

Well that was embarrassingly easy, thank you!

1 Like

This page might also help provide similar tricks and further context: Working with InferenceData — ArviZ 0.19.0 documentation