**Overview: Stochastic Simulations**

Found at edx.org (week 3 and 4), this is one of the first stochastic simulations I’ve worked on. The goal is to model virus growth in a patient over time, understand the behavior of virus growth and its interaction with time and a number of prescriptions.

We use a stochastic simulation in this case because we understand the microscopic behavior of each virus (reproduction probabilities, clearance probabilities) but want to extrapolate to a population of viruses.

There are two major classes: Patients, and Viruses. Each “Patient” instance holds a list of “Virus” instances that have various probabilities assigned to things like: mutation probability, reproduction probability, clearance probability. Depending on the random numbers generated the different outcomes (whether to clear, whether to reproduce, whether to mutate) will be enacted.

Example:

Each virus has is a “Clearance Probability”. This is the probability that a virus will die at a given iteration. For these tests the “Clearance Probability was 5%. We generate a random number in python with

In [1]: import random

In [8]: random.random() <= .05

Out[8]: False

In this example, since the outcome is false the virus particle would not reproduce.

For more reading related to montecarlo simulations: https://docs.python.org/2/library/random.html, and https://en.wikipedia.org/wiki/Stochastic_simulation

We use a stochastic simulation in this case because we understand the microscopic behavior of each virus (reproduction probabilities, clearance probabilities) but want to extrapolate to a population of viruses.

There are two major classes: Patients, and Viruses. Each “Patient” instance holds a list of “Virus” instances that have various probabilities assigned to things like: mutation probability, reproduction probability, clearance probability. Depending on the random numbers generated the different outcomes (whether to clear, whether to reproduce, whether to mutate) will be enacted.

Example:

Each virus has is a “Clearance Probability”. This is the probability that a virus will die at a given iteration. For these tests the “Clearance Probability was 5%. We generate a random number in python with

In [1]: import random

In [8]: random.random() <= .05

Out[8]: False

In this example, since the outcome is false the virus particle would not reproduce.

For more reading related to montecarlo simulations: https://docs.python.org/2/library/random.html, and https://en.wikipedia.org/wiki/Stochastic_simulation

## Simulation Comparison: No Treatment, 1 Drug, and 2 Drugs at various times

Starting Virus Population = 100 Max Virus Pop (used for density calculations) = 1000 Max Birth Prob = 10% Clearance Probability = 5% Starting Drug Resistances = None Mutation Probability = 0.5% Number of Patients = 100 | |

## Simulation 1: No Drugs

## Simulation 2: Drug @ T = 0 "Ideal Case"

Receiving Treatment at T = 0 results in 0 mutations and therefore no resistances developed. This is obviously ideal and unrealistic.

Since the default starting resistance to each drug is "false" at T = 0 , and since viruses aren't allowed to reproduce in the presence of a drug they're not resistant to, you can see there is no reproduction and all viruses clear by roughly T = ~70. With a final population of 0 in all patients.

Since the default starting resistance to each drug is "false" at T = 0 , and since viruses aren't allowed to reproduce in the presence of a drug they're not resistant to, you can see there is no reproduction and all viruses clear by roughly T = ~70. With a final population of 0 in all patients.

## Simulation 3: Drug @ T = 75

## Simulation 4: Drug @ T = 150

## Simulation 5: Drug @ T = 300

For Prescriptions administered at T = 75, T = 150, and T = 300, there is a marginal difference in number of patients cured (virus pop < 50). Although, due to T = 300 not being at a steady state we can't include that in our comparison.

## Simulation 6: 1st Drug @ T = 0 2nd Drug @ T = 150

As expected, this looks exactly like the test with one drug at T = 0. If the patient is cured before T = 100 then a drug at T = 150 should show no difference on either of the histogram or the time series charts.

## Simulation 7: 1st Drug @ T = 75 2nd Drug @ T = 150

## Simulation 8: 1st Drug @ T = 150 2nd Drug @ T = 150

For sim 7: T = 75 T = 150 and Sim 8: two drugs at T = 150 , the results were surprising. I reran these a couple of times to see that I just hadn't mislabeled them.

What I expected was for the Sim 7 to have more cured patients since any treatment at all was started earlier. However, Sim 8 had more cures even though both drugs were administered later. I think I have an explanation.

When the patient receives a Drug 1 at T = 75 the virus population hasn't quite hit the "steady state" ceiling that slows reproduction. So viruses that haven't reached their steady state limit yet have more opportunities to reproduce, and therefore more opportunities for resistance mutation.

For Sim 8, the drugs are administered at the same time, and at a steady state virus population which means two things: There are fewer opportunities for resistance mutation, and the mutations have two drugs to mutate resistance to simultaneously giving them an effective mutation probability of .25% ( .5% * .5%) at time of drug administration. More analysis would be necessary to characterize this difference in more detail.

These two simulations also highlight a key difference in the "Time Window of Adminstration" that results in a cure (virus population < 50).

What I expected was for the Sim 7 to have more cured patients since any treatment at all was started earlier. However, Sim 8 had more cures even though both drugs were administered later. I think I have an explanation.

When the patient receives a Drug 1 at T = 75 the virus population hasn't quite hit the "steady state" ceiling that slows reproduction. So viruses that haven't reached their steady state limit yet have more opportunities to reproduce, and therefore more opportunities for resistance mutation.

For Sim 8, the drugs are administered at the same time, and at a steady state virus population which means two things: There are fewer opportunities for resistance mutation, and the mutations have two drugs to mutate resistance to simultaneously giving them an effective mutation probability of .25% ( .5% * .5%) at time of drug administration. More analysis would be necessary to characterize this difference in more detail.

These two simulations also highlight a key difference in the "Time Window of Adminstration" that results in a cure (virus population < 50).

## Simulation 9: 1st Drug @ T = 150 2nd Drug @ T = 300

Sim 9 is kind of funny.

The drugs are spaced far enough apart that the viruses can mutate against each one independently enough to return to a steady state close to what would have happened if they had taken no drugs at all.

The drugs are spaced far enough apart that the viruses can mutate against each one independently enough to return to a steady state close to what would have happened if they had taken no drugs at all.

## Conclusion

For the realistic cases (No Drug at T = 0) it appears that taking two drugs simultaneously instead of one or two at different times allows for a larger window of administration (i.e. not requiring you to catch the virus at an early enough time) and higher likelihood of cure.

Simulation 3 - 5 and 9 resistant populations seem to show that it is actually worse to take 1 drug "not early enough" or to take 1 or 2 drugs too far apart. Doing so would result in developing mutated viruses that no longer respond to either of the drugs administered.

Simulation 3 - 5 and 9 resistant populations seem to show that it is actually worse to take 1 drug "not early enough" or to take 1 or 2 drugs too far apart. Doing so would result in developing mutated viruses that no longer respond to either of the drugs administered.

## Thoughts

This simulation doesn't consider things like:

which helps me understand how this is a whole entire niche industry in itself. (https://en.wikipedia.org/wiki/Bioinformatics)

I can also see the use of very powerful computers for this kind of analysis since each simulation run here took roughly 2 minutes running on a MacBook 2.6 gHz 8 GB RAM. Learning to run these kinds of simulations in the cloud is something I'm planning on the horizon.

Tools used:

Source: https://github.com/Ryanglambert/virus_simulation

- side-effects
- drug to drug interactions
- patient compliance
- varying strength of drugs
- many more

which helps me understand how this is a whole entire niche industry in itself. (https://en.wikipedia.org/wiki/Bioinformatics)

I can also see the use of very powerful computers for this kind of analysis since each simulation run here took roughly 2 minutes running on a MacBook 2.6 gHz 8 GB RAM. Learning to run these kinds of simulations in the cloud is something I'm planning on the horizon.

Tools used:

*matplotlib, numpy, Python*Source: https://github.com/Ryanglambert/virus_simulation