Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We now provide you with code for simulating the model above ( see below ) . This consists of two functions, which you can inspect

We now provide you with code for simulating the model above (see below). This consists of two functions, which you can inspect below. All can be seen in the live docs. Read them to help answer the remainder of question 5, which is situated below the code.
parameterise_basic_model
solve
We also provide a variable data, that provides noisy data on the predator and prey populations taken by a biologist...
data[:,1] contains the timepoints (measured in years) over which the data was taken
data[:,2] represents the estimated prey population (measured in hundreds, i.e. data[2,2]=3 means 300 estimated animals at timepoint 2) over these timepoints
data[:,3] represents the predator population over these timepoints, measured in tens. 1001\times 3 Matrix{Float64}:
0.00.8253710.820219
0.011.251260.880475
0.021.074471.19519
0.031.145951.36702
0.040.740690.820193
0.050.8032850.802094
0.061.042340.996427
9.950.9602512.89815
9.960.9586672.57985
9.971.148992.78071
9.981.096213.08052
9.990.6355452.79623
10.00.8571592.38937. solve(f::Function, tspan, x0::Vector)
Numerically solves the ODE x(t)= f(x(t), t)
on the timespan whose start/end points are enclosed in tspan. Recall that x denotes the time derivative of x(t), i.e. dx/dt.
Example
solve(f,(0,10),[1,0])
solves between t=0 and t=10, using initial conditions x0=[1,0]. e) How would the basic model change if we instead measured predators and prey in units of a single animal?
Hint: take =Z100 and =O10.
Can you rewrite the differential equation in terms of these two variables instead, using the chain rule?
f) Build a function simulation(p). It must take in a vector of 4 parameters (e.g. simulation([1,2,3,4]). It must output a 1001\times 2 matrix holding the solution of the differential equation: i.e. the populations of prey (1st column) and predators (2nd column) over the timepoints range(0,10,step=0.01). The initial conditions can be [1,1].
g) Build a function mse(p). It must take in a vector of 4 parameters (e.g. mse[1,2,3,4]). It must output the mean squared error between the model simulation, and the data provided in the variable data. The mean squared error is the sum of the squared residuals between the data and the simulation over all timepoints, divided by the number of timepoints.
h) Use the gradient function provided below (or not if you prefer!) to implement a gradient descent algorithm, with stepsize 0.01
. Run it, starting from the initial parameter set p0=[1,4,1,4]. You have succeeded if you can use this algorithm to find a new parameter set pnew =[a,b,c,d] that reduces the mean squared error by a factor of 3, as compared to p0. Do two plots:
A comparison of the data and the simulation at p0
A comparison of the data and the simulation at pend.
Hint: to overlay two plots you can use the code:
p = plot()
plot!(p,...)
scatter!(p,...)
where ... are the arguments you would usually provide to plot or scatter
If the algorithm doesn't effectively fit the data, why do you think this might be the case?
i) Suppose you found parameter values that perfectly fitted the data (mse =0). Are these parameter values unique? i.e., could you find another set of parameter values that also perfectly fit the data?
gradient
gradient(f::Function, x::Number)
Extracts the numerical gradient (/jacobian/multidimensional derivative) of a function f, evaluated at the vector x. gradient uses the finite difference approximation
Conditions on f
f must accept a vector x of inputs, e.g. f([1,2,3]. This vector is of length n, where n is any number.
f must return a scalar output (i.e. a number, not a vector)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions