import numpy import random import pylab class SimpleVirus(object): """ Representation of a simple virus (does not model drug effects/resistance). """ def __init__(self, maxBirthProb, clearProb): """ Initialize a SimpleVirus instance, saves all parameters as attributes of the instance. maxBirthProb: Maximum reproduction probability (a float between 0-1) clearProb: Maximum clearance probability (a float between 0-1). """ self.maxBirthProb = maxBirthProb self.clearProb = clearProb def getMaxBirthProb(self): """ Returns the max birth probability. """ return self.maxBirthProb # TODO def getClearProb(self): """ Returns the clear probability. """ return self.clearProb # TODO def doesClear(self): """ Stochastically determines whether this virus particle is cleared from the patient's body at a time step. returns: True with probability self.getClearProb and otherwise returns False. """ return self.clearProb > random.random() # TODO def reproduce(self, popDensity): """ Stochastically determines whether this virus particle reproduces at a time step. Called by the update() method in the Patient and TreatedPatient classes. The virus particle reproduces with probability self.maxBirthProb * (1 - popDensity). If this virus particle reproduces, then reproduce() creates and returns the instance of the offspring SimpleVirus (which has the same maxBirthProb and clearProb values as its parent). popDensity: the population density (a float), defined as the current virus population divided by the maximum population. returns: a new instance of the SimpleVirus class representing the offspring of this virus particle. The child should have the same maxBirthProb and clearProb values as this virus. Raises a NoChildException if this virus particle does not reproduce. """ repoProbability = self.maxBirthProb * (1 - popDensity) if(random.random() > repoProbability): raise NoChildException('In reproduce()') return SimpleVirus(self.maxBirthProb, self.clearProb) # TODO
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question