Package: pyross
PyRoss: inference, forecasts, and optimised control for epidemiological models in PythonAbout|Documentation|Examples|Installation|Publications|AboutPyRossis a numerical library that offers an integrated platform forinference,forecastsandnon-pharmaceutical interventionsin structured epidemiological compartment models.Compartment modelsof arbitrary complexity can beuser-definedthrough Python dictionaries. The most common epidemiological models, and several less common ones, come pre-defined with the library. Models can includestagesto allow for non-exponentially distributed compartmental residence times. Currently,pre-defined modelsinclude ones with multiple disease states (exposed, asymptomatic, symptomatic, etc) and may be further divided by age, and by objective medical states (hospitalized, in ICU, etc). The compartment framework supports models fordisease surveillanceandquarantineand a variety of other processes of epidemiological relevance.Generative processescan be formulatedstochastically(as Markov population processes) ordeterministically(as systems of differential equations). Population processes are sampled exactly by the Doob-Gillespie algorithm or approximately by the tau-leaping algorithm while differential equations are integrated by both fixed and adaptive time-stepping. Ahybrid algorithmtransits dynamically between these  depending on the magnitude of the compartmental fluctuations.Bayesian inferenceon pre-defined or user-defined models is performed using model-adaptedGaussian processesderived fromfunctional limit theoremsfor Markov  population process. Generative models are fitted to data through the surveillance model allowing for possibilyunobservedcompartments. TheMAPestimates of parameters and their standard errors can be obtained rapidly by optimising, obviating the need for expensive Markov chain Monte Carlo. This enables the fast evaluation of themodel evidence, through which competing models may beobjectively comparedand their forecasts combined byBayesian model averaging. Forecasts of disease progression, then, can befully Bayesian, convolving uncertainties in data, parameters and models. The sensitivity of these forecasts is estimated through theFisher information matrix.Non-pharmaceutical interventionsare implemented as modifications of thecontact structuresof the model.Optimised controlof these structures, givencost functions, is possible.PyRossGeois a companion library that supportsspatially resolved compartment modelswith explicitcommuting networks.The libraries are named afterSir Ronald Ross, doctor, mathematician and poet. In 1898 he made "the great discovery" in his laboratory in Calcutta "that malaria is conveyed by the bite of a mosquito".  He won the Nobel Prize in 1902 and laid the foundations of the mathematical modelling of infectious diseases.The library was developed as a part ofThe Rapid Assistance in Modelling the Pandemic (RAMP)taskforce at theUniversity of Cambridge. In alphabetical order, the authors are:Ronojoy Adhikari,Austen Bolitho,Erik Brorson,Fernando Caballero,Michael Cates,Jakub Dolezal,Tim Ekeh,Jules Guioth,Robert Jack,Julian Kappler,Lukas Kikuchi,Hideki Kobayashi,Irene Li,Joseph Peterson,Patrick Pietzonka,Benjamin Remez,Paul Rohrbach,Rajesh Singh,
andGünther Turk.
PyRoss development was also partially supported by aMicrosoft Research Awardfor "Building an open platform for pandemic modelling".Please read thePyRoss paperandPyRoss Wikibefore you use PyRoss for your research.Open an issue, in preference to emailing us with queries. Join ourSlack channelfor discussion. Please follow theContributor Covenantin all PyRoss fora. Thank you!InstallationYou can take PyRoss for a spinwithout installation:. Please be patient whileBinderloads.From a checkout of  PyRoss GitHub repositoryThis is the recommended way as it downloads a whole suite of examples along with the package.Install PyRoss and an extended list of dependencies using>>gitclonehttps://github.com/rajeshrinet/pyross.git
>>cdpyross
>>pipinstall-rrequirements.txt
>>pythonsetup.pyinstallInstall PyRoss and an extended list of dependencies, viaAnaconda, in anenvironmentnamedpyross:>>gitclonehttps://github.com/rajeshrinet/pyross.git
>>cdpyross
>>makeenv
>>condaactivatepyross
>>makeVia pipInstall the latestPyPIversion>>pipinstallpyrossTestingShort test of initialisation and running>>maketestLong test of all example notebooks. Optionally can specify path and recursion
to test a certain subset of notebooks>>makenbtest-epath=examples/deterministic/ExamplesPyRoss has model-agnostic, formulation-agnostic intuitive interface. Once a model is instantiated, stochastic, deterministic and hybrid simulations can be performed through the same interface. The example below shows how to set up a deterministic SIR simulation with three age-groups.# SIR with three age-groups (M=3)importnumpyasnpimportpyrossimportmatplotlib.pyplotaspltmodel_spec={"classes":["S","I"],"S":{"infection":[["I","S","-beta"]]},## the I class passes infection to S class"I":{"linear":[["I","-gamma"]],## this is recovery process for I class"infection":[["I","S","beta"]]}## the recovered class R is internally determined by number conservation}parameters={'beta':0.1,'gamma':0.1,}M=3;Ni=1000*np.ones(M);N=np.sum(Ni)# Initial conditions as an arrayx0=np.array([980,980,980,# S20,20,20,# I])# Or initial conditions as a dictionaryx0={'S':[n-20forninNi],'I':[20,20,20]}CM=np.array([[1,0.5,0.1],[0.5,1,0.5],[0.1,0.5,1]],dtype=float)defcontactMatrix(t):returnCM# duration of simulation and data fileTf=160;Nf=Tf+1;det_model=pyross.deterministic.Model(model_spec,parameters,M,Ni)# simulate modeldata=det_model.simulate(x0,contactMatrix,Tf,Nf)# plot the data and obtain the epidemic curveS=np.sum(det_model.model_class_data('S',data),axis=1)I=np.sum(det_model.model_class_data('I',data),axis=1)R=np.sum(det_model.model_class_data('R',data),axis=1)t=data['t']fig=plt.figure(num=None,figsize=(10,8),dpi=80,facecolor='w',edgecolor='k')plt.rcParams.update({'font.size':22})plt.fill_between(t,0,S/N,color="#348ABD",alpha=0.3)plt.plot(t,S,'-',color="#348ABD",label='$S$',lw=4)plt.fill_between(t,0,I/N,color='#A60628',alpha=0.3)plt.plot(t,I,'-',color='#A60628',label='$I$',lw=4)plt.fill_between(t,0,R/N,color="dimgrey",alpha=0.3)plt.plot(t,R,'-',color="dimgrey",label='$R$',lw=4)plt.legend(fontsize=26);plt.grid()plt.autoscale(enable=True,axis='x',tight=True)plt.ylabel('Compartment value')plt.xlabel('Days');Read more in theexamplesfolders.PublicationsBayesian inference across multiple models suggests a strong increase in lethality of COVID-19 in late 2020 in the UK. Patrick Pietzonka, Erik Brorson, William Bankes, Michael E. Cates, Robert L. Jack, R. AdhikarimedRxiv, 2021Efficient Bayesian inference of fully stochastic epidemiological models with applications to COVID-19. Yuting I. Li, Günther Turk, Paul B. Rohrbach, Patrick Pietzonka, Julian Kappler, Rajesh Singh, Jakub Dolezal, Timothy Ekeh, Lukas Kikuchi, Joseph D. Peterson, Hideki Kobayashi, Michael E. Cates, R. Adhikari, Robert L. Jack,arXiv:2010.11783, 2020|ResearchGateEfficient and flexible methods for time since infection models, Joseph D. Peterson, R. Adhikari,arXiv:2010.10955, 2020Inference, prediction and optimization of non-pharmaceutical interventions using compartment models: the PyRoss library. R. Adhikari, Austen Bolitho, Fernando Caballero, Michael E. Cates,
Jakub Dolezal, Timothy Ekeh, Jules Guioth, Robert L. Jack, Julian Kappler,
Lukas Kikuchi, Hideki Kobayashi, Yuting I. Li, Joseph D. Peterson, Patrick
Pietzonka, Benjamin Remez, Paul B. Rohrbach, Rajesh Singh, and Günther Turk,arXiv:2005.09625, 2020|ResearchGate.Age-structured impact of social distancing on the COVID-19 epidemic in India. Rajesh Singh and R. Adhikari,arXiv:2003.12055, 2020|ResearchGate.LicenseWe believe that openness and sharing improves the practice of science and increases the reach of its benefits. This code is released under theMIT license. Our choice is guided by the excellent article onLicensing for the scientist-programmer.