nchopin/particles

Bayesian inference with multidimensional prior

Closed this issue · 1 comments

When running the PMMH algorithm with verbose non-zero and a prior for a non-scalar parameter, there's a bug in the print_progress method in the MCMC class:

    def print_progress(self, n):
        params = self.chain.theta.dtype.fields.keys()
        msg = 'Iteration %i' % n
        if hasattr(self, 'nacc') and n > 0:
            msg += ', acc. rate=%.3f' % (self.nacc / n)
        for p in params:
            msg += ', %s=%.3f' % (p, self.chain.theta[p][n])
        print(msg)

In the case of a prior for a non-scalar parameter, self.chain.theta[p][n] is an array and one has to use another kind of string formatting.

NB: It's not much of a problem. If verbose=0 or one can factor the multidimensional parameter into scalar parameters, everything works fine.

OK, I replaced %.3f by %s, which should work whether self.chaintheta[p][n] is a scalar or or an array. (We loose the formatting, but I guess that's ok.)
Thx.