ITPEC FE Subject B October 2024 Question 15

From the answer group below, select the correct combination of answers to be inserted into A and B in the program. Here, the array indexes start at 1.

Suppose the weather in a city, from day to day, follows a Markov process. This implies the next day’s weather depends only on today’s weather and not on those of the previous days. If it rains today in the city, a probability 0.3 exists that it will rain again tomorrow. Similarly, the probability that tomorrow’s weather will be sunny is 0.4 and that it will be cloudy is 0.3. If today’s weather is sunny, the next day will be rainy, sunny, or cloudy with probabilities 0.2, 0.7, and 0.1, respectively. Additionally, if today’s weather is cloudy, the next day will be rainy, sunny, or cloudy with probabilities 0.25, 0.5, and 0.25, respectively.
Let us say that the weather is in state 1 if it is rainy, in state 2 if it is sunny, and in state 3 if it is cloudy. Then, the above is a three-state Markov chain whose transition probabilities are given by the following:

to123from10.30.40.320.20.70.130.250.50.25

Using this transition matrix, the probability distribution of the weather after several days can be estimated.
The program calculates the probability distribution of the weather of the city after three days from the present day and outputs a 3 × 3 square matrix that shows this probability distribution of the weather. For instance, if the weather on the present day is sunny (state 2), the probability that the weather three days after will be rainy (state 1) is the value in the second row and the first column of the outputted matrix.

[Program]
real [,]: pmat ← {{0.3, 0.4, 0.3}, {0.2, 0.7, 0.1}, {0.25, 0.5, 0.25}}
real [,]: dmat ← pmat
real [,]: smat
integer: i, j, k, m
for (increase m from 1 to A by 1)
smat ← {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}
for (increase i from 1 to 3 by 1)
for (increase j from 1 to 3 by 1)
for (increase k from 1 to 3 by 1)
smat[i, j] ← smat[i, j] + B
endfor
endfor
endfor
dmat ← smat
endfor
output dmat

Answer group

OptionAB

Explanation

A: 2, B: dmat[i, k] × pmat[k, j] — the distribution three days ahead is the transition matrix cubed, P3, and dmat already holds P before the loop.

One day is one multiplication by P. Row i of the current matrix times column j of P sums, over every state k, the chance of being in k so far and then moving from k to j: smat[i, j] = Σ dmat[i, k] × pmat[k, j], with k as the shared inner index.

dmat starts as P, one day ahead, and each pass of the m loop adds a day:

  • •after pass 1: P2, two days; for example sunny to rainy is 0.2 × 0.3 + 0.7 × 0.2 + 0.1 × 0.25 = 0.225
  • •after pass 2: P3, three days

So m runs from 1 to 2.

Answer (a)

Why not others:

  • •(c) and (e) — 3 or 4 passes give P4 or P5, four or five days ahead: they forget that dmat already holds the first day before the loop
  • •(b), (d) and (f) — Σ pmat[j, k] × dmat[k, i] is element [j, i] of the product stored at [i, j], so the output is the transpose: rows become the "to" state instead of today's state, and the rows no longer sum to 1 (for P3 they would be about 0.70, 1.78 and 0.52)

Key rule: n steps of a Markov chain are Pn; a loop that starts from P needs n - 1 multiplications, each summing row of the left matrix times column of the right one.

Math & Data Science · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.