Part A: Probabilities
Part A: Probabilities
Part A
8.0 points possible (graded)
PART A: PROBABILITIES
This part of the problem set involves some pencil-and-paper exercises. It will
help you practice and understand simple probability and statistics.
Let's say Alvin will catch the flu with probability of 1/10 during any given month.
Let's also assume that Alvin can catch the flu only once per month, and that if he
has caught the flu, the flu virus will die by the end of the month. What is the
probability of the following events?
Answer each question in reduced fraction form - eg 1/5 instead of 2/10.
1.
2.
He catches the flu in September and then again in November, but not in
October.
unanswered
3.
He catches the flu exactly once in the three months from September
through November.
unanswered
4.
He catches the flu in two or more of the three months from September
through November.
unanswered
Part A
INTRODUCTION
In this problem set, using Python and Pylab, you will design and implement a
stochastic simulation of patient and virus population dynamics, and reach
conclusions about treatment regimens based on the simulation results.
GETTING STARTED
Download: ProblemSet3.zip, a skeleton file for Part B.
In reality, diseases are caused by viruses and have to be treated with medicine,
so in the remainder of this problem set, we'll be looking at a detailed simulation
of the spread of a virus within a person. We've provided you with skeleton code
in ps3b.py.
We start with a trivial model of the virus population - the patient does not take
any drugs and the viruses do not acquire resistance to drugs. We simply model
the virus population inside a patient as if it were left untreated.
SIMPLEVIRUS CLASS
To implement this model, you will need to fill in the SimpleVirus class, which
maintains the state of a single virus particle. You will implement the methods
__init__, getMaxBirthProb, getClearProb,doesClear, and reproduce
according to the specifications. Use random.random() for generating random
numbers to ensure that your results are consistent with ours.
Hint: random seed
During debugging, you might want to use random.seed(0) so that your results
are reproducible.
The reproduce method in SimpleVirus should produce an offspring by
returning a new instance of SimpleVirus with probability:
self.maxBirthProb * (1 - popDensity). This method raises a
NoChildException if the virus particle does not reproduce. For a reminder on
raising execptions, review the Python docs.
self.maxBirthProb is the birth rate under optimal conditions (the virus
population is negligible relative to the available host cells so there is ample
nourishment available). popDensity is defined as the ratio of the current virus
population to the maximum virus population for a patient and should be
calculated in the update method of the Patient class.
PATIENT CLASS
You will also need to implement the Patient class, which maintains the state of
a virus population associated with a patient.
The update method in the Patient class is the inner loop of the simulation. It
modifies the state of the virus population for a single time step and returns the
total virus population at the end of the time step. At every time step of the
simulation, each virus particle has a fixed probability of being cleared
(eliminated from the patient's body). If the virus particle is not cleared, it is
considered for reproduction. The virus population should never exceed maxPop;
if you utilize the population density correctly, you shouldn't need to provide an
explicit check for this.
Be very wary about mutating an object while iterating over its elements. It is best
to avoid this entirely (consider introducing additional "helper" variables). See the
6.00.2x Style Guide for more information.
Note that the mapping between time steps and actual time will vary depending
on the type of virus being considered, but for this problem set, think of a time
step as a simulated hour of time.
About the grader: When defining a Patient class member variable to store the
viruses list representing the virus population, please use the name
self.viruses in order for your code to be compatible with the grader and to
pass one of the tests.
Part B: Problem 2
Click to add Bookmark this page
Compared to the previous problem sets, testing your simulation code is more
challenging, because the behavior of the code is stochastic, and the expected
output is not exactly known. How do you know whether your plots are correct or
not? One way to test this is to run the simulation with extreme input values (i.e.
initialization parameters), and check that the output matches your intuition. For
example, if maxBirthProb is set to 0.99 instead of 0.1, then you would expect
that the virus population rapidly increases over a short period of time. Similarly,
if you run your simulation with clearProb = 0.99 and maxBirthProb = 0.1,
then you should see the virus population quickly decreasing within a small
number of steps. You can also try to vary the input values, and check whether
the output plots change as you expect. For example, if you run multiple
simuation runs, each time increasing maxBirthProb, the curves in the
successive plots should show an "upward" trend, since the virus will reproduce
faster with a higher maxBirthProb.
For further testing, we have provided the .pyc (compiled Python) files for the
completed Patient and SimpleVirus classes (and for Problem 5, the
ResistantVirus and TreatedPatient classes) that you can use to confirm
that your code is generating the correct results during simulation.
If you comment out your versions of these classes in ps3b.py, and add the
following import statements to the top of your file, you can run the simulation
using our pre-compiled implementation of these classes to make sure you are
obtaining the correct results. This is a good way to test if you've implemented
these classes correctly. Make sure to comment out the import statement and
uncomment your implementations before moving to Problem 4.
For Python 3.5: from ps3b_precompiled_35 import *
Part B: Problem 3
Click to add Bookmark this page
RESISTANTVIRUS CLASS
In order to model this effect, we introduce a subclass of SimpleVirus called
ResistantVirus. ResistantVirus maintains the state of a virus particle's
drug resistances, and accounts for the inheritance of drug resistance traits to
offspring. Implement the ResistantVirus class.
Part B: Problem 4
Click to add Bookmark this page
We also need a representation for a patient that accounts for the use of drug
treatments and manages a collection of ResistantVirus instances. For this, we
introduce the TreatedPatient class, which is a subclass of Patient.
TreatedPatient must make use of the new methods in ResistantVirus and
maintain the list of drugs that are administered to the patient.
Drugs are given to the patient using the TreatedPatient class's
addPrescription() method. What happens when a drug is introduced? The
drugs we consider do not directly kill virus particles lacking resistance to
the drug, but prevent those virus particles from reproducing (much like actual
drugs used to treat HIV). Virus particles with resistance to the drug continue to
reproduce normally. Implement the TreatedPatient class.
Hint: reproduce function child resistances
If you are really unsure about how to think about what each child resistances
should be changed to, here is a different approach. If the probability mutProb is
successful, the child resistance switches. Otherwise, the child resistance stays
the same as the parent resistance.
Part B: Problem 5
Click to add Bookmark this page