Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Mathematics and Computational Methods of Complex Systems (MCMC 2022)

Question 1 (16 marks)

Consider a symmetric matrix A, and the matrix B = = A2.

a. Show that if A is an eigenvalue of A, then A2 is an eigenvalue of B. (4 marks)

b. Show that B is also a symmetric matrix, and use the eigenvalue decomposition of A (i.e. that A = UTAU) to find the eigenvalue decomposition of B. (4 marks)

c. Use the previous results as inspiration to construct a new matrix C which has the same eigenvalues of A and satisfies CTC = A. Show that C is also symmetric, and hence can be used to define the "square root" of a matrix (i.e. \/~A = C). (4 marks)

d. Design an algorithm that, given A, builds its corresponding C. Implement it in Python, and show that is works using one example. (4 marks)

Question 2 (12 marks)

Here we will calculate the critical values of the function /(x, y) = (x — l)4 + (y — 4)2 (i.e. the values of x and y for which the gradient of f is zero) in two alternative ways.

a. Calculate the gradient of f analytically. (4 marks)

b. Find the critical values of f by equating the gradient found in the previous item to zero. How many critical values does the function have? Use techniques to identify if the values found are a minimum, a maximum, ora saddle point. (4 marks)

c. Make a code implementing gradient descent on f. Confirm if the resulting solution is equal to the one provided in the previous point. (4 marks)

Question 3 (12 marks)

Verify the fundamental theorem of calculus in a concrete example.

a. Consider the function /(x) = 2 cos(x) + x3 4- and calculate analytically G(y) = £ f(x)dx. (4 marks)

b. Now, calculate the derivative of G(x) as found in the previous example, and show that G'(x) = f(x). (4 marks)

c. Plot G(x) forx from 0 to 10, and use the values of /(x) to draw the tangent lines ofG every 1 units ofx (i.e. atx = 1, x = 2,..., and x = 9). (4 marks)

Question 4 (20 marks)

Here we will explore how to implement a linear regression model via gradient descent. For this, we will use the following "dataset", which you can re-generate for different values of the parameters a and b.

In [2]:

from numpy. random import normal import matplot lib. pyplot as pit

a = 4 # height

b = 2 # slope

# generate data

N = 200 # sample size

X normal (loc=0. 0, scale=l. 0, size二N) W = normal (loc=0. 0, scale=l. 0, size=N) Y = a + b*X + W

# plot data pit. scatter (X, Y) pit. xlabel (' X') pit. ylabel (' Y') pit. show0

 

Let us consider now the model given by F(x, ivi, W2) = which has two parameters W\ and W2- We want to adjust the values of and so

that F is a good approximation of the 'data' Y plotted above. For this purpose, let's do the following:

a. Write a python function that takes as arguments X and Y, and returns the mean square error of F given by

]N

EOl,W2)= — £(勿1 + W2Xt -弟2,

A i=l

where x, and yt are the i-th element of the arrays X and Y, respectively. (4 marks)

b. Calculate the gradient of analytically. Then, implement a function that calculates the gradient in Python. (4 marks)

c. Using the function of the previous item, implement a gradient descent algorithm that can estimate good values of u)i and u)2- Show that it works, i.e. that the final values of and are similar to the ones of a and b used above to generate the data. (4 marks)

d. Make a plot including a scatter plot of the data Y (i.e. same as above), a linear function using the initial values of and a linear function using it final values, and a linear function using the values of a and b. Make sure to add plot labels for the linear functions so we know which is which! (4 marks)

e. Write another python function for the following error function:

~ 1 N

