ArticleslgStudy

computer science

Difference-map algorithm

Difference-map 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 Difference-map algorithm rather than just read about it. In short: The difference-map algorithm is a search algorithm for general constraint satisfaction problems. It is a meta-algorithm in the sense that it is built from more basic algorithms that perform projections onto constraint sets.

Difference-map algorithm — main illustration
Difference-map algorithm — illustration

Key takeaways

  • Difference-map 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 Difference-map algorithm to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Difference-map algorithm from memory before moving on to harder problems.

Reference excerpt

The difference-map algorithm is a search algorithm for general constraint satisfaction problems. It is a meta-algorithm in the sense that it is built from more basic algorithms that perform projections onto constraint sets. From a mathematical perspective, the difference-map algorithm is a dynamical system based on a mapping of Euclidean space. Solutions are encoded as fixed points of the mapping. Although originally conceived as a general method for solving the phase problem, the difference-map algorithm has been used for the boolean satisfiability problem, protein structure prediction, Ramsey numbers, diophantine equations, and Sudoku, as well as sphere- and disk-packing problems. Since these applications include NP-complete problems, the scope of the difference map is that of an incomplete algorithm. Whereas incomplete algorithms can efficiently verify solutions (once a candidate is found), they cannot prove that a solution does not exist. The difference-map algorithm is a generalization of two iterative methods: Fienup's Hybrid input output (HIO) algorithm for phase retrieval and the Douglas-Rachford algorithm for convex optimization. Iterative methods, in general, have a long history in phase retrieval and convex optimization. The use of this style of algorithm for hard, non-convex problems is a more recent development.

Algorithm The problem to be solved must first be formulated as a set intersection problem in Euclidean space: find an x in the intersection of sets A and B. Another prerequisite is an implementation of the projections PA and PB that, given an arbitrary input point x, return a point in the constraint set A or B that is nearest to x. One iteration of the algorithm is given by the mapping:

x↦D(x)=x+β[PA(fB(x))−PB(fA(x))],fA(x)=PA(x)−1β(PA(x)−x),fB(x)=PB(x)+1β(PB(x)−x) The real parameter β should not be equal to 0 but can have either sign; optimal values depend on the application and are determined through experimentation. As a first guess, the choice β=1 (or β=−1) is recommended because it reduces the number of projection computations per iteration:

D(x)=x+PA(2PB(x)−x)−PB(x) A point x is a fixed point of the map x↦D(x) precisely when PA(fB(x))=PB(fA(x)). Since the left-hand side is an element of A and the RHS is an element of B, the equality implies that we have found a common element to the two constraint sets. Note that the fixed point x itself need not belong to either A or B. The set of fixed points will typically have much higher dimension than the set of solutions. The progress of the algorithm can be monitored by inspecting the norm of the difference of the two projections:

Δ=|PA(fB(x))−PB(fA(x))|. When this vanishes, a point common to both constraint sets has been found and the algorithm can be terminated.

Example: logical satisfiability Incomplete algorithms, such as stochastic local search, are widely used for finding satisfying truth assignments to boolean formulas. As an example of solving an instance of 2-SAT with the difference-map algorithm, consider the following formula (~ indicates NOT):

(q1 or q2) and (~q1 or q3) and (~q2 or ~q3) and (q1 or ~q2) To each of the eight literals in this formula we assign one real variable in an eight-dimensional Euclidean space. The structure of the 2-SAT formula can be recovered when these variables are arranged in a table:

Rows are the clauses in the 2-SAT formula and literals corresponding to the same boolean variable are arranged in columns, with negation indicated by parentheses. For example, the real variables x11, x21 and x41 correspond to the same boolean variable (q1) or its negation, and are called replicas. It is convenient to associate the values 1 and -1 with TRUE and FALSE rather than the traditional 1 and 0. With this convention, the compatibility between the replicas takes the form of the following linear equations:

x11 = -x21 = x41 x12 = -x31 = -x42 x22 = -x32 The linear subspace where these equations are satisfied is one of the constraint spaces, say A, used by the difference map. To project to this constraint we replace each replica by the signed replica average, or its negative:

a1 = (x11 - x21 + x41) / 3 x11 → a1 x21 → -a1 x41 → a1 The second difference-map constraint applies to the rows of the table, the clauses. In a satisfying assignment, the two variables in each row must be assigned the values (1, 1), (1, -1), or (-1, 1). The corresponding constraint set, B, is thus a set of 34 = 81 points. In projecting to this constraint the following operation is applied to each row. First, the two real values are rounded to 1 or -1; then, if the outcome is (-1, -1), the larger of the two original values is replaced by 1. Examples:

(-.2, 1.2) → (-1, 1) (-.2, -.8) → (1, -1) It is a straightforward exercise to check that both of the projection operations described minimize the Euclidean distance between input and output values. Moreover, if the algorithm succeeds in finding a point x that lies in both constraint sets, then we know that (i) the clauses associated with x are all TRUE, and (ii) the assignments to the replicas are consistent with a truth assignment to the original boolean variables. To run the algorithm one first generates an initial point x0, say

Using β = 1, the next step is to compute PB(x0) :

This is followed by 2PB(x0) - x0,

and then projected onto the other constraint, PA(2PB(x0) - x0) :

Incrementing x0 by the difference of the two projections gives the first iteration of the difference map, D(x0) = x1 :

Here is the second iteration, D(x1) = x2 :

This is a fixed point: D(x2) = x2. The iterate is unchanged because the two projections agree. From PB(x2),

we can read off the satisfying truth assignment: q1 = TRUE, q2 = FALSE, q3 = TRUE.

Chaotic dynamics

In the simple 2-SAT example above, the norm of the difference-map increment Δ decreased monotonically to zero in three iterations. This contrasts with the behavior of Δ when the difference map is given a hard instance of 3-SAT, where it fluctuates strongly prior to the discovery of the fixed point. As a dynamical system the difference map is believed to be chaotic, and that the space being searched is a strange attractor.

Phase retrieval

… excerpt ends here. Continue reading the full article.

Illustrations

Difference-map algorithm: Time series of the norm of the difference-map increment Δ in the course of solving a random 3-SAT instance with 1000 variables and 4200 clauses.
Time series of the norm of the difference-map increment Δ in the course of solving a random 3-SAT instance with 1000 variables and 4200 clauses.
Difference-map algorithm: Fourier transform modulus (diffraction pattern) of the grayscale image shown being reconstructed at the top of the page.
Fourier transform modulus (diffraction pattern) of the grayscale image shown being reconstructed at the top of the page.

Worked examples

Example 1 — a first encounter with Difference-map algorithm

Start with the simplest possible case. Write down what Difference-map 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 Difference-map 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 Difference-map 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 Difference-map algorithm

In research
Difference-map 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 Difference-map 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
Difference-map algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics Constraint programming, Search algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Difference-map 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 “Difference-map algorithm” →

How to study Difference-map algorithm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Difference-map 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 Difference-map algorithm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Difference-map algorithm in simple terms?

The difference-map algorithm is a search algorithm for general constraint satisfaction problems. It is a meta-algorithm in the sense that it is built from more basic algorithms that perform projections onto constraint sets.

Why does Difference-map 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 Difference-map 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 Difference-map algorithm.

Tags

  • Constraint programming
  • Search algorithms

Keep exploring