Getting the mode of a posterior

After getting the trace of my parameters with NUTS (for instance), how can I compute the mode of each of my parameters?

Since the values inside the trace are just 2-dimensional numpy arrays, you should be able to use
scipy.stats.mode for this, similar to this:

I think the default of axis=0 should work, but you may have to adjust this.
So, something like this

from scipy import stats

stats.mode(trace["my_var"], axis=0)

For medians, you can just use numpy:

import numpy as np

np.median(trace["my_var"], axis=0)
1 Like

To complement Claus’ answer, there are also interesting functions in ArviZ – see az.summary and az.plot_posterior in particular

1 Like