Answered step by step
Verified Expert Solution
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 which is situated below the code.
parameterisebasicmodel
solve
We also provide a variable data, that provides noisy data on the predator and prey populations taken by a biologist...
data: contains the timepoints measured in years over which the data was taken
data: represents the estimated prey population measured in hundreds, ie data means estimated animals at timepoint over these timepoints
data: represents the predator population over these timepoints, measured in tens. times MatrixFloat:
solvef::Function, tspan, x::Vector
Numerically solves the ODE xt fxt t
on the timespan whose startend points are enclosed in tspan. Recall that x denotes the time derivative of xt ie dxdt
Example
solvef
solves between t and t using initial conditions x e How would the basic model change if we instead measured predators and prey in units of a single animal?
Hint: take and
Can you rewrite the differential equation in terms of these two variables instead, using the chain rule?
f Build a function simulationp It must take in a vector of parameters eg simulation It must output a times matrix holding the solution of the differential equation: ie the populations of prey st column and predators nd column over the timepoints rangestep The initial conditions can be
g Build a function msep It must take in a vector of parameters eg mse 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
Run it starting from the initial parameter set p You have succeeded if you can use this algorithm to find a new parameter set pnew abcd that reduces the mean squared error by a factor of as compared to p Do two plots:
A comparison of the data and the simulation at p
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 Are these parameter values unique? ie could you find another set of parameter values that also perfectly fit the data?
gradient
gradientf::Function, x::Number
Extracts the numerical gradient jacobianmultidimensional 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, eg f This vector is of length n where n is any number.
f must return a scalar output ie a number, not a vector
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started