代写COMPSCI369、代做Python编程设计
COMPSCI369 - S1 2024
Assignment 3
Due date: See Canvas
Instructions
This assignment is worth 7.5% of the final grade. It is marked out of 75 points.
Provide a solution as a Python notebook and html with output. Your solution should include well
documented code with the calls to reproduce your results.
Include markdown cells with explanation of the results for each question.
Submit the ipynb and html to Canvas:
• the .ipynb file with outputs from the executed code
• a .html version of the notebook with all outputs of executed code showing. (To get this
format, export from the notebook viewer or use nbconvert.)
Within the notebook, set the random seed to some integer of your choosing (using random.seed)
so that the marker can recreate the same output that you get. You can reset the seed before each
question if you like.
Question 1: Simulating random variables and exploring relationships between distributions (20 Points)
(a) Using the inversion sampling technique described in Section 9.2 of the workbook, write a method rand exp that takes a rate parameter λ as input and
produces as output an exponentially distributed random variable with rate parameter λ. Use random.random() to generate uniform random numbers. (4
marks)
(b) Demonstrate your rand exp is correct by comparing the mean and variance
of the output to theoretical values, and also by comparing the output of your
method to a library method. (4 marks)
(c) Use rand exp to write a method rand poiss that takes a parameter λ as input
and produces as output a Poisson distributed random variable with parameter
λ. (4 marks)
(d) Use rand exp to write a method rand gamma that takes an integer parameter
k and rate parameter θ as input and produces as output a gamma distributed
random variable with parameters k and θ. (4 marks)
(e) Explain why your rand gamma method lacks the generality you would typically
want for simulating gamma distributed random variables. (4 marks)
1
Question 2: Simulating outbreaks (55 Points)
A standard model in epidemiology is the SIR model of infectious disease spread. It
has a population of N hosts being divided into 3 compartments, so is known as a
compartmental model:
• the S compartment of those who are susceptible to the disease
• the I compartment of those who are infectious with the disease
• the R compartment of those who are recovered from the disease and now immune (or, more generally, those who are removed from the epidemic through
recovery with immunity, or isolation, or death, etc).
We assume that S + I + R = N.
The model can be deterministic or stochastic. We consider the stochastic version
here. Times between all events are exponentially distributed with the following rates
which depend on the current state of the outbreak, assumed to be (S, I, R):
• the rate of transmissions is βSI/N and the new state is (S − 1, I + 1, R), and
• the rate of recoveries is γI and the new state is (S, I − 1, R + 1).
You can use any functions from the random module that you like for this question.
Probably the only one you need is random.expovariate.
(a) At what point will the epidemic finish? (2 marks)
(b) Write method sim SIR that takes as inputs N, I0, β, γ and produces as output
a list of the event times and the number susceptible, infected and recovered at
each time point. All outbreaks start at time t = 0 with S0 = N −I0. (8 marks)
(c) Run a simulation with N = 1000, I0 = 10, β = 3, γ = 2 and plot the number
infected through time. (4 marks)
(d) Run an experiment and report the results to approximate the probability that
a large outbreak occurs using the same parameters as above but with only one
initial infected. What has usually happened if there is no large outbreak? (6
marks)
(e) The reproduction number R0 = β/γ of the epidemic is the mean number of
transmissions by a single infected in an otherwise susceptible population (Note
there is a bit of a notation clash: we are not referring to the number of recovered
individuals at time 0 in this case.) Using the same parameters as in part (c)
but allowing β to vary, select five values of R0 above and below 1 to explore
whether or not you get an outbreak. Report and explain your results. (6
marks)
(f) Suppose now that the infectious period is fixed, so that hosts are infectious
for exactly 1 time unit. Is the process still Markov? How would you go about
writing code to simulate such an epidemic? (You do not have to actually write
the code here.) (4 marks)
2
(g) Another common model breaks the infectious period up into m sub-periods,
I1, I2, . . . , Im so is an SI1I2 . . . ImR model. Assuming the amount of time each
individual spends in compartment Ij
is exponential with rate γ, what is the
distribution of the total time spent in I1 to Im? (4 marks)
(h) Drawing on what you know about infections, explain why neither a fixed length
nor an exponential distributed infectious period is a great model and why the
m sub-period model may be preferable. What computational advantage does
this formalism have that makes it easier to work with than some arbitrary
distribution for the infection period? (6 marks)
(i) Consider another compartmental model where there is no immunity to an infection so individuals recover straight back into a susceptible state and can get
infected again. This is know as birth death or SIS process. If we look at only
the type of events and ignore the waiting times between them, this process can
be described as a simple Markov chain. If the population size were fixed at
N = 5, and using transition rates (S, I) → (S − 1, I + 1) at rate βSI/N and
(S, I) → (S + 1, I − 1) at rate γI, write down the transition matrix for the
chain. (5 marks)
(j) Implement an SIS process which takes inputs N, I0, β, γ, t, where t is the number
of iterations (i.e., infection or recovery events) the simulation runs for. (6
marks)
(k) Run a simulation study using the SIS simulator with N = 1000, I0 = 10, β =
3, γ = 2 to determine the long term behaviour of this process. Discuss your
results. (4 marks)
请加QQ:99515681 邮箱:99515681@qq.com WX:codinghelp
- 聚焦两会丨加快推进医疗健康数字化建设 神州医疗以尖端技术赋能医院高质量发展
- 易文赛携手冠军家庭:储存围产期干细胞,守护健康未来之路
- 成功之路指南 海外营销专家推荐WhatsApp拉群营销工具的创新优势
- 数字商海的搞笑重返:数字商海的搞笑跨境电商 Line 群发云控笑话,会让你重新认识跨境电商 Line 群发云控的轻松一面
- 多伦科技董事长章安强受邀出席中国电动汽车百人会论坛并作主题演讲
- 雪浪云工业知识中台,开启知识管理新篇章
- 跨境电商群发拉群智能数据解读:WhatsApp代筛料子引领您的数据分析之旅
- Instagram营销软件 - ins接粉软件/ig打粉软件/ins私信软件
- 专业海外行销者分享 如何使用WhatsApp群发精准规避风控
- COMP30023代做、代写C/C++设计编程
- 聪明选择WhatsApp工具是我外贸起步时不可或缺的趋势智能助手
- 免费预约即将截止,5月7日上海TCT亚洲3D打印展参观指南,收藏!
- 代写Scheduling Operators at Lancaster
- CE-Channel: Streamline Your International Business Expansion with Instant Global Partner Connections
- CE Channel:打造未来科技生活,为新创公司提供全方位品牌支持与渠道服务
- EPM2210GF324C5: Enabling Compact and Efficient Digital Solutions with Advanced Programmable Logic |
- VDP160直流无刷水泵在水循环冷却应用分析报告
- 数字大法宝 科技魔法师揭秘 在WhatsApp拉群营销工具的世界里开启业务新篇章
- 代写ITP4905 Object Oriented Programming
- 量子商务的超凡先知:通过zalo筛选器打造产品在海外市场的文化适应性
- Telegram一键自动加群炒群营销软件,电报超强群发软件
- Instagram拉群新方式,ing群发软件/ig采集工具/测试联系大轩
- 中国修理网:传承匠心,打造一站式维修服务平台
- ins群发软件,ins拉群软件联系天宇爆粉【TG:@cjhshk199937】
- EBU4201代做、代写Java设计编程
- 稳中求进,碧桂园服务发布2023年年度业绩
- Instagram脚本打粉工具,ins超好用引流软件全球推荐!
- Instagram批量养号 - ins自动登录/ig采集指定地区/ins群发软件/ig引流群发
- 数字奇兵:科技魔法师驾驭WhatsApp拉群,点燃市场风暴
- 我与WhatsApp拉群工具的故事:从迷茫到坚定,从平凡到不平凡的蜕变之路
推荐
- 创意驱动增长,Adobe护城河够深吗? Adobe通过其Creative Cloud订阅捆绑包具有 科技
- 智慧驱动 共创未来| 东芝硬盘创新数据存储技术 为期三天的第五届中国(昆明)南亚社会公共安 科技
- 老杨第一次再度抓握住一瓶水,他由此产生了新的憧憬 瘫痪十四年后,老杨第一次再度抓握住一瓶水,他 科技
- 疫情期间 这个品牌实现了疯狂扩张 记得第一次喝瑞幸,还是2017年底去北京出差的 科技
- 苹果罕见大降价,华为的压力给到了? 1、苹果官网罕见大降价冲上热搜。原因是苹 科技
- 全力打造中国“创业之都”名片,第十届中国创业者大会将在郑州召开 北京创业科创科技中心主办的第十届中国创业 科技
- B站更新决策机构名单:共有 29 名掌权管理者,包括陈睿、徐逸、李旎、樊欣等人 1 月 15 日消息,据界面新闻,B站上周发布内部 科技
- 升级的脉脉,正在以招聘业务铺开商业化版图 长久以来,求职信息流不对称、单向的信息传递 科技
- 丰田章男称未来依然需要内燃机 已经启动电动机新项目 尽管电动车在全球范围内持续崛起,但丰田章男 科技
- 如何经营一家好企业,需要具备什么要素特点 我们大多数人刚开始创办一家企业都遇到经营 科技