## 7144CEM Assignment Help

## Principles of Data Science Assignment help

Task 1. Markov Chains

Example: Flowers. Consider a particular variety of flower which can take one of three colours: red, white and pink. Suppose after each year, 40% of red flowers remain red but 60% of red flowers mutate to pink. For pink flowers, 30% mutate to red, 50% remain as pink, and 20% mutate to white. For white flowers, 90% remain as white and 10% mutate to pink. We can capture these probabilities in a transition matrix π where the columns correspond to red, pink and white flowers in the current year and the rows correspond to red, pink and white flowers in the next year. π=[0.40.300.60.50.100.20.9]

If a certain garden initially has 80 of this variety of red flowers and 20 of this variety of white flowers then after one year: π[80020]=[325018]

so we would expect to see 32 red, 50 pink and 18 white flowers in the garden. If we look at the garden after 5 years: πππππ[80020]=π5[80020]=[20.8837.0842.04]

so we would expect to see approximately 21 red, 37 pink and 42 white flowers in the garden. This is an example of a system called a βMarkov chainβ. The next state of the system depends only on its present state and does not depend on the earlier history of the system.

Assessment: Mice in a maze. Consider the closed maze shown below containing seven rooms (labelled 0 to 6) with doorways connecting the rooms. A number of mice are placed in the maze and the mice then move randomly from room to room. Each time step, a mouse either stays in the same room (with probability 0.6) or leaves the room it is in by choosing at random (equally likely) one of the doors out of the room.

(1) Construct a 7Γ7 transition matrix π (as a numpy array) to model the mice moving around the maze as a Markov chain.

(2) Suppose that 50 mice are placed in Room 0 and 90 mice are placed in Room 1. All other rooms are initially empty. Use numpy to calculate how many mice we would expect to see in each room at the end of each time step for each of the next 30 time steps. Use Python to plot your results on a line graph showing one line for each room, together with a legend. Briefly comment on what you observe. You might find numpy.linalg.matrix_power() helpful.

(3) Use numpy to find the eigenvectors of the transition matrix π from part (1), and explain how one of these eigenvectors is related to the number of mice we would expect to see in each room in the βlong-run steady stateβ. Also, for each room π, find the expected number of time steps for a particular mouse initially located in room π to first return to room π. Hint: if ππ is the probability that the particular mouse is in room π in the βlong-run steady stateβ then the expected first return time is given by 1/ππ.

(4) Suppose the mouse population is in the βlong run steady stateβ from part (3) when a large piece of poisoned cheese is placed in Room 6 so that any mouse that enters that room instantly dies.

(a) Modify the transition matrix π from part (1) and estimate the number of time steps until 80% of the mice have died.

(b) The expected number of time steps needed for a mouse starting from room π to reach room π for the first time can be calculated using matrix operations and is denoted πππ. For a particular destination room π, let π be the transition matrix π from part (4)(a) but with row π and column π both deleted, and let πΌ be the 6Γ6 identity matrix. The sum of each column of the matrix (πΌβπ)β1 gives the values πππ. Use this method to find the expected number of time steps needed for a mouse to die, for each of the possible rooms in the maze that the mouse could start from. Briefly comment on what you observe.

## Leave A Comment