Implement the function `jordan` (respect the header and the specifications). You will need to use the function `dijkstra_shortest_paths` of the LighGraphs library, refer to the doc for more information. If there are multiple minimal vertices, then return the first one.\n",
" \n",
"###### The corrector should be able to write `zero = jordan(g,state,alpha)` with your code."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"function jordan(g, state)\n",
" \"\"\"Find patient zero by mean of the jordan center method.\n",
"\n",
" PARAMS\n",
" g (LightGraph): graph representing the contact network\n",
" state (Array{Int32,1}): disease status of each vertex\n",
"\n",
" RETURNS\n",
" (Int32): the patient zero vertex number \n",
" \"\"\"\n",
" # TODO\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
\n",
" \n",
"
Question 21 (code): Implement the function `distance` (respect the header and the specifications). You will need to use the function `dijkstra_shortest_paths` of the LighGraphs library, refer to the doc for more information. If there are multiple minimal vertices, then return the first one.\n",
" \n",
"###### The corrector should be able to write `zero = distance(g,state,alpha)` with your code."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"function distance(g, state, alpha = 1.0)\n",
" \"\"\"Find patient zero by mean of the distance centrality method.\n",
"\n",
" PARAMS\n",
" g (LightGraph): graph representing the contact network\n",
" state (Array{Int32,1}): disease status of each vertex\n",
" alpha (Float64): curing rate\n",
"\n",
" RETURNS\n",
" (Int32): the patient zero vertex number \n",
" \"\"\"\n",
" # TODO\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
\n",
"\n",
"Question 22 (written): Run the 3 following scripts using your functions `state` and `state` and comment on the results.\n",
" \n",
"The contact network is karat7 for 2 different patient zero and a $50\\times 50$ grid. The real patient zero (\"Z\"), your jordan (\"J\") and distance (\"D\") approximations are appearing in `colorant\"lightblue\"`.\n",
"\n",
"> TODO"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Loading a snapshot of karat7\n",
"@load \"karat7_Q22_1.jld2\" g state pat_zero alpha beta loc_x loc_y\n",
"\n",
"# Run the patient zero finding function\n",
"cent_pat_zero = distance(g, state, alpha)\n",
"jor_pat_zero = jordan(g, state)\n",
"\n",
"# Some display options \n",
"labels = Array{String,1}(undef, nv(g))\n",
"for k = 1:nv(g)\n",
" if state[k] == 1\n",
" labels[k] = \"I\"\n",
" elseif state[k] == 2\n",
" labels[k] = \"R\"\n",
" else\n",
" labels[k] = \"S\"\n",
" end\n",
"end\n",
"\n",
"if cent_pat_zero == jor_pat_zero == pat_zero\n",
" labels[cent_pat_zero] = \"C+J+Z\"\n",
"elseif cent_pat_zero == jor_pat_zero\n",
" labels[cent_pat_zero] = \"C+J\"\n",
" labels[pat_zero] = \"Z\"\n",
"elseif cent_pat_zero == pat_zero\n",
" labels[cent_pat_zero] = \"C+Z\"\n",
" labels[jor_pat_zero] = \"J\"\n",
"elseif jor_pat_zero == pat_zero\n",
" labels[jor_pat_zero] = \"J+Z\"\n",
" labels[cent_pat_zero] = \"C\"\n",
"else\n",
" labels[cent_pat_zero] = \"C\"\n",
" labels[jor_pat_zero] = \"J\"\n",
" labels[pat_zero] = \"Z\"\n",
"end\n",
"\n",
"nodecolor = [colorant\"lightseagreen\", colorant\"orange\", colorant\"purple\"]\n",
"colors = nodecolor[state+ones(Int32, nv(g))]\n",
"colors[pat_zero] = colorant\"lightblue\"\n",
"colors[cent_pat_zero] = colorant\"lightblue\"\n",
"colors[jor_pat_zero] = colorant\"lightblue\"\n",
"\n",
"# Display\n",
"draw(PNG(\"karat7_Q22_1.png\", 20cm, 20cm), gplot(g, loc_x, loc_y, nodefillc = colors, nodelabel = labels))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Loading a snapshot of karat7\n",
"@load \"karat7_Q22_2.jld2\" g state pat_zero alpha beta loc_x loc_y\n",
"\n",
"# Run the patient zero finding function\n",
"cent_pat_zero = distance(g, state, alpha)\n",
"jor_pat_zero = jordan(g, state)\n",
"\n",
"# Some display options \n",
"labels = Array{String,1}(undef, nv(g))\n",
"for k = 1:nv(g)\n",
" if state[k] == 1\n",
" labels[k] = \"I\"\n",
" elseif state[k] == 2\n",
" labels[k] = \"R\"\n",
" else\n",
" labels[k] = \"S\"\n",
" end\n",
"end\n",
"\n",
"if cent_pat_zero == jor_pat_zero == pat_zero\n",
" labels[cent_pat_zero] = \"C+J+Z\"\n",
"elseif cent_pat_zero == jor_pat_zero\n",
" labels[cent_pat_zero] = \"C+J\"\n",
" labels[pat_zero] = \"Z\"\n",
"elseif cent_pat_zero == pat_zero\n",
" labels[cent_pat_zero] = \"C+Z\"\n",
" labels[jor_pat_zero] = \"J\"\n",
"elseif jor_pat_zero == pat_zero\n",
" labels[jor_pat_zero] = \"J+Z\"\n",
" labels[cent_pat_zero] = \"C\"\n",
"else\n",
" labels[cent_pat_zero] = \"C\"\n",
" labels[jor_pat_zero] = \"J\"\n",
" labels[pat_zero] = \"Z\"\n",
"end\n",
"\n",
"nodecolor = [colorant\"lightseagreen\", colorant\"orange\", colorant\"purple\"]\n",
"colors = nodecolor[state+ones(Int32, nv(g))]\n",
"colors[pat_zero] = colorant\"lightblue\"\n",
"colors[cent_pat_zero] = colorant\"lightblue\"\n",
"colors[jor_pat_zero] = colorant\"lightblue\"\n",
"\n",
"# Display\n",
"draw(PNG(\"karat7_Q22_2.png\", 20cm, 20cm), gplot(g, loc_x, loc_y, nodefillc = colors, nodelabel = labels))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Loading a snapshot of grid50\n",
"@load \"grid50_Q22.jld2\" g state pat_zero alpha beta loc_x loc_y\n",
"\n",
"# Run the patient zero finding function\n",
"cent_pat_zero = distance(g, state, alpha)\n",
"jor_pat_zero = jordan(g, state)\n",
"\n",
"# Some display options \n",
"labels = Array{String,1}(undef, nv(g))\n",
"for k = 1:nv(g)\n",
" if state[k] == 1\n",
" labels[k] = \"I\"\n",
" elseif state[k] == 2\n",
" labels[k] = \"R\"\n",
" else\n",
" labels[k] = \"S\"\n",
" end\n",
"end\n",
"\n",
"if cent_pat_zero == jor_pat_zero == pat_zero\n",
" labels[cent_pat_zero] = \"C+J+Z\"\n",
"elseif cent_pat_zero == jor_pat_zero\n",
" labels[cent_pat_zero] = \"C+J\"\n",
" labels[pat_zero] = \"Z\"\n",
"elseif cent_pat_zero == pat_zero\n",
" labels[cent_pat_zero] = \"C+Z\"\n",
" labels[jor_pat_zero] = \"J\"\n",
"elseif jor_pat_zero == pat_zero\n",
" labels[jor_pat_zero] = \"J+Z\"\n",
" labels[cent_pat_zero] = \"C\"\n",
"else\n",
" labels[cent_pat_zero] = \"C\"\n",
" labels[jor_pat_zero] = \"J\"\n",
" labels[pat_zero] = \"Z\"\n",
"end\n",
"\n",
"nodecolor = [colorant\"lightseagreen\", colorant\"orange\", colorant\"purple\"]\n",
"colors = nodecolor[state+ones(Int32, nv(g))]\n",
"colors[pat_zero] = colorant\"lightblue\"\n",
"colors[cent_pat_zero] = colorant\"lightblue\"\n",
"colors[jor_pat_zero] = colorant\"lightblue\"\n",
"\n",
"# Display\n",
"draw(PNG(\"grid50_Q22.png\", 100cm, 100cm), gplot(g, loc_x, loc_y, nodefillc = colors, nodelabel = labels))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.8.0-DEV",
"language": "julia",
"name": "julia-1.8"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.8.0-DEV"
}
},
"nbformat": 4,
"nbformat_minor": 4
}