Skip to article frontmatterSkip to article content

From matrix to insight

Any two-dimensional array of numbers may be interpreted as a matrix. Whether or not this is the only point of view that matters to a particular application, it does lead to certain types of analysis. The related mathematical and computational tools are universally applicable and find diverse uses.

7.1.1Tables as matrices

Tables are used to represent variation of a quantity with respect to two variables. These variables may be encoded as the rows and columns of a matrix.

7.1.2Graphs as matrices

Graphs are a useful way to represent the link structure of social networks, airline routes, power grids, sports teams, and web pages, to name a few examples. The natural interpretation is that the edge (vi,vj)(v_i,v_j) denotes a link from node ii to node jj, in which case we say that node ii is adjacent to node jj. One usually visualizes small graphs by drawing points for nodes and arrows or lines for the edges.

Here are some elementary results about adjacency matrices.

The representation of a graph by its adjacency matrix opens up the possibility of many kinds of analysis of the graph. One might ask whether the nodes admit a natural partition into clusters, for example. Or one might ask to rank the nodes in order of importance to the network as determined by some objective criteria—an application made famous by Google’s PageRank algorithm, and one which is mathematically stated as an eigenvalue problem.

7.1.3Images as matrices

Computers typically represent images as rectangular arrays of pixels, each of which is colored according to numerical values for red (R), green (G), and blue (B) components of white light. Most often, these are given as integers in the range from zero (no color) to 255 (full color). Thus, an image that is mm-by-nn pixels can be stored as an mm-by-nn-by-3 array of integer values. In Julia, we can work with an m×nm\times n matrix of 3-vectors representing entire colors.

Representation of an image as a matrix allows us to describe some common image operations in terms of linear algebra. For example, in Singular value decomposition we will use the singular value decomposition to compress the information, and in section-krylov-matrixfree we will see how to apply and remove blurring effects.

7.1.4Exercises

  1. ✍ Consider the terms numerical, analysis, and fun. Write out the term-document matrix for the following statements:

    (a) Numerical analysis is the most fun type of analysis.

    (b) It’s fun to produce numerical values for the digits of pi.

    (c) Complex analysis is a beautiful branch of mathematics.

  2. ✍ Write out the adjacency matrix for the following graph on six nodes.

    little graph
  3. ✍ Here is a graph adjacency matrix.

    [0101010101001001001011000000001001011001000010000]\begin{bmatrix} 0 & 1 & 0 & 1 & 0 & 1 & 0 \\ 1 & 0 & 1 & 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 & 1 & 0 & 1 \\ 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 1 & 0 \\ 1 & 1 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 \end{bmatrix}

    (a) How many vertices are adjacent to vertex 5?

    (b) How many edges are in the graph?

    (c) Is the graph directed or undirected?

    (d) Draw the graph.

  4. ⌨ Refer to Demo 7.1.5 on loading and displaying test images.

    (a) Display the “lighthouse” test image upside-down.

    (b) Display it mirror-reversed from left to right.

    (c) Display the image so that it is cropped to isolate the black beacon section at the top of the lighthouse.

  5. ⌨ For this problem you need to download and import data via:

    datafile = download("https://tobydriscoll.net/fnc-julia/_static/resources/actors.jld2")
    @load datafile A

    Based on data provided by the Self-Organized Networks Database at the University of Notre Dame, it contains information about the appearances of 392,400 actors in 127,823 movies, as given by the Internet Movie Database. The matrix A\mathbf{A} has Aij=1A_{ij}=1 if actor jj appeared in movie ii and zero elements elsewhere.

    (a) What is the maximum number of actors appearing in any one movie?

    (b) How many actors appeared in exactly three movies?

    (c) Define C=ATA\mathbf{C}=\mathbf{A}^T\mathbf{A}. How many nonzero entries does C\mathbf{C} have? What is the interpretation of CijC_{ij}?