Access sampler stats and saving burn-in

I want to save all my samples (including burn-in) as csv file, but also be able to access statistics from trace.stat_names.

Saving it like
db = pm.backends.Text(‘MyTrace’)
trace = pm.sample(10000, [updI], start={‘I’:0.5}, trace=db)

the trace.stat_names command returns an empty set.

To get around this, I convert trace into a dataframe :
df = pm.backends.tracetab.trace_to_dataframe(trace)
df.to_csv(“MyTest.csv”)

However, this will let me loose the samples for the burn-in.
Is there are way of achieving both, getting stat_names and burn in?

Text backend is not very well maintained, so if you want to do I think the most robust way is:

pm.sample(1000, tune=1000, discard_tuned_samples=False)
1 Like