I have this line of code that I use as part of computing (approximating) the entropy of a posterior distribution:
trace_logps: np.ArrayLike[np.longdouble] = \
np.fromiter((self.logp_point(i) for i in self.trace),
np.longdouble)
This line of code works fine when I have just created a trace.
However, if I save a trace to the text
backend, and then use pm.backends.text.load()
to reload it, the above bit of code no longer works.
AFAICT, if I have a “fresh” MultiTrace
, then I can iterate over it, and the iteration passes over all the points of all the chains. But if I get “reloaded” MultiTrace
, this iterator does not work, an din stead I get
In [55] np.fromiter((model.logp_point(i) for i in trace), np.longdouble)
Out [55] array([], dtype=float128)
so it seems like somehow the original MultiTrace
is iterable and the reloaded one is not. Is this a bug? Should I replace this to always use for i in trace.points()
?
P.S. OK, using for i in trace.points()
also seems wrong, because I get this:
(Pdb) p len(list(trace.points()))
4824
but trace
has 20 chains, each of 10000 samples. So something is badly wrong here.