In statistical physics, Glauber dynamics is a way to simulate the Ising model (a model of magnetism) on a computer. It is a type of Markov Chain Monte Carlo algorithm. In the Ising model, we have say N particles that can spin up (+1) or down (-1). Say the particles are on a 2D grid. We label each with an x and y coordinate. Glauber's algorithm becomes: Choose a particle at random. Sum its four neighboring spins. . Compute the change in energy if the spin x, y were to flip. This is (see the Hamiltonian for the Ising model). Flip the spin with probability where T is the temperature . Display the new grid. Repeat the above N times. In Glauber algorithm, if the energy change in flipping a spin is zero, , then the spin would flip with probability . Metropolis–Hastings algorithm gives identical results as Glauber algorithm does, but it is faster. In the Metropolis algorithm, selecting a spin is deterministic. Usually, one may select the spins one by one following some order, for example “typewriter order”. In the Glauber dynamic, however, every spin has an equal chance of being chosen at each time step, regardless of being chosen before. The Metropolis acceptance criterion also includes the Boltzmann weight, , but it always flips a spin in favor of lowering the energy, such that the spin-flip probability is: Although both of the acceptance probabilities approximate a step curve and they are almost indistinguishable at very low temperatures, they differ when temperature gets high. For an Ising model on a 2d lattice, the critical temperature is . In practice, the main difference between the Metropolis–Hastings algorithm and with Glauber algorithm is in choosing the spins and how to flip them (step 4). However, at thermal equilibrium, these two algorithms should give identical results. In general, at equilibrium, any MCMC algorithm should produce the same distribution, as long as the algorithm satisfies ergodicity and detailed balance. In both algorithms, for any change in energy, , meaning that transition between the states of the system is always possible despite being very unlikely at some temperatures.