Skip to main content

Authors in a Markov matrix: Which author do people find most inspiring? (14)


Let's continue the story of matrix calculation from the last time. It's a bit cumbersome to write the same adjacency matrix every time, let's call this station connection matrix \(M_{bahn}\) since Bahn means train in German.
\begin{eqnarray*} M_{bahn} &= & \left[ \begin{array}{cccc} 1 & 1 & 0 & 0 \\ 1 & 1 & 1 & 1 \\ 0 & 1 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ \end{array} \right] \end{eqnarray*}
We can compute neighbor stations by applying \(M_{bahn}\) to the station vector. If we apply the \(M_{bahn}\) twice to the the station vector, you can get the reachable station by two hops. The resulting number means how many possible paths to reach the station. Let's apply the \(M_{bahn}\) twice to the station vector that means one is at the Weinmeisterstr.
\begin{eqnarray*} (M_{bahn})^2 \left[ \begin{array}{c} 1 \\ 0 \\ 0 \\ 0 \\ \end{array} \right] &=& \left[ \begin{array}{c} 2 \\ 2 \\ 1 \\ 1 \\ \end{array} \right] \end{eqnarray*}
The resulting element of the vector is how many paths to get the each station by 2 hops. Namely:
\begin{eqnarray*} \left[ \begin{array}{c} 2 \\ 2 \\ 1 \\ 1 \\ \end{array} \right] \begin{array}{cccl} \mbox{Wein.} & \rightarrow & \mbox{Wein.} & \mbox{2 paths} \\ \mbox{Wein.} & \rightarrow & \mbox{Alex.} & \mbox{2 paths} \\ \mbox{Wein.} & \rightarrow & \mbox{Hack.} & \mbox{1 path} \\ \mbox{Wein.} & \rightarrow & \mbox{Jann.} & \mbox{1 path.} \\ \end{array} \end{eqnarray*} For instance, the first entry is 2, this means there are two paths from Weinmeisterstr to Weinmeisterstr by two hops. The first path is
Wein. \(\rightarrow\) Alex. \(\rightarrow\) Wein.
that first hop is go to Alexanderplatz, then second hop is go back to the Weinmeisterstr. The second path is
Wein. \(\rightarrow\) Wein. \(\rightarrow\) Wein.
that first hop is stay at Weinmeisterstr and second hop is also stay at Weinmeisterstr. Therefore, two different paths to go to Weinmeisterstr with two hops.

I recommend to use octave [6] or matlab to compute this kind of computation. I personally like matlab, but, the license is too expensive for me to do my personal hobby. I will definitely buy if they provide 5 years older version including toolboxes with 100 Euro. I am looking for the matlab Home edition like Mathematica Home edition. However, it seems it is 100 times expensive. So, I usually use octave. This free software is also a great software. The followings show the computation result by octave. (I edited the output result to fit into the column.)

octave:6> Mb = [1 1 0 0; 1 1 1 1;
                0 1 1 0; 0 1 0 1];
octave:7> w = [1 0 0 0]';
octave:8> Mb * w
ans =
   1
   1
   0
   0
octave:9> Mb * Mb * w
ans =
   2
   2
   1
   1


How is the three steps.

octave:10> Mb^3 * w
ans =
   4
   6
   3
   3

The first element is 4, this means there are four paths from Weinmeisterstr to Weinmeisterstr with three hops as the following.
\begin{eqnarray*} \begin{array}{ccccccc} \mbox{W} & \rightarrow & \mbox{W} & \rightarrow & \mbox{W} & \rightarrow & \mbox{W} \\ \mbox{W} & \rightarrow & \mbox{A} & \rightarrow & \mbox{W} & \rightarrow & \mbox{W} \\ \mbox{W} & \rightarrow & \mbox{W} & \rightarrow & \mbox{A} & \rightarrow & \mbox{W} \\ \mbox{W} & \rightarrow & \mbox{A} & \rightarrow & \mbox{A} & \rightarrow & \mbox{W} \\ \end{array} \end{eqnarray*}
Where W is Weinmeisterstr, A is Alexanderplatz. There are three allows, this means three movements (or stay).

Here you saw how you used an adjacency matrix to know where you were after n steps movement.

By the way, why does an adjacency matrix tells us the number of paths? (The following explanation assumes you know about the relationship between the column space and the solution space. If you are not familiar with them, you can skip this paragraph.) First of all, we need to transpose the matrix if the graph is a directed graph. Then each column represents connection of the neighbor nodes. The matrix has now number of column dimension column space which is the neighborhood connection space. The solution space is a linear combination of the column space. Thus this is a connection combination. The column space has all the possibility of the neighbor connection. How we can get a linear combination of the column space? The answer is applying the matrix to a vector. This is the brief reason why an adjacency matrix can tell us the reachable nodes. If you know the solution, like you know how many paths you need to visit the stations, you can also know the last step by solving the system. Though this is not so interesting question for me of the station connection graph. Since my usual question is where can I reach to in some steps, not which station I came from.

Now we know how to write a graph in a matrix form and how to use the adjacency matrix. Next article, we are going to look into the property of the matrix by the eigenanalysis.

References

[6]  GNU Octave, http://www.gnu.org/software/octave/

Comments

Popular posts from this blog

Why parallelogram area is |ad-bc|?

Here is my question. The area of parallelogram is the difference of these two rectangles (red rectangle - blue rectangle). This is not intuitive for me. If you also think it is not so intuitive, you might interested in my slides. I try to explain this for hight school students. Slides:  A bit intuitive (for me) explanation of area of parallelogram  (to my site, external link) . 

Geometric Multiplicity: eignvectors (2)

If eigenvectors of a matrix A are independent, it is a happy property. Because the matrix A can be diagonalized with a matrix S that column vectors are eigenvectors of A . For example, Why this is a happy property of A? Because I can find A's power easily. A^{10} is not a big deal. Because Λ is a diagonal matrix and power of a diagonal matrix is quite simple. A^{10} = SΛ^{10} S^{-1} Then, why if I want to compute power of A ? That is the same reason to find eigenvectors. Eigenvectors are a basis of a matrix. A matrix can be represented by a single scalar. I repeat this again. This is the happy point, a matrix becomes a scalar. What can be simpler than a scalar value. But, this is only possible when the matrix S's columns are independent. Because S^{-1} must be exist. Now I come back to my first question. Is the λ's multiplicity related with the number of eigenvectors? This time I found this has the name. Geometric multiplicity (GM): the number of in...

Gauss's quote for positive, negative, and imaginary number

Recently I watched the following great videos about imaginary numbers by Welch Labs. https://youtu.be/T647CGsuOVU?list=PLiaHhY2iBX9g6KIvZ_703G3KJXapKkNaF I like this article about naming of math by Kalid Azad. https://betterexplained.com/articles/learning-tip-idea-name/ Both articles mentioned about Gauss, who suggested to use other names of positive, negative, and imaginary numbers. Gauss wrote these names are wrong and that is one of the reason people didn't get why negative times negative is positive, or, pure positive imaginary times pure positive imaginary is negative real number. I made a few videos about explaining why -1 * -1 = +1, too. Explanation: why -1 * -1 = +1 by pattern https://youtu.be/uD7JRdAzKP8 Explanation: why -1 * -1 = +1 by climbing a mountain https://youtu.be/uD7JRdAzKP8 But actually Gauss's insight is much powerful. The original is in the Gauß, Werke, Bd. 2, S. 178 . Hätte man +1, -1, √-1) nicht positiv, negative, imaginäre (oder gar um...