Skip to main content

Subsection 4.1.1 Predicting the weather

The following table tells us how the weather for any day (e.g., today) predicts the weather for the next day (e.g., tomorrow):

Today
sunny cloudy rainy
sunny 0.4 0.3 0.1
Tomorrow cloudy 0.4 0.3 0.6
rainy 0.2 0.4 0.3

This table is interpreted as follows: If today is rainy, then the probability that it will be cloudy tomorrow is 0.6, etc.

Homework 4.1.1.1.

If today is cloudy, what is the probability that tomorrow is

  • sunny?

  • cloudy?

  • rainy?

Solution

To answer this, we simply consult the table:

  • sunny? 0.3

  • cloudy? 0.3

  • rainy? 0.4

Homework 4.1.1.2.

If today is sunny, what is the probability that the day after tomorrow is sunny? cloudy? rainy?

Solution
  • The probability that it will be sunny the day after tomorrow and sunny tomorrow is \(0.4 \times 0.4 \text{.}\)

  • The probability that it will sunny the day after tomorrow and cloudy tomorrow is \(0.3 \times 0.4 \text{.}\)

  • The probability that it will sunny the day after tomorrow and rainy tomorrow is \(0.1 \times 0.2 \text{.}\)

Thus, the probability that it will be sunny the day after tomorrow, if it is sunny today, is \(0.4 \times 0.4 + 0.3 \times 0.4 + 0.1 \times 0.2 = 0.30 \text{.}\) Notice that this is the inner product of the vector that is the row for "Tomorrow is sunny" and the column for "Today is cloudy". By similar arguments, the probability that it is cloudy the day after tomorrow is 0.40 and the probability that it is rainy is 0.3.

Ponder This 4.1.1.3.

If today is cloudy, what is the probability that a week from today it is sunny? cloudy? rainy?

Think about this for at most two minutes, and then look at the answer.

Solution

