← Back to Home

Solving Nonograms with Compressive Sensing: Part 2

3. Introducing compressive sensing

Today, we will consider how to turn the solution of a nonogram into a sparse vector. But first, let me take a detour and illustrate an approach that Oscar and I initially had considered and comment on its strengths and weaknesses in solving the puzzle.

Throughout our discussion, we will consider the stylish lambda example:

a. Initial attempt

We can indicate whether a cell needs to be empty or shaded with a binary number. Since a nonogram involves an m×nm \times n grid, it's natural to imagine the solution as a matrix X{0,1}m×nX \in \{0,\,1\}^{m \times n}. By listing the entries in single file, we can also think of the solution as a vector x{0,1}N\vec{x} \in \{0,\,1\}^{N}, with

N=mn.N = mn.

(The notations {0,1}m×n\{0,\,1\}^{m \times n} and {0,1}N\{0,\,1\}^{N} refer to the set of matrices with binary entries and the set of vectors with binary entries.)

The (i,j)(i,\,j)-th cell uniquely corresponds to xkx_{k}, the kk-th entry in the vector x\vec{x}. We let k=(i1)n+jk = (i - 1)n + j, for example. Then, assign xk=0x_{k} = 0 if the cell should be empty, and xk=1x_{k} = 1 if shaded.

The solution to the stylish lambda is given by a vector x{0,1}12\vec{x} \in \{0,\,1\}^{12}, where

x=[110001111101]T.\vec{x} = \bigl[ \,\,1\,\, \,\,1\,\, \,\,0\,\, \,|\, \,\,0\,\, \,\,0\,\, \,\,1\,\, \,|\, \,\,1\,\, \,\,1\,\, \,\,1\,\, \,|\, \,\,1\,\, \,\,0\,\, \,\,1\,\, \bigr]^{T}.

If we assume that a nonogram had been created randomly, then Lemma 2.1 says that half of the cells would be shaded. In other words, we can expect the sparsity level ss (the number of nonzero entries) of the solution x\vec{x} to be,

E(s)=mn2.\displaystyle\mathbb{E}(s) = \frac{mn}{2}.

Compressive sensing asks us to provide at least 2s=mn2s = mn measurements for sparse recovery of x\vec{x}, with an extra multiplicative factor of ln(Ns)=ln(2)\ln\bigl(\frac{N}{s}\bigr) = \ln(2) for stability. Rather fortunately, this factor is constant on average and independent of the puzzle size.

The problem is, it is not clear how to group cells to faithfully represent the row and column sequences. Consider the stylish lambda. The first row sequence (2)(2) means we must shade a block of 2 cells. How do we express the idea of "a group of cells" when each entry of x\vec{x} stands for a single cell?

One way is to enumerate all possibilities, e.g. we require that

x1x2=1orx2x3=1,x_{1}x_{2} = 1 \,\,\,\text{or}\,\,\, x_{2}x_{3} = 1,

but this creates additional problems. These constraints are nonlinear, the degrees of these constraints equal the block size (i.e. for larger blocks, the nonlinearity is more severe), and the solver that we use may not handle a logical operator such as "or."

Furthermore, for sequences like (1,1)(1,\,1) and (1,2)(1,\,2) with more than one number, we must also specify that there exist empty cells between any two consecutive blocks of cells. We do not know upfront how many empty cells there are, however. Again, we could consider all possibilities, but Theorem 2.3 tells us that doing this is very unwise.

Probably the best that we can do is to impose the row and column sequences weakly. For example, we require that the row sums and the column sums are satisfied. These, we can easily do with (m+n)(m + n) linear equations. However, the number of equations is nowhere close to 2s=mn2s = mn that is needed for sparse recovery.

b. Our solution

The main problems of representing the solution as a vector x\vec{x} as described above are that (1) it is hard to group cells and (2) to indicate that, in certain places, there needs to be empty cells.

We can come to a new insight by considering the stylish lambda and one of its rows, which has n=3n = 3 cells:

There are n(n+1)2=6\frac{n(n + 1)}{2} = 6 possible ways to shade a block of cells in this row. Mainly,

As shown above, we label these six objects by

ekj,e_{kj},