E(wu W2)= £(山1 + w2xi -弟气

~ " i=1

Calculate analytically the gradient of E, and implement another python function that calculates it. (4 marks)

Question 5 (15 marks)

Game 1

You are presented with three locked boxes: , %, and 83. One of the boxes contains £X, but you don't know which. The others are empty. You will choose one of the boxes, with uniform probability.

• Let's call the box with the money BR. So for instance, if the first box has the money, we write BR = Bi

・ Let's call the chosen box Bc. So if we choose the third box, we write Bc = B3.

a. Describe the outcome space (i.e. sample space). It might help to note that there are two uncertain events here (2 marks)

b. Once you choose a box, it is unlocked and you are allowed to keep the money, if there is any. Let R be a random variable whose value is the amount of money you earn. Calculate E[A] (your expected reward), and var(R) (variance of the reward). (4 marks)

The steps you took to get there should be concise but clear....! don't want just two numbers as the answer!

Game 2

1. After you have chosen a box, you are no longer allowed to immediately open it. Instead, I open one of the empty boxes that don't have any money, and show you that they are empty.

2. Then you have the option to stick with your initial choice, or swap to the final (unopened, unchosen) box.

3. Finally your chosen box (whether your original choice or the swapped one) is opened and you can take the reward inside, if there is any.

c. What are the expected value and variance of your reward if you use the 'stick' strategy? What about if you use the 'swap1 strategy? (4 marks)

Hint: Separate outcomes into two events: 1. that you initially, unknowingly choose the correct box, and 2. that you choose one of the incorrect boxes

d. Instead of having one box with a reward amongst three total boxes, suppose we have K boxes with a reward out of N total boxes. What are the expected value and the variance of the reward now for the swap strategy? (5 marks)

Question 6 (25 marks)

Recall the Lotka volterra model of predator-prey interactions from the lectures:

N(t) = aN(t) - bN(t)P(t)

P(t) = cN(t)P(t) - dP(t)

where N(t) is the number of prey, P(t) is the number of predators, a and b are the birth and death rates of prey, c and d are the birth and death rates of predators.

a) In this model, what do the dynamics of the prey population over time look like in the absence of predators (P(0) = 0)? Do you think this is reasonable? (A verbal description without maths is sufficient, although you are welcome to use equations if you like} (3 marks)

A common alteration of the birth rate in Lotka-Volterra-style models, which somewhat deals with the issue raised in question a), is the following:

N(t) = aN(t)

where K > 1 is a parameter we will ask you to describe.

b) Can you verbally describe how this deals with the issue of question a? What is the maximum value the prey population could take after starting from an initial population of 1? How would you interpret the parameter K? (3 marks)

We are now going to deal with a model of species competition. Two species which don't predate on each other, but compete for a limited food source. Their respective populations are and JV2O).

M)= riM(0 (1 -潔-如詈)
)=50) (1 --如豈)

Notice that the differential equation describing population change of each species , is exactly the same as for the differential equation of question b, except it includes an additional term 也快.This term models inter-species competition. For instance, if N2(t) is large, this term exerts a negative pull on the population growth rate of M(f).

We are now going to reduce the number of parameters in our model by nondimensionalisation. The nondimensionalised model is:

票■(£)= wifr) (1 -旳O) - ai2«2W)
争,-或m))

where the new parameters, expressed in terms of the original parameters, are:

旳=", u2 =告, t = rxt, p =?????

Ki K2

,K2 -

。12 = ®12 — 。21 = »21 —

Ki K2

c) Figure out what p is, in terms of the parameters of the original equation. Describe what it represents biologically (Possible even if you couldn't find its formula using common sense and after running the simulations below) (2 marks)

d) We're now going to simulate the differential equation several times. So write some code for simulating the differential equation, using scipy. integrate. solve_ivp . Of course, to actually simulate the system, you will need initial conditions and parameter values: (4 marks)

• For each simulation, we are going to have the following initial conditions:

«i(0) = ”2(0) = 0.1

However, we will change the parameters repeatedly, to see how they influence the behaviour of the model.

Simulate repeatedly with each of the following sets of parameter values (no need to write or plot anything for the report). The point of this is only to get a feel for how the model behaviour changes with the parameters.

“12 = 0.6 «21 = 0-4 p = 5

C12 = 0.4 «21 0.6 p = 5

e) From simulating, with these parameter combinations, what seems to be more important for long term species survival in this model: its natural growth rate or the degree to which it is suppressed by its competitor? Plot ONE simulation from the parameter values above that supports your conclusion. (3 marks)

f) Now calculate the four fixed points of the differential equation. You will find three are easier, and one is harder. For all four fixed points, briefly describe (1/2 sentences) what each fixed point represents in terms of the competition between the two species. Although you don't need the previous simulations for this question, they might be a useful sanity check for your answers! (5 marks)

Our system of differential equations is in the general form:

父(f) = /'(x(f)),

where x(t) is the vector u2(t)]. Note that t is just time with rescaled units (like minutes vs seconds), so you can treat it as time.

g) Calculate the Jacobian matrix (2 marks)

j(x)=畏(x)

ax

h) Evaluate this Jacobian matrix at the two fixed points you arrive at when using the parameters:

(212 = 0.9 «2i = LI P 1.6

“12 = 1.1 “21 = 0.9 p  1.6

What are the requirements on the values of % and %i for these fixed points to be stable? (3 marks)

To do this, figure out conditions on when the Jacobian matrix has appropriate eigenvalues. Ybu don't necessarily need to calculate the individual eigenvalues. Instead note that

1. The trace (sum of diagonal elements) of the matrix is equal to the sum of eigenvalues

2. The determinant of the matrix is equal to the product of the eigenvalues

...and we only need to know the sum and product of two numbers (the eigenvalues) to see if they are both negative!