We will not answer this question until a little later in this unit. We insert it to make the point that things can get messy! (Hopefully you didn't waste too much time.)

When things get messy, it helps to introduce some notation.

  • Let \(\chi_s^{(k)} \) denote the probability that it will be sunny \(k\) days from now (on day \(k \)).

  • Let \(\chi_c^{(k)} \) denote the probability that it will be cloudy \(k \) days from now.

  • Let \(\chi_r^{(k)} \) denote the probability that it will be rainy \(k \) days from now.

The discussion so far motivate the equations

\begin{equation*} \begin{array}{rcl} \begin{array}{r c r c r c r} \chi_s^{(k+1)} \amp=\amp 0.4 \times \chi_s^{(k)} \amp+\amp 0.3 \times \chi_c^{(k)} \amp+\amp 0.1 \times \chi_r^{(k)} \\ \chi_c^{(k+1)} \amp=\amp 0.4 \times \chi_s^{(k)} \amp+\amp 0.3 \times \chi_c^{(k)} \amp+\amp 0.6 \times \chi_r^{(k)} \\ \chi_r^{(k+1)} \amp=\amp 0.2 \times \chi_s^{(k)} \amp+\amp 0.4 \times \chi_c^{(k)} \amp+\amp 0.3 \times \chi_r^{(k)}. \end{array} \end{array} \end{equation*}

The probabilities that denote what the weather may be on day \(k \) and the table that summarizes the probabilities are often represented as a (state) vector, \(x^{(k)} \text{,}\) and transition matrix, \(P \text{,}\) respectively:

\begin{equation*} x^{(k)} = \left( \begin{array}{r} {\chi_s^{(k)}} \\ {\chi_c^{(k)}} \\ {\chi_r^{(k)}} \end{array} \right) \quad \mbox{and} \quad P = \left( \begin{array}{r r r r} 0.4 \amp 0.3 \amp 0.1 \\ 0.4 \amp 0.3 \amp 0.6 \\ 0.2 \amp 0.4 \amp 0.3 \end{array} \right). \end{equation*}

The transition from day \(k\) to day \(k+1 \) is then written as the matrix-vector product (multiplication)

\begin{equation*} \left( \begin{array}{r} {\chi_s^{(k+1)}} \\ {\chi_c^{(k+1)}} \\ {\chi_r^{(k+1)}} \end{array} \right) = \left( \begin{array}{r r r r} 0.4 \amp 0.3 \amp 0.1 \\ 0.4 \amp 0.3 \amp 0.6 \\ 0.2 \amp 0.4 \amp 0.3 \end{array}\right) \left( \begin{array}{c} {\chi_s^{(k)}} \\ {\chi_c^{(k)}} \\ {\chi_r^{(k)}} \end{array}\right) \end{equation*}

or \(x^{(k+1)} = P x^{(k)} \text{,}\) which is simply a more compact representation (way of writing) the system of linear equations.

Remark 4.1.1.1.

What this demonstrates is that matrix-vector multiplication can also be used to compactly write a set of simultaneous linear equations.

Assume again that today is cloudy so that the probability that it is sunny, cloudy, or rainy today is 0, 1, and 0, respectively:

\begin{equation*} x^{(0)} = \left( \begin{array}{r} {\chi_s^{(0)}} \\ {\chi_c^{(0)}} \\ {\chi_r^{(0)}} \end{array} \right) = \left( \begin{array}{r} {0} \\ {1} \\ {0} \end{array} \right). \end{equation*}

(If we KNOW today is cloudy, then the probability that is is sunny today is zero, etc.)

Remark 4.1.1.2.

Ah! Our friend the standard basis vector reappears!

Then the vector of probabilities for tomorrow's weather, \(x^{(1)} \text{,}\) is given by

\begin{equation*} \begin{array}{rcl} \left( \begin{array}{r} {\chi_s^{(1)}} \\ {\chi_c^{(1)}} \\ {\chi_r^{(1)}} \end{array} \right) \amp=\amp \left( \begin{array}{r r r r} 0.4 \amp 0.3 \amp 0.1 \\ 0.4 \amp 0.3 \amp 0.6 \\ 0.2 \amp 0.4 \amp 0.3 \end{array} \right) \left( \begin{array}{r} {\chi_s^{(0)}} \\ {\chi_c^{(0)}} \\ {\chi_r^{(0)}} \end{array} \right) = \left( \begin{array}{r r r r} 0.4 \amp 0.3 \amp 0.1 \\ 0.4 \amp 0.3 \amp 0.6 \\ 0.2 \amp 0.4 \amp 0.3 \end{array} \right) \left( \begin{array}{r} {0} \\ {1} \\ {0} \end{array} \right) \\ \amp=\amp \left( \begin{array}{r c r c r c r} 0.4 \times 0 \amp+\amp 0.3 \times 1 \amp+\amp 0.1 \times 0 \\ 0.4 \times 0 \amp+\amp 0.3 \times 1 \amp+\amp 0.6 \times 0 \\ 0.2 \times 0 \amp+\amp 0.4 \times 1 \amp+\amp 0.3 \times 0 \end{array} \right) = \left( \begin{array}{r} {0.3} \\ {0.3} \\ {0.4} \end{array} \right). \end{array} \end{equation*}
Remark 4.1.1.3.

Ah! \(P e_1 = p_1 \text{,}\) where \(p_1 \) is the second column in matrix \(P \text{.}\) You should not be surprised!

The vector of probabilities for the day after tomorrow, \(x^{(2)} \text{,}\) is given by

\begin{equation*} \begin{array}{rcl} \left( \begin{array}{r} {\chi_s^{(2)}} \\ {\chi_c^{(2)}} \\ {\chi_r^{(2)}} \end{array} \right) \amp=\amp \left( \begin{array}{r r r r} 0.4 \amp 0.3 \amp 0.1 \\ 0.4 \amp 0.3 \amp 0.6 \\ 0.2 \amp 0.4 \amp 0.3 \end{array} \right) \left( \begin{array}{r} {\chi_s^{(1)}} \\ {\chi_c^{(1)}} \\ {\chi_r^{(1)}} \end{array} \right) = \left( \begin{array}{r r r r} 0.4 \amp 0.3 \amp 0.1 \\ 0.4 \amp 0.3 \amp 0.6 \\ 0.2 \amp 0.4 \amp 0.3 \end{array} \right) \left( \begin{array}{r} {0.3} \\ {0.3} \\ {0.4} \end{array} \right) \\ \amp=\amp \left( \begin{array}{r c r c r c r} 0.4 \times 0.3 \amp+\amp 0.3 \times 0.3 \amp+\amp 0.1 \times 0.4 \\ 0.4 \times 0.3 \amp+\amp 0.3 \times 0.3 \amp+\amp 0.6 \times 0.4 \\ 0.2 \times 0.3 \amp+\amp 0.4 \times 0.3 \amp+\amp 0.3 \times 0.4 \end{array} \right) = \left( \begin{array}{r} {0.25} \\ {0.45} \\ {0.30} \end{array} \right). \end{array} \end{equation*}
Homework 4.1.1.4.

Repeating this process (preferrably using Python rather than by hand), we can find the probabilities for the weather for the next seven days, under the assumption that today is cloudy, by completing the following calculations in the obvious way:

Solution

We tabulate the result:

\begin{equation*} \begin{array}{| c || c | c | c | c | c | c | c | |} \hline k = \amp ~~~~~0~~~~~ \amp ~~~~~1~~~~~ \amp ~~~~~2~~~~~ \amp ~~~~~3~~~~~ \\ \hline x^{(k)} = \amp \left( \begin{array}{r} 0 \\ 1 \\ 0 \end{array} \right) \amp \left( \begin{array}{r} 0.3 \\ 0.3 \\ 0.4 \end{array} \right) \amp \left( \begin{array}{r} 0.25 \\ 0.45 \\ 0.30 \end{array} \right) \amp \left( \begin{array}{r} 0.265 \\ 0.415 \\ 0.320 \end{array} \right) \\ \hline ~ \\ k = \amp ~~~~~4~~~~~ \amp ~~~~~5~~~~~ \amp ~~~~~6~~~~~ \amp ~~~~~7~~~~~ \\ \hline x^{(k)} = \amp \left( \begin{array}{r} 0.26325 \\ 0.42075 \\ 0.31600 \end{array} \right) \amp \left( \begin{array}{r} 0.26312 \\ 0.42112 \\ 0.31575 \end{array} \right) \amp \left( \begin{array}{r} 0.26316 \\ 0.42104 \\ 0.31580 \end{array} \right) \amp \left( \begin{array}{r} 0.2625 \\ 0.4225 \\ 0.3150 \end{array} \right) \\ \hline \end{array} \end{equation*}

We could build a table that tells us how to predict the weather for the day after tomorrow from the weather today:

Today
sunny cloudy rainy
Day after sunny
tomorrow cloudy
rainy

One way you can do this is to observe that

\begin{equation*} \begin{array}{rcl} \left( \begin{array}{r} {\chi_s^{(2)}} \\ {\chi_c^{(2)}} \\ {\chi_r^{(2)}} \end{array} \right) \amp=\amp \left( \begin{array}{r r r r} 0.4 \amp 0.3 \amp 0.1 \\ 0.4 \amp 0.3 \amp 0.6 \\ 0.2 \amp 0.4 \amp 0.3 \end{array} \right) \left( \begin{array}{r} {\chi_s^{(1)}} \\ {\chi_c^{(1)}} \\ {\chi_r^{(1)}} \end{array} \right) \\ \amp=\amp \left( \begin{array}{r r r r} 0.4 \amp 0.3 \amp 0.1 \\ 0.4 \amp 0.3 \amp 0.6 \\ 0.2 \amp 0.4 \amp 0.3 \end{array} \right) \left( \left( \begin{array}{r r r r} 0.4 \amp 0.3 \amp 0.1 \\ 0.4 \amp 0.3 \amp 0.6 \\ 0.2 \amp 0.4 \amp 0.3 \end{array} \right) \left( \begin{array}{r} {\chi_s^{(0)}} \\ {\chi_c^{(0)}} \\ {\chi_r^{(0)}} \end{array} \right) \right) = Q \left( \begin{array}{r} {\chi_s^{(0)}} \\ {\chi_c^{(0)}} \\ {\chi_r^{(0)}} \end{array} \right) , \end{array} \end{equation*}

where \(Q \) is the transition matrix that tells us how the weather today predicts the weather the day after tomorrow. (Well, actually, we don't yet know that applying a matrix to a vector twice is a linear transformation... We'll learn that later this week.)

Now, just like \(P \) is simply the matrix of values from the original table that showed how the weather tomorrow is predicted from today's weather, \(Q \) is the matrix of values for the above table.

Homework 4.1.1.5.

Given

Today
sunny cloudy rainy
sunny 0.4 0.3 0.1
Tomorrow cloudy 0.4 0.3 0.6
rainy 0.2 0.4 0.3

fill in the following table, which predicts the weather the day after tomorrow, given the weather today:

Today
sunny cloudy rainy
Day after sunny
tomorrow cloudy
rainy

Now here is the hard part: Do so without using your knowledge about how to perform a matrix-matrix multiplication, since you won't learn about that until later this week...

Hint

May we suggest that you use Python to perform the necessary calculations. You can start with this Sage cell.

Solution

By now surely you have noticed that the \(j\)th column of a matrix \(A\text{,}\) \(a_j \text{,}\) equals \(A e_j \text{.}\) So, the \(j \)th column of \(Q\) equals \(Q e_j \text{.}\) Now, using \(e_0 \) as an example,

\begin{equation*} \begin{array}{rcl} q_0 = Q e_0 \amp=\amp P ( P e_o ) = \left( \begin{array}{r r r r} 0.4 \amp 0.3 \amp 0.1 \\ 0.4 \amp 0.3 \amp 0.6 \\ 0.2 \amp 0.4 \amp 0.3 \end{array} \right) \left( \left( \begin{array}{r r r r} 0.4 \amp 0.3 \amp 0.1 \\ 0.4 \amp 0.3 \amp 0.6 \\ 0.2 \amp 0.4 \amp 0.3 \end{array} \right) \left( \begin{array}{c} 1 \\ 0 \\ 0 \end{array} \right) \right) \\ \amp = \amp \left( \begin{array}{r r r r} 0.4 \amp 0.3 \amp 0.1 \\ 0.4 \amp 0.3 \amp 0.6 \\ 0.2 \amp 0.4 \amp 0.3 \end{array} \right) \left( \begin{array}{r r r r} 0.4 \\ 0.4 \\ 0.2 \end{array} \right) = \left( \begin{array}{r r r r} 0.3 \\ 0.4 \\ 0.3 \end{array} \right) \end{array} \end{equation*}

Let's make Python do the work instead:

The other columns of \(Q \) can be computed similarly:
This yields

Today
sunny cloudy rainy
Day after sunny 0.30 0.25 0.25
Tomorrow cloudy 0.40 0.45 0.40
rainy 0.30 0.30 0.35