where kk is the size of the block of shaded cells, and jj is the starting column position of the block. (We listed the indices kk and jj in an "odd" manner, because it's easier to say what ekje_{kj} does in words. For example, we would say that e21e_{21} means "shade a block of 2 cells starting at the first column.")

Despite the conflict in terminologies, we call these six objects the (row) basis vectors, because we can write every row sequence as a unique sum of these basis vectors. For the stylish lambda,

we can represent rows 1 and 4 as,

=e11=0+e12=0+e13=0+e21=1+e22=0+e31=0= \underbrace{e_{11}}_{=\,0} + \underbrace{e_{12}}_{=\,0} + \underbrace{e_{13}}_{=\,0} + \underbrace{e_{21}}_{=\,1} + \underbrace{e_{22}}_{=\,0} + \underbrace{e_{31}}_{=\,0}

=e11=1+e12=0+e13=1+e21=0+e22=0+e31=0= \underbrace{e_{11}}_{=\,1} + \underbrace{e_{12}}_{=\,0} + \underbrace{e_{13}}_{=\,1} + \underbrace{e_{21}}_{=\,0} + \underbrace{e_{22}}_{=\,0} + \underbrace{e_{31}}_{=\,0}.

We did not write e11+e12+e13+e21+e22+e31=1+1+0+0+0+0e_{11} + e_{12} + e_{13} + e_{21} + e_{22} + e_{31} = 1 + 1 + 0 + 0 + 0 + 0 for row 1, because this violates the nonogram rule that two consecutive blocks are separated by empty cell(s). As long as we can enforce this rule, we would get a unique sum.

Since we can create these basis vectors for each row, let us insert an index ii to denote the row position of a basis vector. Hence, every basis vector has the name

eikj,where{i=1,,mk=1,,nj=1,,nk+1.\boxed{e_{ikj},\,\,\text{where}\,\,\left\{\begin{array}{l} i = 1,\,\cdots,\,m \\ k = 1,\,\cdots,\,n \\ j = 1,\,\cdots,\,n - k + 1. \end{array}\right.}

Sometimes, we will arrive at a result that holds true for any row. In such cases, we will suppress the index ii for simplicity. Also, we will use eikje_{ikj} to mean the name of the basis vector as well as the binary variable that indicates whether to shade a block of kk cells starting at the (i,j)(i,\,j)-th position. It will be obvious from the context to which we refer.

Let us store eikje_{ikj} as entries of a vector x{0,1}N\vec{x} \in \{0,\,1\}^{N}. Note that,

N=mn(n+1)2.\displaystyle\boxed{N = \frac{mn(n + 1)}{2}}.

The solution to the stylish lambda is given by x{0,1}24\vec{x} \in \{0,\,1\}^{24}, where

x=[e111e112e113e121e122e131e411e412e413e421e422e431]T=[000100001000000001101000]T.\begin{aligned} \vec{x} &= \bigl[ \,\,e_{111}\,\, \,\,e_{112}\,\, \,\,e_{113}\,\, \,\,e_{121}\,\, \,\,e_{122}\,\, \,\,e_{131}\,\, \,\cdots\, \,\,e_{411}\,\, \,\,e_{412}\,\, \,\,e_{413}\,\, \,\,e_{421}\,\, \,\,e_{422}\,\, \,\,e_{431}\,\, \bigr]^{T} \\ &= \bigl[\,\,0\,\, \,\,0\,\, \,\,0\,\, \,\,1\,\, \,\,0\,\, \,\,0\,\, \,|\, \,\,0\,\, \,\,0\,\, \,\,1\,\, \,\,0\,\, \,\,0\,\, \,\,0\,\, \,|\, \,\,0\,\, \,\,0\,\, \,\,0\,\, \,\,0\,\, \,\,0\,\, \,\,1\,\, \,|\, \,\,1\,\, \,\,0\,\, \,\,1\,\, \,\,0\,\, \,\,0\,\, \,\,0\,\, \bigr]^{T}. \end{aligned}

We call the manner in which we have listed the variables eikje_{ikj} in the solution vector x\vec{x} as the natural order of the basis vectors.

Our new approach allows the solution vector x{0,1}N\vec{x} \in \{0,\,1\}^{N} to be sparse. For any row sequence, we will likely need only a few basis vectors to represent the sequence. For the stylish lambda, we used 5 basis vectors out of the possible 24. This is because 5 numbers appear in the row sequences.

Had a nonogram been created randomly, Lemma 2.1 says that, on average, each row has n+14\frac{n + 1}{4} blocks of shaded cells. This means, we can recreate each row with n+14\frac{n + 1}{4} basis vectors. Hence, we expect the sparsity level ss to be,

E(s)=m(n+1)4.\displaystyle\boxed{\mathbb{E}(s) = \frac{m(n + 1)}{4}}.

This is nearly half of that from our initial approach, meaning we could make fewer measurements and reconstruct the solution. The logarithmic factor for stability is now ln(2n)\ln(2n), but this increases very slowly if the column size increases.

Furthermore, there is a huge prize: We can easily indicate a block of shaded cells now, thanks to the very construction of the basis vectors. Each number in a row sequence indicates a block of shaded cells, which corresponds to a particular basis vector.

By now, you may have noticed that the basis vectors lie along just one direction. Next time, I will detail how to build constraints from the nonogram, including those that say empty cells must exist between any two consecutive blocks. We will see that we can easily extract information from the row sequences but not from the column sequences.

Of course, we can also create basis vectors for a column so that we make a better use of the column sequences. At the end of the series, I will show the benefits of doing so.

Notes

We discussed the sparsity level in terms of its expected value. For analysis, it is more convenient and meaningful to consider the expectation, which (as we saw above) is a function "directly" of the size of the puzzle. However, we do know the exact value.

In the first approach, the sparsity level is equal to,

s=i=1mri,\displaystyle s = \sum_{i\,=\,1}^{m}\,r_{i},

the sum of all the row sums. It is also equal to the sum of all the column sums.

In the second approach, it is,

s=i=1mpi,\displaystyle s = \sum_{i\,=\,1}^{m}\,p_{i},

the total number of blocks of shaded cells (row-wise), or equivalently, how many numbers appear in the row sequences.