As you probably know, there are two kinds of linear system solvers out there.

- “Exact” like the Gauss elimination

- Iterative like Jacobi or Gauss – Seidel (yes, it’s the same Gauss. This guy is everywhere!)

Today I want to talk about another method, the one invented by Kaczmarz (as well as a few other people, you can check Wikipedia to learn more about them). This method falls in the “iterative methods” category. Another name for it is ART or Algebraic Reconstruction Technique.

Let’s setup the problem a bit. We have a matrix and a vector b and we want to find an x such that . Everything is straightforward so far.

The point of an iterative method is to find a function/operator g such that if g has a fixed point , then that fixed point will also be the solution to the problem we are trying to solve. Thus, two questions which come to mind immediately are : Out of all g, which of them have this fixed point and under which conditions does the sequence actually converge?

Although the second question is very important, the first is not easier and usually we have to turn the problem around until we find a good formulation through which we can build such a g. An easy example for that is the search for the root of a smooth function and the idea to linearize to find an approximate root of a new object, which in turn leads to Newton’s method. In our case, the theme is to find the solution of an equivalent least squares problem.

## Inspiration from optimization

Let’s say that we want to solve the following problem :

Find an x such that

We can say a few things about this problem if we know the properties of A. Is (R(A) being the column space of A)? Then there is an x such that , i.e there is at least one absolute minimum. If the matrix is invertible, the minimizer is unique and thus searching for the minimum is equivalent to solving .

It may be strange to some that we are interested in this formulation in the case that . After all, this problem is usually introduced in the opposite case, when we don’t have b anywhere in our space of A, so we want the next best thing. It turns out that this gives us a very powerful algorithm though. Before we talk about it, we need to consider another related problem.

## Finding the common ground

Imagine that we have two convex & closed sets, D and C, which share a common point. Our goal is to find that point!

Here’s a very quick review of convex sets. To bypass it, ctrl + f, Review end. Keep that on your search field to quickly bypass similar reviews.

Review start {

A set B is convex if and only if for any two elements and any , the point . In other words, the line that connects two different points of a set rests completely inside the set.

A set that is convex :

And another one, not convex this time,

Convexity of a set can make a big difference both in application and in theory.

A set is closed if it’s complement is open and a set is open if we can find a small ball around every point of the set so that the ball is inside it.

Review end}

So, how can we find that point? An idea is to use a method called alternating projection. To use this, we have to pick a starting point, let’s say , and project it onto one of the two sets, say D. Then, we project the resulting point onto C and we start all over, projecting this new point onto D, then onto C, etc, etc.

In mathematical language, that would be stated as follows. Let the projection matrices onto C and D and pick a starting point . Then iterate the sequence until a criterion is fulfilled. Does this fixed point iteration have the correct fixed point, i.e a common point of C and D?

Let’s say that x is that point. Then, since x belongs to D, . In addition, since x belongs to C, . Thus, indeed if x is the common point, it’s also a fixed point of T. Going backwards, we can also see that the converse holds, that if x is a fixed point of T, then it has to be a common point of C and D.

The simplest convex and closed set comes from the intersection of any convex set with a line. Now, with our new knowledge, let’s return to our problem.

## A “trivial” problem

Up to this point, we’ve written the problem Ax = b as an optimization problem and we’ve talked about a method to find the common point of two closed and convex sets (essentially, through optimization again). It’s time to connect those worlds now to get to the Kaczmarz algorithm.

When trying to solve Ax = b, we are trying to find an x such . Or perhaps we should say that we try to find the common point x of the hyperplanes defined by , where is the i-th row of A and is the i-th component of b. This hyperplane can be written as but I like to present it in a “simpler” way, like this,

Stating it in this way exposes the role of as a normal vector of the hyperplane passing from . It also enables us to find the projection of a vector y onto that hyperplane by

By now, you probably have guessed what we are working on to. We are gonna start from a point and start projecting it onto the different hyperplanes until we get the common point of the hyperplanes, which is a solution vector of the system Ax = b! Earlier we said that to apply the alternating projection method we need convex and closed sets and we are in luck since our hyperplanes are closed and affine. The definition of an affine set is the same with that of a convex set with a twist; t now can be any real number. A trivial affine set is a line. Check also that an affine set in has to be unbounded in at least one dimension.

## Visualizing the algorithm

So, the easier thing we can do is pick an easy problem for which we can visualize what’s happening. So, let’s fix A and b, , and let’s write our algorithm for finding x.

- Pick
- While (criterion == False)
- End while

At the end, . Let’s see what happens for A and b as we picked before.

The red and black lines are the hyperplanes defined by the rows of A. The blue line represents the steps of the algorithm and the green and red stars are the exact and approximate solutions of . Seeing this graph, one gets the feeling that the concept is actually really simple & impressive at the same time. 😀

Here is a very simple Matlab code that produces the previous graph.

function [x, sol] = Kaczmarz() A = [1,1;2,5]; b = [1;1]; x0 = rand(2,1)*6; sol = A\b; fprintf('Solution of system is : %1.3f , %1.3f\n',sol(1), sol(2)); x = x0; m = size(A,1); close; hold on; f1 = @(x)b(1)/A(1,2) - A(1,1)/A(1,2)*x; f2 = @(x)b(2)/A(2,2) - A(2,1)/A(2,2)*x; fplot(f1,[-6,6],'k'); fplot(f2,[-6,6],'r'); plot(sol(1), sol(2), 'g*'); maxIter = 50; Iter = 0; while(norm(A*x - b) > 1e-3 && Iter < maxIter) for i = 1 : m xprev = x; x = x + (b(i) - A(i,:)*x)*A(i,:).'/norm(A(i,:).')^2; plot([xprev(1),x(1)],[xprev(2),x(2)],'b--.'); Iter = Iter + 1; pause(1); end end plot(x(1),x(2),'r*') hold off; end

## Under the rug

There are a couple of things that we did not talk about.

- What’s the dependence on for convergence?
- How fast is it converging?
- We picked i as in the algorithm. Is there another way, better perhaps in terms of rate of convergence, to pick i?
- What happens if the system is overdetermined?

I will hold onto those questions for another post.

## One thought on “The Kaczmarz method for solving linear systems of equations”

Comments are closed.