ArticleslgStudy

computer science

Wang and Landau algorithm

Wang and Landau algorithm is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Wang and Landau algorithm rather than just read about it. In short: The Wang and Landau algorithm, proposed by Fugao Wang and David P. Landau, is a Monte Carlo method designed to estimate the density of states of a system.

Key takeaways

  • Wang and Landau algorithm belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Wang and Landau algorithm to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Wang and Landau algorithm from memory before moving on to harder problems.

Reference excerpt

The Wang and Landau algorithm, proposed by Fugao Wang and David P. Landau, is a Monte Carlo method designed to estimate the density of states of a system. The method performs a non-Markovian random walk to build the density of states by quickly visiting all the available energy spectrum. The Wang and Landau algorithm is an important method to obtain the density of states required to perform a multicanonical simulation. The Wang–Landau algorithm can be applied to any system which is characterized by a cost (or energy) function. For instance, it has been applied to the solution of numerical integrals and the folding of proteins. The Wang–Landau sampling is related to the metadynamics algorithm.

Overview The Wang and Landau algorithm is used to obtain an estimate for the density of states of a system characterized by a cost function. It uses a non-Markovian stochastic process which asymptotically converges to a multicanonical ensemble. (i.e., to a Metropolis–Hastings algorithm with sampling distribution inverse to the density of states) The major consequence is that this sampling distribution leads to a simulation where the energy barriers are invisible. This means that the algorithm visits all the accessible states (favorable and less favorable) much faster than a Metropolis algorithm.

Algorithm Consider a system defined on a phase space Ω, and a cost function, E (the energy), bounded on a spectrum E∈Γ=[Emin,Emax]. E has an associated density of states, ρ(E), which is to be estimated. The estimator is ρ̂(E)≡exp⁡(S(E)). Because Wang and Landau algorithm works in discrete spectra, the spectrum Γ is divided in N discrete values with a difference between them of Δ, such that

Δ=Emax−EminN. Given this discrete spectrum, the algorithm is initialized by:

setting all entries of the microcanonical entropy to zero, S(Ei)=0 i=1,2,...,N initializing f=1 and initializing the system randomly, by putting in a random configuration 𝒓∈Ω. The algorithm then performs a multicanonical ensemble simulation: a Metropolis–Hastings random walk in the phase space of the system with a probability distribution given by P(𝒓)=1/ρ̂(E(𝒓))=exp⁡(−S(E(𝒓))) and a probability of proposing a new state given by a probability distribution g(𝒓→𝒓′). A histogram H(E) of visited energies is stored. Like in the Metropolis–Hastings algorithm, a proposal-acceptance step is performed, and consists in (see Metropolis–Hastings algorithm overview):

proposing a state 𝒓′∈Ω according to the arbitrary proposal distribution g(𝒓→𝒓′) accept/refuse the proposed state according to A(𝒓→𝒓′)=min⁡(1,eS−S′g(𝒓′→𝒓)g(𝒓→𝒓′)) where S=S(E(𝒓)) and S′=S(E(𝒓′)). After each proposal-acceptance step, the system transits to some value Ei, H(Ei) is incremented by one and the following update is performed:

S(Ei)←S(Ei)+f. This is the crucial step of the algorithm, and it is what makes the Wang and Landau algorithm non-Markovian: the stochastic process now depends on the history of the process. Hence the next time there is a proposal to a state with that particular energy Ei, that proposal is now more likely refused; in this sense, the algorithm forces the system to visit all of the spectrum equally. The consequence is that the histogram H(E) is more and more flat. However, this flatness depends on how well-approximated the calculated entropy is to the exact entropy, which naturally depends on the value of f. To better and better approximate the exact entropy (and thus histogram's flatness), f is decreased after M proposal-acceptance steps:

f←f/2. It was later shown that updating the f by constantly dividing by two can lead to saturation errors. A small modification to the Wang and Landau method to avoid this problem is to use the f factor proportional to 1/t, where t is proportional to the number of steps of the simulation.

Test system We want to obtain the DOS for the harmonic oscillator potential.

E(x)=x2, The analytical DOS is given by,

ρ(E)=∫δ(E(x)−E)dx=∫δ(x2−E)dx, by performing the last integral we obtain

ρ(E)∝{E−1/2,for x∈ℝ1const,for x∈ℝ2E1/2,for x∈ℝ3 In general, the DOS for a multidimensional harmonic oscillator will be given by some power of E, the exponent will be a function of the dimension of the system. Hence, we can use a simple harmonic oscillator potential to test the accuracy of Wang–Landau algorithm because we know already the analytic form of the density of states. Therefore, we compare the estimated density of states ρ̂(E) obtained by the Wang–Landau algorithm with ρ(E).

Sample code The following is a sample code of the Wang–Landau algorithm in Python, where we assume that a symmetric proposal distribution g is used:

g(𝒙′→𝒙)=g(𝒙→𝒙′) The code considers a "system" which is the underlying system being studied.

Parallel Implementations The Wang–Landau algorithm lends itself to parallelisation (utilising multiple CPU and/or GPU cores to improve simulation performance) in three key ways. First is that the energy domain may be divided into several smaller energy sub-domains, with an independent Wang–Landau walker gathering statistics in each sub-domain. (In this case, the global DOS is periodically recovered from the local DOS.) These energy sub-domains may be chosen to be non-uniform in size, to ensure a higher concentration of walkers in regions where the density of states is most challenging to converge. Second is that, in a given energy domain, multiple independent Wang–Landau walkers may gather statistics which are later combined. Third is that, in the case that multiple energy sub-domains are used, an overlap between energy sub-domains facilitates replica exchange, i.e. swapping of walkers from one energy sub-domain to another, which can improve exploration of the configuration space.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Wang and Landau algorithm

Start with the simplest possible case. Write down what Wang and Landau algorithm claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Wang and Landau algorithm before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Wang and Landau algorithm ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Wang and Landau algorithm

In research
Wang and Landau algorithm appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Wang and Landau algorithm in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Wang and Landau algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computational physics, Markov chain Monte Carlo, Statistical algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Wang and Landau algorithm outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Wang and Landau algorithm” →

How to study Wang and Landau algorithm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Wang and Landau algorithm means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Wang and Landau algorithm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Wang and Landau algorithm in simple terms?

The Wang and Landau algorithm, proposed by Fugao Wang and David P. Landau, is a Monte Carlo method designed to estimate the density of states of a system.

Why does Wang and Landau algorithm matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Wang and Landau algorithm?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Wang and Landau algorithm.

Tags

  • Computational physics
  • Markov chain Monte Carlo
  • Statistical algorithms

Keep exploring