0:59

The particular kind of model we use will be SIR.

Â And it takes a little while to explain it and then we still we still also have to

Â talk little bit about how the Julia code works but then we can plug the results.

Â So SRI, the name of the model stands for

Â three kinds of people involved in the disease.

Â The first kind are the susceptibles.

Â These are people who might still get ill.

Â Initially there are S at node, that time equals zero,

Â but then S time goes on, this changes.

Â And so we write S(t) for

Â the number of people who are susceptible to the disease at time t.

Â At any given time as the disease progresses,

Â there maybe some infected people, which we symbolize with i.

Â And of course initially S(t) equal zero.

Â There are some people who are ill because otherwise the epidemic would not start.

Â And then finally people previously infected but

Â no longer infected called removed.

Â We assume that they remain non infectious from that time onward.

Â So this is not a disease like flu where people can get re-infected all the time.

Â Unfortunately, remove does not mean that they have recovered.

Â The illness isn't a joke.

Â So it's important to notice that S, I and R do not have to be whole numbers.

Â All we want is for S, I, and R to be close to what is observed.

Â And by close we just mean in some few percent.

Â If we can get a model that gets within a few percent of the values

Â that are observed we have done brilliantly well.

Â Epidemiology is not an exact science.

Â Getting the numbers within a few percent unfortunately is only possible with

Â hindsight usually.

Â We will do this with the SIR model for our able epidemic.

Â Okay so let's get the equations.

Â What we do is that we assume that time goes into discrete steps.

Â And the distance from one time to another,

Â the duration of time form one step to the next will always be dt.

Â That means that T sub I which is the time of the I steps is t sub zero.

Â Which is zero, plus I times dt, so

Â t sub I is just I times dt.

Â So code from t sub I to t sub I plus one,

Â we want to compute values for S of t I plus one.

Â I at D sub I plus one and RD sub I plus one.

Â To predict these we will only use the values at the previous time step so

Â that's s and t sub I and S t sub I and R t sub I plus one.

Â And they are what we use, so we need a formula to compute S and

Â t sub I plus one using these.

Â And similarly for I.

Â To compute I t sub I plus one using those three.

Â And so our model is a set of three equations, and they all have this form.

Â The new value is the old value, plus the gains, minus the losses.

Â So that's a very obvious form in which models are derived.

Â And all of the effort of modeling goes into working out how you might compute

Â at every time step gains and the losses.

Â And for susceptibles,

Â of course, the only thing that can happen is that a susceptible becomes infected.

Â The simplest SIR models use the law of mass action.

Â And what it says is that all susceptibles are exactly equivalent and

Â they all have an equal chance of meeting an infected.

Â Similarly all infecteds are exactly equal,

Â and they all have an exactly equal chance of meeting a susceptible.

Â And so the number of meetings between infected and

Â susceptibles is just proportional to the product S times I.

Â That's the goal of mass.

Â Now the number of infections that will result from meetings is not equal to SMI.

Â It's not equal equal to S times I.

Â It's just proportional to it.

Â We will say that this is a constant,

Â that the probability that it's acceptable is infected when

Â 4:53

an infected person is exactly the same for all people at all times.

Â And so then, lambda SI is the rate at which susceptibles become infected.

Â This is a rate per day, because we are using days as our time variable.

Â And so the actual loss over a time step dt in terms of day.

Â So say dt is one tenth of a day.

Â Then actually only a tenth of lambda SI should get infected.

Â And so lambda SI times dt is the rate at which

Â the lambda SI times dt is the number of new infections that have generated.

Â During this time step dt.

Â The new value is the old value minus the losses.

Â Now we go on to infected people.

Â So infected people stop being infected by being removed or being recovered.

Â And again we say that all infected people have the same chance of recovery

Â at every day.

Â So some constant fraction is removed every day.

Â But this is the fraction gamma.

Â And so therefore gamma I is the number of infecteds that get removed per day.

Â And so gamma I dt, that's the loss of infecteds.

Â The kind of infecteds we already know, because every bit of

Â population that gets lost from susceptible gets added to infected.

Â And so here is the new infecteds, the previous level of infected

Â plus all the ones that are newly infected minus the ones that are now being removed.

Â Because it's an SIR model, once you're removed you stay there, so

Â all that happens is that there's a gain term.

Â And this gain term is of course the same as the last term from the infecteds, and

Â so that's our third equation.

Â And our SIR model is just three equations for S, I, and R.

Â 6:43

So now we go on to writing the Julia code.

Â What I choose to do is to write a single function, which takes S, I and

