willvousden / ptemcee

A parallel-tempered version of emcee.
MIT License
58 stars 29 forks source link

Adaptive temperature spacing not improving convergence of model evidence #15

Open ljschumacher opened 4 years ago

ljschumacher commented 4 years ago

I have been using you code for model selection, for which I have been calculating evidence using the built-in thermodynamic integration.

However I am finding that the adaptive temperature spacing does not improve the convergence of the model evidence estimates. I don't have a minimal working example, but here is the result from my actual use case: evidence_convergence_nsamples_nw40_adaptive.pdf Blue solid line is with adaptive=True, orange dashed line is adaptive=False. I've checked that the non-adaptive case has converged after 40k samples, but the adaptive case doesn't seem to. They both select the same model as best (shown above), but arrive at a different value for the evidence

Is there an example code I can run to test this adaptive sampling?

I'm also wondering about this comment in ptemcee/ensemble.py:

def step(self):
        self._stretch(self.x, self.logP, self.logl)
        self.x = self._temperature_swaps(self.x, self.logP, self.logl)
        ratios = self.swaps_accepted / self.swaps_proposed

        # TODO: Should the notion of a 'complete' iteration really include the temperature adjustment?
        if self.adaptive and self.ntemps > 1:
            dbetas = self._get_ladder_adjustment(self.time,
                                                 self.betas,
                                                 ratios)
            self.betas += dbetas
            self.logP += self._tempered_likelihood(self.logl, betas=dbetas)

        self.time += 1

Are you sure it is implemented correctly?