"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Plotting inferction spread\n",
"\n",
"pos = nx.spectral_layout(G)\n",
"fig = plt.figure(figsize=(15,10))\n",
"for t in xrange(0,timePeriod+1):\n",
" plt.subplot(3,4,t+1)\n",
" nx.draw_spectral(G,\n",
" nodelist=np.nonzero(states[:,t])[0].tolist(),\n",
" node_color = 'r')\n",
" nx.draw_spectral(G,\n",
" nodelist=np.nonzero(1-states[:,t])[0].tolist(),\n",
" node_color = 'b')\n",
" plt.title('t = {0}'.format(t+1))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The branching process"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In simple branchin process (tree of depth $h$ with $k$ leaths per each parent and probability $p$ to infect a neigbour) we are considerring $R_0=pk$ - the basic reproductive number of the infection.
\n",
"* If $R_0 < 1$ infection will stop without reaching the bottom of the tree\n",
"* If $R_0 > 1$ infertion will corrupt all population"
]
},
{
"cell_type": "code",
"execution_count": 159,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1., 3., 5., 6., 5., 2., 0., 0., 0., 0., 0.])"
]
},
"execution_count": 159,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"## Checking of branching branching process\n",
"\n",
"G=nx.balanced_tree(3,7, create_using=nx.DiGraph())\n",
"sp = nx.shortest_path_length(G,0)\n",
"\n",
"timePeriod = 10\n",
"modelParams = {}\n",
"modelParams['t2Recover'] = 1\n",
"modelParams['initInfected'] = [0]\n",
"modelParams['probInfect'] = 0.2\n",
"modelParams['updateInfection'] = False\n",
"\n",
"A = np.array(nx.adj_matrix(G))\n",
"\n",
"states = simulSIS(A, timePeriod, modelParams)\n",
"sum(states)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.9"
}
},
"nbformat": 4,
"nbformat_minor": 0
}