ZhouHUB / pyIID

Monte Carlo Based Diffraction Simulation
Other
1 stars 0 forks source link

ENH: Parallel Tempering #67

Open CJ-Wright opened 8 years ago

CJ-Wright commented 8 years ago

Parallel Tempering may be a useful way to achieve faster mixing and convergence. Thus we should support it as a meta ensemble.

Potential API:

class ParallelTempering(Ensemble):
    def __init__(atoms, ensemble, Ts): # Or maybe momentum?
        super
        self.ensembles = [ensemble(atoms.copy(), temperature=T) for atoms, T in Ts]
    def step():
        if self.rs.rand() > .5:
            for i in range(len(self.ensembles)-1):
                e0 = self.ensembles[i]
                e1 = self.ensembles[i+1]
                a0 = e0.traj[-1]
                a1 = e1.traj[-1]
                T0 = e0.temperature
                T1 = e1.temperature
                p = min(1, exp(1/k * (a0.get_potential_energy() - a1.get_potential_energy())(1/T0- 1/T1)))
                if p > rs.rand():
                     e1.temperature = T0
                     e0.temperature = T1
        else:
              for e in self.ensembles:
                   e.step()