Â R all at once, and gives back the new values of S, I and R all at once.

Â So these functions of course have to know the values of the parameters.

Â And the way we're going to pause these values to Julia is not to write them

Â as part of the argument of the function.

Â But just to declare them at the level where the function is created,

Â and then the function will see them on the inside of the function.

Â This is quite surprising.

Â Many experienced programmers would not expect to see this.

Â The way it works is the following.

Â So, if we assign to the variable b the value a, that is no, I'll be here.

Â Then the function f of x is created so when I run this, that executes.

Â Then this line executes and it creates a function x.

Â Now, this point the value of b.

Â Is actually known.

Â So when we run this, we get 56 as the outcome.

Â If we change that to six, of course that becomes 48.

Â But if we change that to four, then that becomes 24.

Â So makes our function simple to write.

Â We have a population vector with three elements.

Â One, two and three and they will be the susceptibles, the infected, and

Â the removeds.

Â And then they'll create the new s is the old susceptibles minus lambda

Â times the susceptibles times the infected times dt.

Â 8:54

Now we compiles and we set our parameter dt, which is the time state length.

Â And lambda and

Â gamma which are the epidemic parameters which specify some sort of input argument.

Â And recall that this is a way of using one assignment to set three different values.

Â So we can set S, I, and R.

Â S becomes 1000, I ten, R becomes 20.

Â Notice that only 1000 is a float, the other two are integers.

Â In fact, what will happen is that Julia will convert ten and 20 to integers.

Â It's not the best form of programming, but Julia forgives us that, and

Â that's part of why it's easy and quick to write you the app code.

Â If we want to optimize the running of the Julia code then,

Â we might find in the end that, this is one of the reasons why our code is running

Â slower than we might wanted, right.

Â So, what does it do?

Â It gives us an output of 975,

Â this is susceptible as minor lambda times infected.

Â So, the number ten that become 10,000

Â then gam is one tenth that means 1000.

Â Okay so the function works and so we can go back to the top and

Â now we discuss how we look through all the times.

Â We want that function to run from start time to the end time and

Â that can't be infinite so we define an end time t final.

Â We will use 610 day to fit data from Wikipedia.

Â So what that means is that there are n steps.

Â Tf divided by dt, but now you've gotta watch out.

Â Computer arithmetic is not infinitely precise.

Â So if we compute n times dt, so we've defined n this way.

Â And now we calculate Tf as n times dt,

Â this should be exactly true mathematically, algebraically.

Â But, in a computer we cannot be sure that this is the case.

Â So if we wanted to, we tested this is an equality might not work exactly.

Â So what I would like to do instead is to use time as a variable,

Â and to keep explicit track of this number I.

Â Then I know exactly how many steps I want to take, at the end of it,

Â the time I reach might not be exact the Tf that I started with.

Â But it will be extremely close to it.

Â Actually, the take home message is that you should not rely on exact equality,

Â even if you can reasonably expect it.

Â Computer code that relies on exact equality is much more prone to error,

Â and it really requires professional programmers to use.

Â We know exactly how many values we are going to need,

Â then we can create an array to hold all of them.

Â If we take n steps, we need n plus one, that is of course we need a value for

Â T equals zero and then the values n steps on from there.

Â So total number of n plus one values.

Â So here's the concept code, now this code doesn't actually do anything.

Â The reason it doesn't do anything is that I only have comment lines inside the loop.

Â This is just to say, okay final 610 days, so

Â the n steps is an integer, that's why I call the round function.

Â And round with type integer means that it's going to round it to integer types.

Â So that gives me an integer number of steps.

Â And in the results I will hold in a variable, three columns n plus one rows.

Â And also a vector of times, which will just be n plus one float values.

Â We need to specify our initial values and our initial result values.

Â Right.

Â Now, we are ready to run the model.

Â So I just cut and paste this code here, initializing everything.

Â Set all the values we need.

Â We need to set lambda, we need to set gam, we need to set dt, we need to set tfinal,

Â we need to set S not, we need to set I not, we need to set R not.

Â None of these can be taken for granted.

Â And then we initialize.

Â We calculate the number of steps.

Â We initialize a vect.

Â We initialize on the right, or results and for the time vector,

Â we initialize this array.

Â So we've created the array here and then we initialize its first row.

Â We're not going to compute this row.

Â We're also not going to compute this time.

Â Having done that, we can now just take n steps,

Â now if we want to take a step so we have one.

Â The next value is going to go to two.

Â And then if the step is two the next value goes to three and

Â in the end we end up with the n plus one steps that we put in our array.

Â