Þ ¥bonds€¬cell_resultsÞ €Ù$f1f89502-0494-11eb-2303-0b79d8bbd13fЦqueued¤logs�§running¦output†¤bodyÙ;frequencies_plot_with_mean (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ênd˰persist_js_state·has_pluto_hook_features§cell_idÙ$f1f89502-0494-11eb-2303-0b79d8bbd13f¹depends_on_disabled_cells§runtimeÎ �„µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$95771ce2-0403-11eb-3056-f1dc3a8b7ec3Цqueued¤logs�§running¦output†¤bodyÚh
👉 Write a function simulation that does the following:
Generate the $N$ agents.
Run sweep! a number $T$ of times. Calculate and store the total number of agents with each status at each step in variables S_counts, I_counts and R_counts.
Return the vectors S_counts, I_counts and R_counts in a named tuple , with keys S, I and R.
You've seen an example of named tuples before: the student variable at the top of the notebook!
Feel free to store the counts in a different way, as long as the return type is the same.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ätn“°persist_js_state·has_pluto_hook_features§cell_idÙ$95771ce2-0403-11eb-3056-f1dc3a8b7ec3¹depends_on_disabled_cells§runtimeÎ
„µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$e6219c7c-0420-11eb-3faa-13126f7c8007Цqueued¤logs�§running¦output†¤bodyÙ¤Abstraction, lines 1-219
Array Basics, lines 1-137
Course Intro, lines 1-44
(for example )
¤mime©text/html¬rootassignee®lines_i_edited²last_run_timestampËAÚ Ë÷®X°persist_js_state·has_pluto_hook_features§cell_idÙ$e6219c7c-0420-11eb-3faa-13126f7c8007¹depends_on_disabled_cells§runtimeÎ =�µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$b817f466-04d4-11eb-0a26-c1c667f9f7f7Цqueued¤logs�§running¦output†¤bodyÙ¥Here we go!
Replace missing with your answer.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÌS°persist_js_state·has_pluto_hook_features§cell_idÙ$b817f466-04d4-11eb-0a26-c1c667f9f7f7¹depends_on_disabled_cells§runtimeÎ ò—µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$08e2bc64-0417-11eb-1457-21c0d18e8c51Цqueued¤logs�§running¦output†¤bodyÚ�Hint
Do you remember how we worked with dictionaries in Homework 3? You can create an empty dictionary using Dict(). You may want to use either the function haskey or the function get on your dictionary – check the documentation for how to use these functions.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ì [Õ°persist_js_state·has_pluto_hook_features§cell_idÙ$08e2bc64-0417-11eb-1457-21c0d18e8c51¹depends_on_disabled_cells§runtimeÎ •¯µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$bb8aeb58-042f-11eb-18b8-f995631df619Цqueued¤logs�§running¦output†¤bodyÙÑAs you separately vary $p$ and $N$ , what do you observe about the mean in each case? Does that make sense?
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äqãó°persist_js_state·has_pluto_hook_features§cell_idÙ$bb8aeb58-042f-11eb-18b8-f995631df619¹depends_on_disabled_cells§runtimeÎ ˜�µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$223933a4-042c-11eb-10d3-852229f25a35Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ê«¬Þ°persist_js_state·has_pluto_hook_features§cell_idÙ$223933a4-042c-11eb-10d3-852229f25a35¹depends_on_disabled_cells§runtimeÎ ÿµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ê{ru°persist_js_state·has_pluto_hook_features§cell_idÙ$ae4ac4b4-041f-11eb-14f5-1bcde35d18f2¹depends_on_disabled_cells§runtimeÎ “¦µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$7f635722-04d0-11eb-3209-4b603c9e843cЦqueued¤logs�§running¦output†¤body‚£msgÚQMethodError: no method matching length(::Missing)
[0mClosest candidates are:
[0m length([91m::Union{Base.KeySet, Base.ValueIterator}[39m) at /opt/hostedtoolcache/julia/1.7.3/x64/share/julia/base/abstractdict.jl:58
[0m length([91m::Union{LinearAlgebra.Adjoint{T, S}, LinearAlgebra.Transpose{T, S}} where {T, S}[39m) at /opt/hostedtoolcache/julia/1.7.3/x64/share/julia/stdlib/v1.7/LinearAlgebra/src/adjtrans.jl:171
[0m length([91m::Union{DataStructures.OrderedRobinDict, DataStructures.RobinDict}[39m) at ~/.julia/packages/DataStructures/IrAJn/src/ordered_robin_dict.jl:86
[0m ...ªstacktrace’Œªcall_shortÙ^sir_mean_plot(simulations::Vector{NamedTuple{(:S, :I, :R), Tuple{Missing, Missing, Missing}}})§inlined£urlÙ‹https://github.com/fonsp/disorganised-mess/tree/6d5f6e46c196925a19e151358b6656510197d2e1//hw4.jl#==#843fd63c-04d0-11eb-0113-c58d346179d6#L1¤pathÙd/home/runner/work/disorganised-mess/disorganised-mess/hw4.jl#==#843fd63c-04d0-11eb-0113-c58d346179d6®source_packageÀ¤callÙ^sir_mean_plot(simulations::Vector{NamedTuple{(:S, :I, :R), Tuple{Missing, Missing, Missing}}})ªlinfo_type³Core.MethodInstance¤line¤fileÙ.hw4.jl#==#843fd63c-04d0-11eb-0113-c58d346179d6¤funcsir_mean_plotparent_moduleÀ¦from_cÂŒªcall_short¯top-level scope§inlinedãurlÀ¤pathÙd/home/runner/work/disorganised-mess/disorganised-mess/hw4.jl#==#7f635722-04d0-11eb-3209-4b603c9e843c®source_packageÀ¤call¯top-level scopeªlinfo_type§Nothing¤line¤fileÙ.hw4.jl#==#7f635722-04d0-11eb-3209-4b603c9e843c¤func»##function_wrapped_cell#413parent_moduleÀ¦from_c¤mimeÙ'application/vnd.pluto.stacktrace+object¬rootassigneeÀ²last_run_timestampËAÚ Ëì©ß°persist_js_state·has_pluto_hook_features§cell_idÙ$7f635722-04d0-11eb-3209-4b603c9e843c¹depends_on_disabled_cells§runtimeÀµpublished_object_keys�¸depends_on_skipped_cells§erroredÃÙ$7c515a7a-04d5-11eb-0f36-4fcebff709d5Цqueued¤logs�§running¦output†¤bodyÙœKeep working on it!
The answer is not quite right.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÌVcZ°persist_js_state·has_pluto_hook_features§cell_idÙ$7c515a7a-04d5-11eb-0f36-4fcebff709d5¹depends_on_disabled_cells§runtimeÍÛµµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$107e65a4-0403-11eb-0c14-37d8d828b469Цqueued¤logs�§running¦output†¤bodyÙTLet's create a package environment:
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÄpIs°persist_js_state·has_pluto_hook_features§cell_idÙ$107e65a4-0403-11eb-0c14-37d8d828b469¹depends_on_disabled_cells§runtimeÎ Pbµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$1c6aa208-04d1-11eb-0b87-cf429e6ff6d0Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Äv#°persist_js_state·has_pluto_hook_features§cell_idÙ$1c6aa208-04d1-11eb-0b87-cf429e6ff6d0¹depends_on_disabled_cells§runtimeÎ nµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$80e6f1e0-04b1-11eb-0d4e-475f1d80c2bbЦqueued¤logs�§running¦output†¤bodyÚIn the cell below, we plot the evolution of the number of $I$ individuals as a function of time for each of the simulations on the same plot using transparency (alpha=0.5 inside the plot command).
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äuß°persist_js_state·has_pluto_hook_features§cell_idÙ$80e6f1e0-04b1-11eb-0d4e-475f1d80c2bb¹depends_on_disabled_cells§runtimeÎ `ñµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$7f4e121c-041d-11eb-0dff-cd0cbfdfd606Цqueued¤logs�§running¦output†¤body§missing¤mimeªtext/plain¬rootassignee«test_status²last_run_timestampËAÚ Êr½^°persist_js_state·has_pluto_hook_features§cell_idÙ$7f4e121c-041d-11eb-0dff-cd0cbfdfd606¹depends_on_disabled_cells§runtimeÍ(úµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$4f19e872-0414-11eb-0dfd-e53d2aecc4dcЦqueued¤logs�§running¦output†¤bodyÙnFunction library
Just some helper functions used in the notebook.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äwy¯°persist_js_state·has_pluto_hook_features§cell_idÙ$4f19e872-0414-11eb-0dfd-e53d2aecc4dc¹depends_on_disabled_cells§runtimeÎ a¥µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$5689841e-0414-11eb-0492-63c77ddbd136Цqueued¤logs�§running¦output†¤body´ ¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ìxç°persist_js_state·has_pluto_hook_features§cell_idÙ$5689841e-0414-11eb-0492-63c77ddbd136¹depends_on_disabled_cells§runtimeÍ$¢µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$759bc42e-04ab-11eb-0ab1-b12e008c02a9Цqueued¤logs�§running¦output†¤bodyÙØKeep working on it!
The agent should recover from an infectious state with the right probability.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ì`ä›°persist_js_state·has_pluto_hook_features§cell_idÙ$759bc42e-04ab-11eb-0ab1-b12e008c02a9¹depends_on_disabled_cells§runtimeÎí<µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$99ef7b2a-0403-11eb-08ef-e1023cd151aeЦqueued¤logs�§running¦output†¤bodyڤ👉 Make a new method for the interact! function that accepts the new infection type as argument, reusing as much functionality as possible from the previous version.
Write it in the same cell as our previous interact! method , and use a begin block to group the two definitions together.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äv뎰persist_js_state·has_pluto_hook_features§cell_idÙ$99ef7b2a-0403-11eb-08ef-e1023cd151ae¹depends_on_disabled_cells§runtimeÎ M¨µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$77b54c10-0403-11eb-16ad-65374d29a817Цqueued¤logs�§running¦output†¤bodyÚ👉 Write an interactive visualization that draws the histogram and mean for $p$ between $0.01$ (not $0$ !) and $1$ , and $N$ between $1$ and $100,000$ , say. To avoid a naming conflict, call them p_interactive and N_interactive, instead of just p and N.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äq¨?°persist_js_state·has_pluto_hook_features§cell_idÙ$77b54c10-0403-11eb-16ad-65374d29a817¹depends_on_disabled_cells§runtimeÎ
µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$7768a2dc-0403-11eb-39b7-fd660dc952feЦqueued¤logs�§running¦output†¤bodyٲ👉 Write the function frequencies_plot_with_mean that calculates the mean recovery time and displays it using a vertical line.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÄqŽÖ°persist_js_state·has_pluto_hook_features§cell_idÙ$7768a2dc-0403-11eb-39b7-fd660dc952fe¹depends_on_disabled_cells§runtimeÎ þQµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$60a8b708-04c8-11eb-37b1-3daec644ac90Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÄsI°persist_js_state·has_pluto_hook_features§cell_idÙ$60a8b708-04c8-11eb-37b1-3daec644ac90¹depends_on_disabled_cells§runtimeÎ !¯µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$95eb9f88-0403-11eb-155b-7b2d3a07cff0Цqueued¤logs�§running¦output†¤bodyÚO👉 Write a function sir_mean_error_plot that does the same as sir_mean_plot, which also computes the standard deviation $\sigma$ of $S$ , $I$ , $R$ at each step. Add this to the plot using error bars , using the option yerr=σ in the plot command; use transparency.
This should confirm that the distribution of $I$ at each step is pretty wide!
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äv?O°persist_js_state·has_pluto_hook_features§cell_idÙ$95eb9f88-0403-11eb-155b-7b2d3a07cff0¹depends_on_disabled_cells§runtimeÎ ìüµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$955321de-0403-11eb-04ce-fb1670dfbb9eЦqueued¤logs�§running¦output†¤bodyÚC👉 Write a function sweep!. It runs step! $N$ times, where $N$ is the number of agents. Thus each agent acts, on average, once per sweep; a sweep is thus the unit of time in our Monte Carlo simulation.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÄtIM°persist_js_state·has_pluto_hook_features§cell_idÙ$955321de-0403-11eb-04ce-fb1670dfbb9e¹depends_on_disabled_cells§runtimeÎ yfµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$ae70625a-041f-11eb-3082-0753419d6d57Цqueued¤logs�§running¦output†¤bodyÚ“When you define a new type like this, Julia automatically defines one or more constructors , which are methods of a generic function with the same name as the type. These are used to create objects of that type.
👉 Use the methods function to check how many constructors are pre-defined for the Agent type.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ärúv°persist_js_state·has_pluto_hook_features§cell_idÙ$ae70625a-041f-11eb-3082-0753419d6d57¹depends_on_disabled_cells§runtimeÎ aµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$843fd63c-04d0-11eb-0113-c58d346179d6Цqueued¤logs�§running¦output†¤bodyÙ.sir_mean_plot (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ËàÑò°persist_js_state·has_pluto_hook_features§cell_idÙ$843fd63c-04d0-11eb-0113-c58d346179d6¹depends_on_disabled_cells§runtimeÎ h%µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$189cae1e-0424-11eb-2666-65bf297d8bddЦqueued¤logs�§running¦output†¤bodyٕ👉 Create an agent test_agent with status S and num_infected equal to 0.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äs&c°persist_js_state·has_pluto_hook_features§cell_idÙ$189cae1e-0424-11eb-2666-65bf297d8bdd¹depends_on_disabled_cells§runtimeÎ uáµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$7f744644-041d-11eb-08a0-3719cc0adeb7Цqueued¤logs�§running¦output†¤bodyÙ{👉 Use the typeof function to find the type of test_status.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Är—ò°persist_js_state·has_pluto_hook_features§cell_idÙ$7f744644-041d-11eb-08a0-3719cc0adeb7¹depends_on_disabled_cells§runtimeÎ ú5µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$488771e2-049f-11eb-3b0a-0de260457731Цqueued¤logs�§running¦output†¤body§missing¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ê«Œü°persist_js_state·has_pluto_hook_features§cell_idÙ$488771e2-049f-11eb-3b0a-0de260457731¹depends_on_disabled_cells§runtimeÍ)ôµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$393041ec-049f-11eb-3089-2faf378445f3Цqueued¤logs�§running¦output†¤bodyÙ¥Here we go!
Replace missing with your answer.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÌY´¯°persist_js_state·has_pluto_hook_features§cell_idÙ$393041ec-049f-11eb-3089-2faf378445f3¹depends_on_disabled_cells§runtimeÎ däµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$531d13c2-0414-11eb-0acd-4905a684869dЦqueued¤logs�§running¦output†¤bodyÙçBefore you submit
Remember to fill in your name and Kerberos ID at the top of this notebook.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ëú°persist_js_state·has_pluto_hook_features§cell_idÙ$531d13c2-0414-11eb-0acd-4905a684869d¹depends_on_disabled_cells§runtimeÎ TYµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$06f30b2a-0403-11eb-0f05-8badebe1011dЦqueued¤logs�§running¦output†¤bodyÚuHomework 4 : Epidemic modeling I
18.S191, fall 2020
This notebook contains built-in, live answer checks ! In some exercises you will see a coloured box, which runs a test case on your code, and provides feedback based on the result. Simply edit the code, run it, and the check runs again.
For MIT students: there will also be some additional (secret) test cases that will be run as part of the grading process, and we will look at your notebook and write comments.
Feel free to ask questions!
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äp0×°persist_js_state·has_pluto_hook_features§cell_idÙ$06f30b2a-0403-11eb-0f05-8badebe1011d¹depends_on_disabled_cells§runtimeÎ ¶fµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$9c39974c-04a5-11eb-184d-317eb542452cЦqueued¤logs�§running¦output†¤bodyƒ¨elements’’¥agent’…¦prefix¥Agent¨elements’’¦status’¶S::InfectionStatus = 0ªtext/plain’¬num_infected’¡0ªtext/plain¤type¦struct¬prefix_short¥Agent¨objectid°8f17d8b939254d92Ù!application/vnd.pluto.tree+object’¦source’…¦prefix¥Agent¨elements’’¦status’¶I::InfectionStatus = 1ªtext/plain’¬num_infected’¡0ªtext/plain¤type¦struct¬prefix_short¥Agent¨objectid°709f2124fc33ddc2Ù!application/vnd.pluto.tree+object¤typeªNamedTuple¨objectid°7ce78337241724ae¤mimeÙ!application/vnd.pluto.tree+object¬rootassigneeÀ²last_run_timestampËAÚ ÊÏ ×°persist_js_state·has_pluto_hook_features§cell_idÙ$9c39974c-04a5-11eb-184d-317eb542452c¹depends_on_disabled_cells§runtimeÍŸ
µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$1ddbaa18-0494-11eb-1fc8-250ab6ae89f1Цqueued¤logs�§running¦output†¤body‚£msgÙûMethodError: no method matching frequencies_plot_with_maximum(::Missing)
[0mClosest candidates are:
[0m frequencies_plot_with_maximum([91m::Vector[39m) at ~/work/disorganised-mess/disorganised-mess/hw4.jl#==#823364ce-041c-11eb-2467-7ffa4f751527:1ªstacktrace‘Œªcall_short¯top-level scope§inlinedãurlÀ¤pathÙd/home/runner/work/disorganised-mess/disorganised-mess/hw4.jl#==#1ddbaa18-0494-11eb-1fc8-250ab6ae89f1®source_packageÀ¤call¯top-level scopeªlinfo_type§Nothing¤line¤fileÙ.hw4.jl#==#1ddbaa18-0494-11eb-1fc8-250ab6ae89f1¤func»##function_wrapped_cell#332parent_moduleÀ¦from_c¤mimeÙ'application/vnd.pluto.stacktrace+object¬rootassigneeÀ²last_run_timestampËAÚ Êcâç°persist_js_state·has_pluto_hook_features§cell_idÙ$1ddbaa18-0494-11eb-1fc8-250ab6ae89f1¹depends_on_disabled_cells§runtimeÀµpublished_object_keys�¸depends_on_skipped_cells§erroredÃÙ$06089d1e-0495-11eb-0ace-a7a7dc60e5b2Цqueued¤logs�§running¦output†¤body§missing¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÊnÚõ°persist_js_state·has_pluto_hook_features§cell_idÙ$06089d1e-0495-11eb-0ace-a7a7dc60e5b2¹depends_on_disabled_cells§runtimeÍ/úµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$15187690-0403-11eb-2dfd-fd924faa3513Цqueued¤logs’ˆ¤lineÿ£msg’Ù;Failed to load integration with PlotlyBase & PlotlyKaleido.ªtext/plain§cell_idÙ$15187690-0403-11eb-2dfd-fd924faa3513¦kwargs‘’©exception’‚£msgÙŠArgumentError: Package PlotlyBase not found in current path:
- Run `import Pkg; Pkg.add("PlotlyBase")` to install the PlotlyBase package.
ªstacktrace˜Œªcall_shortÙ"require(into::Module, mod::Symbol)§inlined£urlÙehttps://github.com/JuliaLang/julia/tree/742b9abb4dd4621b667ec5bb3434b8b3602f96fd/base/loading.jl#L959¤path¬./loading.jl®source_packageÀ¤callÙ"require(into::Module, mod::Symbol)ªlinfo_type³Core.MethodInstance¤lineÍǤfileªloading.jl¤func§requireparent_moduleÀ¦from_cÂŒªcall_short¯top-level scope§inlined£urlÀ¤pathÙ8/home/runner/.julia/packages/Plots/uiCPf/src/backends.jl®source_packageÀ¤call¯top-level scopeªlinfo_typeCore.CodeInfo¤lineÍ8¤file«backends.jl¤func¯top-level scopeparent_moduleÀ¦from_cÂŒªcall_short¤eval§inlinedãurlÀ¤path©./boot.jl®source_packageÀ¤call¤evalªlinfo_type§Nothing¤lineÍu¤file§boot.jl¤func¤evalparent_moduleÀ¦from_cÂŒªcall_shortÙ-_initialize_backend(pkg::Plots.PlotlyBackend)§inlined£urlÙ?file:///home/runner/.julia/packages/Plots/uiCPf/src/backends.jl¤pathÙ8/home/runner/.julia/packages/Plots/uiCPf/src/backends.jl®source_packageÀ¤callÙ-_initialize_backend(pkg::Plots.PlotlyBackend)ªlinfo_type³Core.MethodInstance¤lineÍ7¤file«backends.jl¤func³_initialize_backendparent_moduleÀ¦from_cÂŒªcall_shortÙ!backend(pkg::Plots.PlotlyBackend)§inlined£urlÙ?file:///home/runner/.julia/packages/Plots/uiCPf/src/backends.jl¤pathÙ8/home/runner/.julia/packages/Plots/uiCPf/src/backends.jl®source_packageÀ¤callÙ!backend(pkg::Plots.PlotlyBackend)ªlinfo_type³Core.MethodInstance¤lineÌõ¤file«backends.jl¤func§backendparent_moduleÀ¦from_cÂŒªcall_short«#plotly#324§inlinedãurlÀ¤pathÙ8/home/runner/.julia/packages/Plots/uiCPf/src/backends.jl®source_packageÀ¤call«#plotly#324ªlinfo_type§Nothing¤lineV¤file«backends.jl¤func«#plotly#324parent_moduleÀ¦from_cÂŒªcall_short¨plotly()§inlined£urlÙ?file:///home/runner/.julia/packages/Plots/uiCPf/src/backends.jl¤pathÙ8/home/runner/.julia/packages/Plots/uiCPf/src/backends.jl®source_packageÀ¤call¨plotly()ªlinfo_type³Core.MethodInstance¤lineV¤file«backends.jl¤func¦plotlyparent_moduleÀ¦from_cÂŒªcall_short¯top-level scope§inlined£urlÀ¤pathÙd/home/runner/work/disorganised-mess/disorganised-mess/hw4.jl#==#15187690-0403-11eb-2dfd-fd924faa3513®source_packageÀ¤call¯top-level scopeªlinfo_typeCore.CodeInfo¤line¤fileÙ.hw4.jl#==#15187690-0403-11eb-2dfd-fd924faa3513¤func¯top-level scopeparent_moduleÀ¦from_cÂÙ'application/vnd.pluto.stacktrace+object¢id®Plots_b627f5e6¤fileÙ8/home/runner/.julia/packages/Plots/uiCPf/src/backends.jl¥group¨backends¥level¤Warnˆ¤lineÿ£msg’Ú)1[32m[1m Updating[22m[39m registry at `~/.julia/registries/General.toml`
[32m[1m Resolving[22m[39m package versions...
[32m[1m Updating[22m[39m `/tmp/jl_tSReBH/Project.toml`
[90m [91a5bcdd] [39m[92m+ Plots v1.40.14[39m
[90m [7f904dfe] [39m[92m+ PlutoUI v0.7.64[39m
[32m[1m Updating[22m[39m `/tmp/jl_tSReBH/Manifest.toml`
[90m [6e696c72] [39m[92m+ AbstractPlutoDingetjes v1.3.2[39m
[90m [66dad0bd] [39m[92m+ AliasTables v1.1.3[39m
[90m [d1d4a3ce] [39m[92m+ BitFlags v0.1.9[39m
[90m [d360d2e6] [39m[92m+ ChainRulesCore v1.25.1[39m
[90m [9e997f8a] [39m[92m+ ChangesOfVariables v0.1.10[39m
[90m [944b1d66] [39m[92m+ CodecZlib v0.7.8[39m
[90m [35d6a980] [39m[92m+ ColorSchemes v3.29.0[39m
[90m [3da002f7] [39m[92m+ ColorTypes v0.12.1[39m
[90m [c3611d14] [39m[92m+ ColorVectorSpace v0.11.0[39m
[90m [5ae59095] [39m[92m+ Colors v0.13.1[39m
[90m [34da2185] [39m[92m+ Compat v4.16.0[39m
[90m [f0e56b4a] [39m[92m+ ConcurrentUtilities v2.5.0[39m
[90m [187b0558] [39m[92m+ ConstructionBase v1.5.8[39m
[90m [d38c429a] [39m[92m+ Contour v0.6.3[39m
[90m [9a962f9c] [39m[92m+ DataAPI v1.16.0[39m
[90m [864edb3b] [39m[92m+ DataStructures v0.18.22[39m
[90m [ffbed154] [39m[92m+ DocStringExtensions v0.9.5[39m
[90m [460bff9d] [39m[92m+ ExceptionUnwrapping v0.1.11[39m
[90m [c87230d0] [39m[92m+ FFMPEG v0.4.2[39m
[90m [53c48c17] [39m[92m+ FixedPointNumbers v0.8.5[39m
[90m [1fa38f19] [39m[92m+ Format v1.3.7[39m
[90m [28b8d3ca] [39m[92m+ GR v0.73.6[39m
[90m [42e2da0e] [39m[92m+ Grisu v1.0.2[39m
[90m [cd3eb016] [39m[92m+ HTTP v1.10.16[39m
[90m [47d2ed2b] [39m[92m+ Hyperscript v0.0.5[39m
[90m [ac1192a8] [39m[92m+ HypertextLiteral v0.9.5[39m
[90m [b5f81e59] [39m[92m+ IOCapture v0.2.5[39m
[90m [3587e190] [39m[92m+ InverseFunctions v0.1.17[39m
[90m [92d709cd] [39m[92m+ IrrationalConstants v0.2.4[39m
[90m [1019f520] [39m[92m+ JLFzf v0.1.11[39m
[90m [692b3bcd] [39m[92m+ JLLWrappers v1.7.0[39m
[90m [682c06a0] [39m[92m+ JSON v0.21.4[39m
[90m [b964fa9f] [39m[92m+ LaTeXStrings v1.4.0[39m
[90m [23fbe1c1] [39m[92m+ Latexify v0.16.8[39m
[90m [2ab3a3ac] [39m[92m+ LogExpFunctions v0.3.28[39m
[90m [e6f89c97] [39m[92m+ LoggingExtras v1.1.0[39m
[90m [6c6e2e6c] [39m[92m+ MIMEs v1.1.0[39m
[90m [1914dd2f] [39m[92m+ MacroTools v0.5.16[39m
[90m [739be429] [39m[92m+ MbedTLS v1.1.9[39m
[90m [442fdcdd] [39m[92m+ Measures v0.3.2[39m
[90m [e1d29d7a] [39m[92m+ Missings v1.2.0[39m
[90m [77ba4419] [39m[92m+ NaNMath v1.0.3[39m
[90m [4d8831e6] [39m[92m+ OpenSSL v1.5.0[39m
[90m [bac558e1] [39m[92m+ OrderedCollections v1.8.1[39m
[90m [69de0a69] [39m[92m+ Parsers v2.8.3[39m
[90m [ccf2f8ad] [39m[92m+ PlotThemes v3.3.0[39m
[90m [995b91a9] [39m[92m+ PlotUtils v1.4.3[39m
[90m [91a5bcdd] [39m[92m+ Plots v1.40.14[39m
[90m [7f904dfe] [39m[92m+ PlutoUI v0.7.64[39m
[90m [aea7be01] [39m[92m+ PrecompileTools v1.2.1[39m
[90m [21216c6a] [39m[92m+ Preferences v1.4.3[39m
[90m [43287f4e] [39m[92m+ PtrArrays v1.3.0[39m
[90m [3cdcf5f2] [39m[92m+ RecipesBase v1.3.4[39m
[90m [01d81517] [39m[92m+ RecipesPipeline v0.6.12[39m
[90m [189a3867] [39m[92m+ Reexport v1.2.2[39m
[90m [05181044] [39m[92m+ RelocatableFolders v1.0.1[39m
[90m [ae029012] [39m[92m+ Requires v1.3.1[39m
[90m [6c6a2e73] [39m[92m+ Scratch v1.2.1[39m
[90m [992d4aef] [39m[92m+ Showoff v1.0.3[39m
[90m [777ac1f9] [39m[92m+ SimpleBufferStream v1.2.0[39m
[90m [a2af1166] [39m[92m+ SortingAlgorithms v1.2.1[39m
[90m [860ef19b] [39m[92m+ StableRNGs v1.0.3[39m
[90m [82ae8749] [39m[92m+ StatsAPI v1.7.1[39m
[90m [2913bbd2] [39m[92m+ StatsBase v0.34.4[39m
[90m [62fd8b95] [39m[92m+ TensorCore v0.1.1[39m
[90m [3bb67fe8] [39m[92m+ TranscodingStreams v0.11.3[39m
[90m [410a4b4d] [39m[92m+ Tricks v0.1.10[39m
[90m [5c2747f8] [39m[92m+ URIs v1.5.2[39m
[90m [1cfade01] [39m[92m+ UnicodeFun v0.4.1[39m
[90m [1986cc42] [39m[92m+ Unitful v1.23.1[39m
[90m [45397f5d] [39m[92m+ UnitfulLatexify v1.7.0[39m
[90m [41fe7b60] [39m[92m+ Unzip v0.2.0[39m
[90m [6e34b625] [39m[92m+ Bzip2_jll v1.0.9+0[39m
[90m [83423d85] [39m[92m+ Cairo_jll v1.18.5+0[39m
[90m [ee1fde0b] [39m[92m+ Dbus_jll v1.16.2+0[39m
[90m [2702e6a9] [39m[92m+ EpollShim_jll v0.0.20230411+1[39m
[90m [2e619515] [39m[92m+ Expat_jll v2.6.5+0[39m
[90m [b22a6f82] [39m[92m+ FFMPEG_jll v4.4.4+1[39m
[90m [a3f928ae] [39m[92m+ Fontconfig_jll v2.16.0+0[39m
[90m [d7e528f0] [39m[92m+ FreeType2_jll v2.13.4+0[39m
[90m [559328eb] [39m[92m+ FriBidi_jll v1.0.17+0[39m
[90m [0656b61e] [39m[92m+ GLFW_jll v3.4.0+2[39m
[90m [d2c73de3] [39m[92m+ GR_jll v0.73.6+0[39m
[90m [78b55507] [39m[92m+ Gettext_jll v0.21.0+0[39m
[90m [7746bdde] [39m[92m+ Glib_jll v2.84.0+0[39m
[90m [3b182d85] [39m[92m+ Graphite2_jll v1.3.15+0[39m
[90m [2e76f6c2] [39m[92m+ HarfBuzz_jll v8.5.1+0[39m
[90m [aacddb02] [39m[92m+ JpegTurbo_jll v3.1.1+0[39m
[90m [c1c5ebd0] [39m[92m+ LAME_jll v3.100.2+0[39m
[90m [88015f11] [39m[92m+ LERC_jll v3.0.0+1[39m
[90m [1d63c593] [39m[92m+ LLVMOpenMP_jll v18.1.8+0[39m
[90m [dd4b983a] [39m[92m+ LZO_jll v2.10.3+0[39m
[90m [e9f186c6] [39m[92m+ Libffi_jll v3.4.7+0[39m
[90m [7e76a0d4] [39m[92m+ Libglvnd_jll v1.7.1+1[39m
[90m [94ce4f54] [39m[92m+ Libiconv_jll v1.18.0+0[39m
[90m [4b2f31a3] [39m[92m+ Libmount_jll v2.41.0+0[39m
[90m [89763e89] [39m[92m+ Libtiff_jll v4.5.1+1[39m
[90m [38a345b3] [39m[92m+ Libuuid_jll v2.41.0+0[39m
[90m [e7412a2a] [39m[92m+ Ogg_jll v1.3.5+1[39m
[90m [458c3c95] [39m[92m+ OpenSSL_jll v3.5.0+0[39m
[90m [91d4177d] [39m[92m+ Opus_jll v1.3.3+0[39m
[90m [36c8627f] [39m[92m+ Pango_jll v1.56.3+0[39m
[90m [30392449] [39m[92m+ Pixman_jll v0.44.2+0[39m
[90m [c0090381] [39m[92m+ Qt6Base_jll v6.7.1+1[39m
[90m [a44049a8] [39m[92m+ Vulkan_Loader_jll v1.3.243+0[39m
[90m [a2964d1f] [39m[92m+ Wayland_jll v1.23.1+0[39m
[90m [2381bf8a] [39m[92m+ Wayland_protocols_jll v1.44.0+0[39m
[90m [02c8fc9c] [39m[92m+ XML2_jll v2.13.6+1[39m
[90m [ffd25f8a] [39m[92m+ XZ_jll v5.8.1+0[39m
[90m [f67eecfb] [39m[92m+ Xorg_libICE_jll v1.1.2+0[39m
[90m [c834827a] [39m[92m+ Xorg_libSM_jll v1.2.6+0[39m
[90m [4f6342f7] [39m[92m+ Xorg_libX11_jll v1.8.12+0[39m
[90m [0c0b7dd1] [39m[92m+ Xorg_libXau_jll v1.0.13+0[39m
[90m [935fb764] [39m[92m+ Xorg_libXcursor_jll v1.2.4+0[39m
[90m [a3789734] [39m[92m+ Xorg_libXdmcp_jll v1.1.6+0[39m
[90m [1082639a] [39m[92m+ Xorg_libXext_jll v1.3.7+0[39m
[90m [d091e8ba] [39m[92m+ Xorg_libXfixes_jll v6.0.1+0[39m
[90m [a51aa0fd] [39m[92m+ Xorg_libXi_jll v1.8.3+0[39m
[90m [d1454406] [39m[92m+ Xorg_libXinerama_jll v1.1.6+0[39m
[90m [ec84b674] [39m[92m+ Xorg_libXrandr_jll v1.5.5+0[39m
[90m [ea2f1a96] [39m[92m+ Xorg_libXrender_jll v0.9.12+0[39m
[90m [c7cfdc94] [39m[92m+ Xorg_libxcb_jll v1.17.1+0[39m
[90m [cc61e674] [39m[92m+ Xorg_libxkbfile_jll v1.1.3+0[39m
[90m [e920d4aa] [39m[92m+ Xorg_xcb_util_cursor_jll v0.1.4+0[39m
[90m [12413925] [39m[92m+ Xorg_xcb_util_image_jll v0.4.1+0[39m
[90m [2def613f] [39m[92m+ Xorg_xcb_util_jll v0.4.1+0[39m
[90m [975044d2] [39m[92m+ Xorg_xcb_util_keysyms_jll v0.4.1+0[39m
[90m [0d47668e] [39m[92m+ Xorg_xcb_util_renderutil_jll v0.3.10+0[39m
[90m [c22f9ab0] [39m[92m+ Xorg_xcb_util_wm_jll v0.4.2+0[39m
[90m [35661453] [39m[92m+ Xorg_xkbcomp_jll v1.4.7+0[39m
[90m [33bec58e] [39m[92m+ Xorg_xkeyboard_config_jll v2.44.0+0[39m
[90m [c5fb5394] [39m[92m+ Xorg_xtrans_jll v1.6.0+0[39m
[90m [3161d3a3] [39m[92m+ Zstd_jll v1.5.7+1[39m
[90m [35ca27e7] [39m[92m+ eudev_jll v3.2.14+0[39m
[90m [214eeab7] [39m[92m+ fzf_jll v0.61.1+0[39m
[90m [a4ae2306] [39m[92m+ libaom_jll v3.11.0+0[39m
[90m [0ac62f75] [39m[92m+ libass_jll v0.15.2+0[39m
[90m [1183f4f0] [39m[92m+ libdecor_jll v0.2.2+0[39m
[90m [2db6ffa8] [39m[92m+ libevdev_jll v1.13.4+0[39m
[90m [f638f0a6] [39m[92m+ libfdk_aac_jll v2.0.3+0[39m
[90m [36db933b] [39m[92m+ libinput_jll v1.28.1+0[39m
[90m [b53b4c65] [39m[92m+ libpng_jll v1.6.49+0[39m
[90m [f27f6e37] [39m[92m+ libvorbis_jll v1.3.7+2[39m
[90m [009596ad] [39m[92m+ mtdev_jll v1.1.7+0[39m
[90m [1270edf5] [39m[92m+ x264_jll v2021.5.5+0[39m
[90m [dfaa095f] [39m[92m+ x265_jll v3.5.0+0[39m
[90m [d8fb68d0] [39m[92m+ xkbcommon_jll v1.8.1+0[39m
[90m [0dad84c5] [39m[92m+ ArgTools[39m
[90m [56f22d72] [39m[92m+ Artifacts[39m
[90m [2a0f44e3] [39m[92m+ Base64[39m
[90m [ade2ca70] [39m[92m+ Dates[39m
[90m [8bb1440f] [39m[92m+ DelimitedFiles[39m
[90m [f43a241f] [39m[92m+ Downloads[39m
[90m [7b1f6079] [39m[92m+ FileWatching[39m
[90m [b77e0a4c] [39m[92m+ InteractiveUtils[39m
[90m [b27032c2] [39m[92m+ LibCURL[39m
[90m [76f85450] [39m[92m+ LibGit2[39m
[90m [8f399da3] [39m[92m+ Libdl[39m
[90m [37e2e46d] [39m[92m+ LinearAlgebra[39m
[90m [56ddb016] [39m[92m+ Logging[39m
[90m [d6f4376e] [39m[92m+ Markdown[39m
[90m [a63ad114] [39m[92m+ Mmap[39m
[90m [ca575930] [39m[92m+ NetworkOptions[39m
[90m [44cfe95a] [39m[92m+ Pkg[39m
[90m [de0858da] [39m[92m+ Printf[39m
[90m [3fa0cd96] [39m[92m+ REPL[39m
[90m [9a3f8284] [39m[92m+ Random[39m
[90m [ea8e919c] [39m[92m+ SHA[39m
[90m [9e88b42a] [39m[92m+ Serialization[39m
[90m [6462fe0b] [39m[92m+ Sockets[39m
[90m [2f01184e] [39m[92m+ SparseArrays[39m
[90m [10745b16] [39m[92m+ Statistics[39m
[90m [fa267f1f] [39m[92m+ TOML[39m
[90m [a4e569a6] [39m[92m+ Tar[39m
[90m [8dfed614] [39m[92m+ Test[39m
[90m [cf7118a7] [39m[92m+ UUIDs[39m
[90m [4ec0a83e] [39m[92m+ Unicode[39m
[90m [e66e0078] [39m[92m+ CompilerSupportLibraries_jll[39m
[90m [deac9b47] [39m[92m+ LibCURL_jll[39m
[90m [29816b5a] [39m[92m+ LibSSH2_jll[39m
[90m [c8ffd9c3] [39m[92m+ MbedTLS_jll[39m
[90m [14a3606d] [39m[92m+ MozillaCACerts_jll[39m
[90m [4536629a] [39m[92m+ OpenBLAS_jll[39m
[90m [05823500] [39m[92m+ OpenLibm_jll[39m
[90m [efcefdf7] [39m[92m+ PCRE2_jll[39m
[90m [83775a58] [39m[92m+ Zlib_jll[39m
[90m [8e850b90] [39m[92m+ libblastrampoline_jll[39m
[90m [8e850ede] [39m[92m+ nghttp2_jll[39m
[90m [3f19e933] [39m[92m+ p7zip_jll[39m
ªtext/plain§cell_idÙ$15187690-0403-11eb-2dfd-fd924faa3513¦kwargs�¢id´PlutoRunner_d1acb81e¤fileÙP/home/runner/.julia/packages/Pluto/6smog/src/runner/PlutoRunner/src/io/stdout.jl¥group¦stdout¥level®LogLevel(-555)§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÉI°persist_js_state·has_pluto_hook_features§cell_idÙ$15187690-0403-11eb-2dfd-fd924faa3513¹depends_on_disabled_cells§runtimeÏ ”I/µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$d8abd2f6-0416-11eb-1c2a-f9157d9760a7Цqueued¤logs�§running¦output†¤body§missing¤mimeªtext/plain¬rootassignee°small_experiment²last_run_timestampËAÚ É²I°persist_js_state·has_pluto_hook_features§cell_idÙ$d8abd2f6-0416-11eb-1c2a-f9157d9760a7¹depends_on_disabled_cells§runtimeÍ7’µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$9374e63c-0493-11eb-0952-4b97512d7cdbЦqueued¤logs�§running¦output†¤bodyÚ¢Great! Feel free to experiment with this function, try giving it a different array as argument. Plots.jl is pretty clever, it even works with an array of strings!
Exercise 1.4
Next, we want to add a new element to our plot: a vertical line. To demonstrate how this works, here we added a vertical line at the maximum value .
To write this function, we first create a base plot , we then modify that plot to add the vertical line, and finally, we return the plot. More on this in the next info box .
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÄqX°°persist_js_state·has_pluto_hook_features§cell_idÙ$9374e63c-0493-11eb-0952-4b97512d7cdb¹depends_on_disabled_cells§runtimeÎ w.µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$2d3bba2a-04a8-11eb-2c40-87794b6aeeacЦqueued¤logs�§running¦output†¤bodyÚyExercise 2.5
👉 Write a function interact! that takes an affected agent of type Agent, an source of type Agent and an infection of type InfectionRecovery. It implements a single (one-sided) interaction between two agents:
If the agent is susceptible and the source is infectious, then the source infects our agent with the given infection probability. If the source successfully infects the other agent, then its num_infected record must be updated.
If the agent is infected then it recovers with the relevant probability.
Otherwise, nothing happens.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÄsÎ!°persist_js_state·has_pluto_hook_features§cell_idÙ$2d3bba2a-04a8-11eb-2c40-87794b6aeeac¹depends_on_disabled_cells§runtimeÎ
®µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$dfb99ace-04cf-11eb-0739-7d694c837d59Цqueued¤logs�§running¦output†¤bodyÚ👉 Allow $p_\text{infection}$ and $p_\text{recovery}$ to be changed interactively and find parameter values for which you observe an epidemic outbreak.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äv™°persist_js_state·has_pluto_hook_features§cell_idÙ$dfb99ace-04cf-11eb-0739-7d694c837d59¹depends_on_disabled_cells§runtimeÎ 2Sµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$271ec5f0-041d-11eb-041b-db46ec1465e0Цqueued¤logs�§running¦output†¤bodyÚNWe have just defined a new type InfectionStatus, as well as names S, I and R that are the (only) possible values that a variable of this type can take.
👉 Define a variable test_status whose value is S.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Är€°persist_js_state·has_pluto_hook_features§cell_idÙ$271ec5f0-041d-11eb-041b-db46ec1465e0¹depends_on_disabled_cells§runtimeÎ Œµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$7946d83a-04a0-11eb-224b-2b315e87bc84Цqueued¤logs�§running¦output†¤bodyÙ0generate_agents (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ê«æ°persist_js_state·has_pluto_hook_features§cell_idÙ$7946d83a-04a0-11eb-224b-2b315e87bc84¹depends_on_disabled_cells§runtimeÎ i®µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$02b0c2fc-0415-11eb-2b40-7bca8ea4eef9Цqueued¤logs�§running¦output†¤bodyÙ*bernoulli (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ É‡i°persist_js_state·has_pluto_hook_features§cell_idÙ$02b0c2fc-0415-11eb-2b40-7bca8ea4eef9¹depends_on_disabled_cells§runtimeÎ Ûõµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$9635c944-0403-11eb-3982-4df509f6a556Цqueued¤logs�§running¦output†¤bodyÚExercse 3.4
👉 What are three simple ways in which you could characterise the magnitude (size) of the epidemic outbreak? Find approximate values of these quantities for one of the runs of your simulation.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äv…ì°persist_js_state·has_pluto_hook_features§cell_idÙ$9635c944-0403-11eb-3982-4df509f6a556¹depends_on_disabled_cells§runtimeÎ f?µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$f3f81172-041c-11eb-2b9b-e99b7b9400edЦqueued¤logs�§running¦output†¤bodyÚ
Note about plotting
Plots.jl has an interesting property: a plot is an object, not an action. Functions like plot, bar, histogram don't draw anything on your screen - they just return a Plots.Plot. This is a struct that contains the description of a plot (what data should be plotted in what way?), not the picture .
So a Pluto cell with a single line, plot(1:10), will show a plot, because the result of the function plot is a Plot object, and Pluto just shows the result of a cell.
Modifying plots
Nice plots are often formed by overlaying multiple plots. In Plots.jl, this is done using the modifying functions : plot!, bar!, vline!, etc. These take an extra (first) argument: a previous plot to modify.
For example, to plot the sin, cos and tan functions in the same view, we do:
function sin_cos_plot()
T = -1.0:0.01:1.0
result = plot(T, sin.(T))
plot!(result, T, cos.(T))
plot!(result, T, tan.(T))
return result
end
💡 This example demonstrates a useful pattern to combine plots:
Create a new plot and store it in a variable
Modify that plot to add more elements
Return the plot
It is recommended that these 3 steps happen within a single cell . This can prevent some strange glitches when re-running cells. There are three ways to group expressions together into a single cell: begin, let and function. More on this later !
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äqv´°persist_js_state·has_pluto_hook_features§cell_idÙ$f3f81172-041c-11eb-2b9b-e99b7b9400ed¹depends_on_disabled_cells§runtimeÎ ‘9µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$4ad11052-042c-11eb-3643-8b2b3e1269bcЦqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Äv™°persist_js_state·has_pluto_hook_features§cell_idÙ$4ad11052-042c-11eb-3643-8b2b3e1269bc¹depends_on_disabled_cells§runtimeÎ !µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$76d117d4-0403-11eb-05d2-c5ea47d06f43Цqueued¤logs�§running¦output†¤bodyٗ👉 Write a function recovery_time(p) that returns the time taken until the person recovers.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äp™F°persist_js_state·has_pluto_hook_features§cell_idÙ$76d117d4-0403-11eb-05d2-c5ea47d06f43¹depends_on_disabled_cells§runtimeÎ pµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$095cbf46-0403-11eb-0c37-35de9562cebcЦqueued¤logs�§running¦output†¤bodyƒ¨elements’’¤name’«"Jazzy Doe"ªtext/plain’«kerberos_id’¦"jazz"ªtext/plain¤typeªNamedTuple¨objectid°eb71b675ed8a366b¤mimeÙ!application/vnd.pluto.tree+object¬rootassignee§student²last_run_timestampËAÚ É@¯-°persist_js_state·has_pluto_hook_features§cell_idÙ$095cbf46-0403-11eb-0c37-35de9562cebc¹depends_on_disabled_cells§runtimeÍOµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$26e2978e-0435-11eb-0d61-25f552d2771eЦqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ävlr°persist_js_state·has_pluto_hook_features§cell_idÙ$26e2978e-0435-11eb-0d61-25f552d2771e¹depends_on_disabled_cells§runtimeÎ )µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$6de37d6c-0415-11eb-1b05-85ac820016c7Цqueued¤logs�§running¦output†¤bodyÙ^👉 What happens for $p=1$ ?
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÄpËC°persist_js_state·has_pluto_hook_features§cell_idÙ$6de37d6c-0415-11eb-1b05-85ac820016c7¹depends_on_disabled_cells§runtimeÎ ßzµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$18d308c4-0424-11eb-176d-49feec6889cfЦqueued¤logs�§running¦output†¤body§missing¤mimeªtext/plain¬rootassigneeªtest_agent²last_run_timestampËAÚ Ê{Ý”°persist_js_state·has_pluto_hook_features§cell_idÙ$18d308c4-0424-11eb-176d-49feec6889cf¹depends_on_disabled_cells§runtimeÍ.ϵpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$46133a74-04b1-11eb-0b46-0bc74e564680Цqueued¤logs�§running¦output†¤bodyÙ'sweep! (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Êäö�°persist_js_state·has_pluto_hook_features§cell_idÙ$46133a74-04b1-11eb-0b46-0bc74e564680¹depends_on_disabled_cells§runtimeÎ Þ µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$771c8f0c-0403-11eb-097e-ab24d0714ad5Цqueued¤logs�§running¦output†¤bodyÚ@Exercise 1.3
👉 Write a function frequencies(data) that calculates and returns the frequencies (i.e. probability distribution) of input data.
The input will be an array of integers, with duplicates , and the result will be a dictionary that maps each occured value to its frequency in the data.
For example,
frequencies([7, 8, 9, 7])
should give
Dict(
7 => 0.5,
8 => 0.25,
9 => 0.25
)
As with any probability distribution, it should be normalised to $1$ , in the sense that the total probability should be $1$ .
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äq°persist_js_state·has_pluto_hook_features§cell_idÙ$771c8f0c-0403-11eb-097e-ab24d0714ad5¹depends_on_disabled_cells§runtimeÎ ¿Rµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$80c2cd88-04b1-11eb-326e-0120a39405eaЦqueued¤logs�§running¦output†¤body…¦prefixÙ:NamedTuple{(:S, :I, :R), Tuple{Missing, Missing, Missing}}¨elementsÜ ’’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object’ ’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object’
’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object’
’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object’’ƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2Ù!application/vnd.pluto.tree+object¤type¥Array¬prefix_short ¨objectid°cf2b1d28459da63f¤mimeÙ!application/vnd.pluto.tree+object¬rootassignee«simulations²last_run_timestampËAÚ Ë`å2°persist_js_state·has_pluto_hook_features§cell_idÙ$80c2cd88-04b1-11eb-326e-0120a39405ea¹depends_on_disabled_cells§runtimeÍCûµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$105d347e-041c-11eb-2fc8-1d9e5eda2be0Цqueued¤logs�§running¦output†¤bodyÙ,frequencies (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ É¼Î¼°persist_js_state·has_pluto_hook_features§cell_idÙ$105d347e-041c-11eb-2fc8-1d9e5eda2be0¹depends_on_disabled_cells§runtimeÎ _Oµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$2c62b4ae-04b3-11eb-0080-a1035a7e31a2Цqueued¤logs�§running¦output†¤bodyƒ¨elements“’¡S’§missingªtext/plain’¡I’§missingªtext/plain’¡R’§missingªtext/plain¤typeªNamedTuple¨objectid°ffffffff7c5378c2¤mimeÙ!application/vnd.pluto.tree+object¬rootassigneeÀ²last_run_timestampËAÚ Ë È¨°persist_js_state·has_pluto_hook_features§cell_idÙ$2c62b4ae-04b3-11eb-0080-a1035a7e31a2¹depends_on_disabled_cells§runtimeÍ�޵published_object_keys�¸depends_on_skipped_cells§erroredÂÙ$6db6c894-0415-11eb-305a-c75b119d89e9Цqueued¤logs�§running¦output†¤bodyÚßWe should always be aware of special cases (sometimes called "boundary conditions"). Make sure not to run the code with $p=0$ ! What would happen in that case? Your code should check for this and throw an ArgumentError as follows:
throw(ArgumentError("..."))
with a suitable error message.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äp³–°persist_js_state·has_pluto_hook_features§cell_idÙ$6db6c894-0415-11eb-305a-c75b119d89e9¹depends_on_disabled_cells§runtimeÎ q˵published_object_keys�¸depends_on_skipped_cells§erroredÂÙ$77db111e-0403-11eb-2dea-4b42ceed65d6Цqueued¤logs�§running¦output†¤bodyÚlExercise 1.6
👉 Use $N = 10,000$ to calculate the mean time $\langle \tau(p) \rangle$ to recover as a function of $p$ between $0.001$ and $1$ (say). Plot this relationship.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Är)=°persist_js_state·has_pluto_hook_features§cell_idÙ$77db111e-0403-11eb-2dea-4b42ceed65d6¹depends_on_disabled_cells§runtimeÎ ù$µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$3d88c056-0414-11eb-0025-05d3aff1588bЦqueued¤logs�§running¦output†¤bodyÙ)correct (generic function with 2 methods)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ì@t%°persist_js_state·has_pluto_hook_features§cell_idÙ$3d88c056-0414-11eb-0025-05d3aff1588b¹depends_on_disabled_cells§runtimeÎ ¬µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$287ee7aa-0435-11eb-0ca3-951dbbe69404Цqueued¤logs�§running¦output†¤bodyÙ4sir_mean_error_plot (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ë÷kð°persist_js_state·has_pluto_hook_features§cell_idÙ$287ee7aa-0435-11eb-0ca3-951dbbe69404¹depends_on_disabled_cells§runtimeÎ Mĵpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$03a85970-0403-11eb-334a-812b59c0905bЦqueued¤logs�§running¦output†¤bodyÙmSubmission by: Jazzy Doe (jazz@mit.edu)
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Éy0
°persist_js_state·has_pluto_hook_features§cell_idÙ$03a85970-0403-11eb-334a-812b59c0905b¹depends_on_disabled_cells§runtimeÎ%Áµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$6d906d0c-0415-11eb-0c1c-b5c0aca841dbЦqueued¤logs�§running¦output†¤bodyÙéHint
Remember to always re-use work you have done previously: in this case you should re-use the function bernoulli.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ì °persist_js_state·has_pluto_hook_features§cell_idÙ$6d906d0c-0415-11eb-0c1c-b5c0aca841db¹depends_on_disabled_cells§runtime΃‹/µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$866299e8-0403-11eb-085d-2b93459cc141Цqueued¤logs�§running¦output†¤bodyٸ👉 We will also need functions is_susceptible and is_infected that check if a given agent is in those respective states.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äsvl°persist_js_state·has_pluto_hook_features§cell_idÙ$866299e8-0403-11eb-085d-2b93459cc141¹depends_on_disabled_cells§runtimeÎ µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$461586dc-0414-11eb-00f3-4984b57bfac5Цqueued¤logs�§running¦output†¤bodyÙ'almost (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÌNU°persist_js_state·has_pluto_hook_features§cell_idÙ$461586dc-0414-11eb-00f3-4984b57bfac5¹depends_on_disabled_cells§runtimeΠεpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$c5156c72-04af-11eb-1106-b13969b036caЦqueued¤logs�§running¦output†¤body‚£msgÙ2Cannot convert Missing to series data for plottingªstacktracešŒªcall_short°error(s::String)§inlined£urlÙbhttps://github.com/JuliaLang/julia/tree/742b9abb4dd4621b667ec5bb3434b8b3602f96fd/base/error.jl#L33¤pathª./error.jl®source_packageÀ¤call°error(s::String)ªlinfo_type³Core.MethodInstance¤line!¤file¨error.jl¤func¥errorparent_moduleÀ¦from_cÂŒªcall_shortÙ _prepare_series_data(x::Missing)§inlined£urlÙGfile:///home/runner/.julia/packages/RecipesPipeline/BGM3l/src/series.jl¤pathÙ@/home/runner/.julia/packages/RecipesPipeline/BGM3l/src/series.jl®source_packageÀ¤callÙ _prepare_series_data(x::Missing)ªlinfo_type³Core.MethodInstance¤line¤file©series.jl¤func´_prepare_series_dataparent_moduleÀ¦from_cÂŒªcall_shortÙB_series_data_vector(x::Missing, plotattributes::Dict{Symbol, Any})§inlined£urlÙGfile:///home/runner/.julia/packages/RecipesPipeline/BGM3l/src/series.jl¤pathÙ@/home/runner/.julia/packages/RecipesPipeline/BGM3l/src/series.jl®source_packageÀ¤callÙB_series_data_vector(x::Missing, plotattributes::Dict{Symbol, Any})ªlinfo_type³Core.MethodInstance¤line$¤file©series.jl¤func³_series_data_vectorparent_moduleÀ¦from_cÂŒªcall_short¯macro expansion§inlinedãurlÀ¤pathÙ@/home/runner/.julia/packages/RecipesPipeline/BGM3l/src/series.jl®source_packageÀ¤call¯macro expansionªlinfo_type§Nothing¤lineÌ�¤file©series.jl¤func¯macro expansionparent_moduleÀ¦from_cÂŒªcall_shortÙxapply_recipe(plotattributes::AbstractDict{Symbol, Any}, #unused#::Type{RecipesPipeline.SliceIt}, x::Any, y::Any, z::Any)§inlined£urlÙHfile:///home/runner/.julia/packages/RecipesBase/BRe07/src/RecipesBase.jl¤pathÙA/home/runner/.julia/packages/RecipesBase/BRe07/src/RecipesBase.jl®source_packageÀ¤callÙxapply_recipe(plotattributes::AbstractDict{Symbol, Any}, #unused#::Type{RecipesPipeline.SliceIt}, x::Any, y::Any, z::Any)ªlinfo_type³Core.MethodInstance¤lineÍ,¤file®RecipesBase.jl¤func¬apply_recipeparent_moduleÀ¦from_cÂŒªcall_shortÙ?_process_userrecipes!(plt::Any, plotattributes::Any, args::Any)§inlined£urlÙLfile:///home/runner/.julia/packages/RecipesPipeline/BGM3l/src/user_recipe.jl¤pathÙE/home/runner/.julia/packages/RecipesPipeline/BGM3l/src/user_recipe.jl®source_packageÀ¤callÙ?_process_userrecipes!(plt::Any, plotattributes::Any, args::Any)ªlinfo_type³Core.MethodInstance¤line&¤file®user_recipe.jl¤funcµ_process_userrecipes!parent_moduleÀ¦from_cÂŒªcall_shortÙ:recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)§inlined£urlÙPfile:///home/runner/.julia/packages/RecipesPipeline/BGM3l/src/RecipesPipeline.jl¤pathÙI/home/runner/.julia/packages/RecipesPipeline/BGM3l/src/RecipesPipeline.jl®source_packageÀ¤callÙ:recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)ªlinfo_type³Core.MethodInstance¤lineH¤file²RecipesPipeline.jl¤func°recipe_pipeline!parent_moduleÀ¦from_cÂŒªcall_shortÙ7_plot!(plt::Plots.Plot, plotattributes::Any, args::Any)§inlined£urlÙ;file:///home/runner/.julia/packages/Plots/uiCPf/src/plot.jl¤pathÙ4/home/runner/.julia/packages/Plots/uiCPf/src/plot.jl®source_packageÀ¤callÙ7_plot!(plt::Plots.Plot, plotattributes::Any, args::Any)ªlinfo_type³Core.MethodInstance¤lineÌߤfile§plot.jl¤func¦_plot!parent_moduleÀ¦from_cÂŒªcall_short©#plot#186§inlinedãurlÀ¤pathÙ4/home/runner/.julia/packages/Plots/uiCPf/src/plot.jl®source_packageÀ¤call©#plot#186ªlinfo_type§Nothing¤linef¤file§plot.jl¤func©#plot#186parent_moduleÀ¦from_cÂŒªcall_short¯top-level scope§inlinedãurlÀ¤pathÙd/home/runner/work/disorganised-mess/disorganised-mess/hw4.jl#==#c5156c72-04af-11eb-1106-b13969b036ca®source_packageÀ¤call¯top-level scopeªlinfo_type§Nothing¤line¤fileÙ.hw4.jl#==#c5156c72-04af-11eb-1106-b13969b036ca¤func»##function_wrapped_cell#396parent_moduleÀ¦from_c¤mimeÙ'application/vnd.pluto.stacktrace+object¬rootassigneeÀ²last_run_timestampËAÚ Ë9¥°persist_js_state·has_pluto_hook_features§cell_idÙ$c5156c72-04af-11eb-1106-b13969b036ca¹depends_on_disabled_cells§runtimeÀµpublished_object_keys�¸depends_on_skipped_cells§erroredÃÙ$c4a8694a-04d4-11eb-1eef-c9e037e6b21fЦqueued¤logs�§running¦output†¤bodyÙ¥Here we go!
Replace missing with your answer.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÌWÇó°persist_js_state·has_pluto_hook_features§cell_idÙ$c4a8694a-04d4-11eb-1eef-c9e037e6b21f¹depends_on_disabled_cells§runtimeÎ µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$1491a078-04aa-11eb-0106-19a3cf1e94b0Цqueued¤logs�§running¦output†¤bodyÙØKeep working on it!
The agent should recover from an infectious state with the right probability.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÌeȽ°persist_js_state·has_pluto_hook_features§cell_idÙ$1491a078-04aa-11eb-0106-19a3cf1e94b0¹depends_on_disabled_cells§runtimeÎ hàµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$c5c7cb86-041b-11eb-3360-45463105f3c9Цqueued¤logs�§running¦output†¤bodyÙ.do_experiment (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ É¤ý—°persist_js_state·has_pluto_hook_features§cell_idÙ$c5c7cb86-041b-11eb-3360-45463105f3c9¹depends_on_disabled_cells§runtimeÎ ,�µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$01341648-0403-11eb-2212-db450c299f35Цqueued¤logs�§running¦output†¤bodyÙB¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äp=°persist_js_state·has_pluto_hook_features§cell_idÙ$01341648-0403-11eb-2212-db450c299f35¹depends_on_disabled_cells§runtimeÎ @ˆµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$48a16c42-0414-11eb-0e0c-bf52bbb0f618Цqueued¤logs�§running¦output†¤bodyÙ%hint (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ì:°persist_js_state·has_pluto_hook_features§cell_idÙ$48a16c42-0414-11eb-0e0c-bf52bbb0f618¹depends_on_disabled_cells§runtimeÎ s¶µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$98beb336-0425-11eb-3886-4f8cfd210288Цqueued¤logs�§running¦output†¤bodyÙ,set_status! (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÊŒkô°persist_js_state·has_pluto_hook_features§cell_idÙ$98beb336-0425-11eb-3886-4f8cfd210288¹depends_on_disabled_cells§runtimeÎ Ä�µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$bb63f3cc-042f-11eb-04ff-a128aec3c378Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Äqʧ°persist_js_state·has_pluto_hook_features§cell_idÙ$bb63f3cc-042f-11eb-04ff-a128aec3c378¹depends_on_disabled_cells§runtimeÎ Yµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$61c00724-0403-11eb-228d-17c11670e5d1Цqueued¤logs�§running¦output†¤bodyÚ™Exercise 4: Reinfection
In this exercise we will re-use our simulation infrastructure to study the dynamics of a different type of infection: there is no immunity, and hence no "recovery" rather, susceptible individuals may now be re-infected
Exercise 4.1
👉 Make a new infection type Reinfection. This has the same two fields as InfectionRecovery (p_infection and p_recovery). However, "recovery" now means "becomes susceptible again", instead of "moves to the R class.
This new type Reinfection should also be a subtype of AbstractInfection. This allows us to reuse our previous functions, which are defined for the abstract supertype.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äv¼V°persist_js_state·has_pluto_hook_features§cell_idÙ$61c00724-0403-11eb-228d-17c11670e5d1¹depends_on_disabled_cells§runtimeÎ �Gµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$9cf9080a-04b1-11eb-12a0-17013f2d37f5Цqueued¤logs�§running¦output†¤bodyÚ,👉 Calculate the mean number of infectious agents of our simulations for each time step. Add it to the plot using a heavier line (lw=3 for "linewidth") by modifying the cell above.
Check the answer yourself: does your curve follow the average trend?
Hint
This exercise requires some creative juggling with arrays, anonymous functions, maps, or whatever you see fit!
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ì Ç¬°persist_js_state·has_pluto_hook_features§cell_idÙ$9cf9080a-04b1-11eb-12a0-17013f2d37f5¹depends_on_disabled_cells§runtimeÎ g;µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$4b3ec86c-0419-11eb-26fd-cbbfdf19afa8Цqueued¤logs�§running¦output†¤body§missing¤mimeªtext/plain¬rootassignee°large_experiment²last_run_timestampËAÚ É¾ÊK°persist_js_state·has_pluto_hook_features§cell_idÙ$4b3ec86c-0419-11eb-26fd-cbbfdf19afa8¹depends_on_disabled_cells§runtimeÍ6ʵpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$61789646-0403-11eb-0042-f3b8308f11baЦqueued¤logs�§running¦output†¤bodyÚ3Exercise 2: Agent-based model for an epidemic outbreak – types
In this and the following exercises we will develop a simple stochastic model for combined infection and recovery in a population, which may exhibit an epidemic outbreak (i.e. a large spike in the number of infectious people). The population is well mixed , i.e. everyone is in contact with everyone else. [An example of this would be a small school or university in which people are constantly moving around and interacting with each other.]
The model is an individual-based or agent-based model: we explicitly keep track of each individual, or agent , in the population and their infection status. For the moment we will not keep track of their position in space; we will just assume that there is some mechanism, not included in the model, by which they interact with other individuals.
Exercise 2.1
Each agent will have its own internal state , modelling its infection status, namely "susceptible", "infectious" or "recovered". We would like to code these as values S, I and R, respectively. One way to do this is using an enumerated type or enum . Variables of this type can take only a pre-defined set of values; the Julia syntax is as follows:
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÄrfI°persist_js_state·has_pluto_hook_features§cell_idÙ$61789646-0403-11eb-0042-f3b8308f11ba¹depends_on_disabled_cells§runtimeÎ ìµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$39dffa3c-0414-11eb-0197-e72b299e9c63Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÌnBÕ°persist_js_state·has_pluto_hook_features§cell_idÙ$39dffa3c-0414-11eb-0197-e72b299e9c63¹depends_on_disabled_cells§runtimeÍ‚µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$f8e05d94-04ac-11eb-26d4-6f1d2c5ed272Цqueued¤logs�§running¦output†¤bodyÙÀGot it!
Your function treats the recovered agent case correctly!
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÌiÌѰpersist_js_state·has_pluto_hook_features§cell_idÙ$f8e05d94-04ac-11eb-26d4-6f1d2c5ed272¹depends_on_disabled_cells§runtimeÎ ŠHµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$88c53208-041d-11eb-3b1e-31b57ba99f05Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Är«C°persist_js_state·has_pluto_hook_features§cell_idÙ$88c53208-041d-11eb-3b1e-31b57ba99f05¹depends_on_disabled_cells§runtimeÎ ¼µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$887d27fc-04bc-11eb-0ab9-eb95ef9607f8Цqueued¤logs�§running¦output†¤bodyÙ+simulation (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÊïÁß°persist_js_state·has_pluto_hook_features§cell_idÙ$887d27fc-04bc-11eb-0ab9-eb95ef9607f8¹depends_on_disabled_cells§runtimeÎ z|µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$d57c6a5a-041b-11eb-3ab4-774a2d45a891Цqueued¤logs�§running¦output†¤bodyÙ.recovery_time (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ É“*x°persist_js_state·has_pluto_hook_features§cell_idÙ$d57c6a5a-041b-11eb-3ab4-774a2d45a891¹depends_on_disabled_cells§runtimeÎ öµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$12cc2940-0403-11eb-19a7-bb570de58f6fЦqueued¤logs‘ˆ¤lineÿ£msg’Ù@[32m[1m Activating[22m[39m new project at `/tmp/jl_tSReBH`
ªtext/plain§cell_idÙ$12cc2940-0403-11eb-19a7-bb570de58f6f¦kwargs�¢id´PlutoRunner_d1acb81e¤fileÙP/home/runner/.julia/packages/Pluto/6smog/src/runner/PlutoRunner/src/io/stdout.jl¥group¦stdout¥level®LogLevel(-555)§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÆŸÁ°persist_js_state·has_pluto_hook_features§cell_idÙ$12cc2940-0403-11eb-19a7-bb570de58f6f¹depends_on_disabled_cells§runtimeÎYHßµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$76f62d64-0403-11eb-27e2-3de58366b619Цqueued¤logs�§running¦output†¤bodyÙçExercise 1.2
👉 Write a function do_experiment(p, N) that runs the function recovery_time N times and collects the results into a vector.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äpä2°persist_js_state·has_pluto_hook_features§cell_idÙ$76f62d64-0403-11eb-27e2-3de58366b619¹depends_on_disabled_cells§runtimeÎ Òçµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$860790fc-0403-11eb-2f2e-355f77dcc7afЦqueued¤logs�§running¦output†¤bodyÚLExercise 2.2
For each agent we want to keep track of its infection status and the number of other agents that it infects during the simulation. A good solution for this is to define a new type Agent to hold all of the information for one agent, as follows:
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ ÄrÞ¹°persist_js_state·has_pluto_hook_features§cell_idÙ$860790fc-0403-11eb-2f2e-355f77dcc7af¹depends_on_disabled_cells§runtimeÎ œµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$b21475c6-04ac-11eb-1366-f3b5e967402dЦqueued¤logs�§running¦output†¤bodyÚPlay around with the test case below to test your function! Try changing the definitions of agent, source and infection. Since we are working with randomness, you might want to run the cell multiple times.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äsç°persist_js_state·has_pluto_hook_features§cell_idÙ$b21475c6-04ac-11eb-1366-f3b5e967402d¹depends_on_disabled_cells§runtimeÎ Q£µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$823364ce-041c-11eb-2467-7ffa4f751527Цqueued¤logs�§running¦output†¤bodyÙ>frequencies_plot_with_maximum (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ Ê@þ¬°persist_js_state·has_pluto_hook_features§cell_idÙ$823364ce-041c-11eb-2467-7ffa4f751527¹depends_on_disabled_cells§runtimeÎ
1µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$619c8a10-0403-11eb-2e89-8b0974fb01d0Цqueued¤logs�§running¦output†¤bodyÚÛExercise 3: Agent-based model for an epidemic outbreak – Monte Carlo simulation
In this exercise we will build on Exercise 2 to write a Monte Carlo simulation of how an infection propagates in a population.
Make sure to re-use the functions that we have already written, and introduce new ones if they are helpful! Short functions make it easier to understand what the function does and build up new functionality piece by piece.
You should not use any global variables inside the functions: Each function must accept as arguments all the information it requires to carry out its task. You need to think carefully about what the information each function requires.
Exercise 3.1
👉 Write a function step! that takes a vector of Agents and an infection of type InfectionRecovery. It implements a single step of the infection dynamics as follows:
Choose two random agents: an agent and a source.
Apply interact!(agent, source, infection).
Return agents.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Ät´°persist_js_state·has_pluto_hook_features§cell_idÙ$619c8a10-0403-11eb-2e89-8b0974fb01d0¹depends_on_disabled_cells§runtimeÎ V•µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$38b1aa5a-04cf-11eb-11a2-930741fc9076Цqueued¤logs�§running¦output†¤bodyÙ3repeat_simulations (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ËBèÕ°persist_js_state·has_pluto_hook_features§cell_idÙ$38b1aa5a-04cf-11eb-11a2-930741fc9076¹depends_on_disabled_cells§runtimeÎ m&µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$8dd97820-04a5-11eb-36c0-8f92d4b859a8Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÄvÏÀ°persist_js_state·has_pluto_hook_features§cell_idÙ$8dd97820-04a5-11eb-36c0-8f92d4b859a8¹depends_on_disabled_cells§runtimeÎ ¦µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$df8547b4-0400-11eb-07c6-fb370b61c2b6Цqueued¤logs�§running¦output†¤bodyÚPExercise 1: Modelling recovery
In this exercise we will investigate a simple stochastic (probabilistic) model of recovery from an infection and the time $\tau$ needed to recover. Although this model can be easily studied analytically using probability theory, we will instead use computational methods. (If you know about this distribution already, try to ignore what you know about it!)
In this model, an individual who is infected has a constant probability $p$ to recover each day. If they recover on day $n$ then $\tau$ takes the value $n$ . Each time we run a new experiment $\tau$ will take on different values, so $\tau$ is a (discrete) random variable. We thus need to study statistical properties of $\tau$ , such as its mean and its probability distribution.
Exercise 1.1 - Probability distributions
👉 Define the function bernoulli(p), which returns true with probability $p$ and false with probability $(1 - p)$ .
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äp€Ç°persist_js_state·has_pluto_hook_features§cell_idÙ$df8547b4-0400-11eb-07c6-fb370b61c2b6¹depends_on_disabled_cells§runtimeÎ Þ&µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$1d3356c4-0403-11eb-0f48-01b5eb14a585Цqueued¤logs�§running¦output†¤bodyÙÔVIDEO
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äp^ú°persist_js_state·has_pluto_hook_features§cell_idÙ$1d3356c4-0403-11eb-0f48-01b5eb14a585¹depends_on_disabled_cells§runtimeÎ Úêµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$82f2580a-04c8-11eb-1eea-bdb4e50eee3bЦqueued¤logs�§running¦output†¤body‚£msgÚ¯MethodError: no method matching Main.workspace#4.Agent()
[0mClosest candidates are:
[0m Main.workspace#4.Agent([91m::Main.workspace#4.InfectionStatus[39m, [91m::Int64[39m) at ~/work/disorganised-mess/disorganised-mess/hw4.jl#==#ae4ac4b4-041f-11eb-14f5-1bcde35d18f2:2
[0m Main.workspace#4.Agent([91m::Any[39m, [91m::Any[39m) at ~/work/disorganised-mess/disorganised-mess/hw4.jl#==#ae4ac4b4-041f-11eb-14f5-1bcde35d18f2:2ªstacktrace‘Œªcall_short¯top-level scope§inlinedãurlÀ¤pathÙd/home/runner/work/disorganised-mess/disorganised-mess/hw4.jl#==#82f2580a-04c8-11eb-1eea-bdb4e50eee3b®source_packageÀ¤call¯top-level scopeªlinfo_type§Nothing¤line¤fileÙ.hw4.jl#==#82f2580a-04c8-11eb-1eea-bdb4e50eee3b¤func»##function_wrapped_cell#354parent_moduleÀ¦from_c¤mimeÙ'application/vnd.pluto.stacktrace+object¬rootassigneeÀ²last_run_timestampËAÚ Ê�êÀ°persist_js_state·has_pluto_hook_features§cell_idÙ$82f2580a-04c8-11eb-1eea-bdb4e50eee3b¹depends_on_disabled_cells§runtimeÀµpublished_object_keys�¸depends_on_skipped_cells§erroredÃÙ$86d98d0a-0403-11eb-215b-c58ad721a90bЦqueued¤logs�§running¦output†¤bodyÚ�We will also need types representing different infections.
Let's define an (immutable) struct called InfectionRecovery with parameters p_infection and p_recovery. We will make it a subtype of an abstract AbstractInfection type, because we will define more infection types later.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äsª‚°persist_js_state·has_pluto_hook_features§cell_idÙ$86d98d0a-0403-11eb-215b-c58ad721a90b¹depends_on_disabled_cells§runtimeÎ )Gµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$dc784864-0430-11eb-1478-d1153e017310Цqueued¤logs�§running¦output†¤bodyÚ‡The frequencies dictionary is difficult to interpret on its own, so instead, we will plot it, i.e. plot $P(\tau = n)$ against $n$ , where $n$ is the recovery time.
Plots.jl comes with a function bar, which does exactly what we want:
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ Äq6¨°persist_js_state·has_pluto_hook_features§cell_idÙ$dc784864-0430-11eb-1478-d1153e017310¹depends_on_disabled_cells§runtimeÎ Sµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$3f5e0af8-0414-11eb-34a7-a71e7aaf6443Цqueued¤logs�§running¦output†¤body…¦prefix«Markdown.MD¨elements›’’Ù2©text/html’’Ù1©text/html’’Ù.©text/html’’Ù+©text/html’’Ù3©text/html’’Ù2©text/html’’Ù3©text/html’’Ù1©text/html’ ’Ù0©text/html’
’ÙAYou got the right answer!
©text/html’’ÙJLet's move on to the next section.
©text/html¤type¥Array¬prefix_short ¨objectid°7e19e2361e36a1ab¤mimeÙ!application/vnd.pluto.tree+object¬rootassignee¤yays²last_run_timestampËAÚ Ì5¯’°persist_js_state·has_pluto_hook_features§cell_idÙ$3f5e0af8-0414-11eb-34a7-a71e7aaf6443¹depends_on_disabled_cells§runtimeÎ £A#µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$3c0528a0-0414-11eb-2f68-a5657ab9e73dЦqueued¤logs�§running¦output†¤bodyÙ,not_defined (generic function with 1 method)¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ ÌK