From cdcb1ec0fdfa1688cb5210a58bddf4b2f5a3c1eb Mon Sep 17 00:00:00 2001 From: jesusmsanchez Date: Sat, 30 Jul 2016 16:47:45 +0200 Subject: [PATCH] Notebook v2 --- SOIL Tutorial.ipynb | 142 ++++++++++++-------------------------------- 1 file changed, 38 insertions(+), 104 deletions(-) diff --git a/SOIL Tutorial.ipynb b/SOIL Tutorial.ipynb index 139ee54..3549e35 100644 --- a/SOIL Tutorial.ipynb +++ b/SOIL Tutorial.ipynb @@ -54,23 +54,11 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 1, "metadata": { "collapsed": false }, - "outputs": [ - { - "ename": "ImportError", - "evalue": "No module named 'matplotlib'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mmatplotlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpyplot\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mnxsim\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mNetworkSimulation\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mnetworkx\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mnx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0msettings\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mImportError\u001b[0m: No module named 'matplotlib'" - ] - } - ], + "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "from nxsim import NetworkSimulation\n", @@ -102,7 +90,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "collapsed": true }, @@ -133,11 +121,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "collapsed": false }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Starting simulations...\n", + "---Trial 0---\n", + "Setting up agents...\n", + "Written 50 items to pickled binary file: sim_01/log.0.state.pickled\n", + "Simulation completed.\n" + ] + } + ], "source": [ "sim = NetworkSimulation(topology=G, states=init_states, agent_type=ControlModelM2,\n", " max_time=settings.max_time, num_trials=settings.num_trials, logging_interval=1.0)\n", @@ -164,11 +164,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "collapsed": false }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Done!\n" + ] + } + ], "source": [ "for x in range(0, settings.number_of_nodes):\n", " for empresa in models.networkStatus[\"agente_%s\"%x]:\n", @@ -199,7 +207,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "collapsed": false }, @@ -251,6 +259,13 @@ "plt.savefig('control_model.png')" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "![alt text](https://raw.githubusercontent.com/gsi-upm/soil/master/control_model.png \"Control model\")" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -267,7 +282,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "collapsed": true }, @@ -310,7 +325,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "collapsed": true }, @@ -373,7 +388,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "collapsed": true }, @@ -514,87 +529,6 @@ "source": [ "This file contains all the variables that can be modified from the simulation. In case of implementing a new spread model, the new variables should be also included in this file." ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "# settings.py\n", - "def init():\n", - "\n", - " network_type=1\n", - " number_of_nodes=1000\n", - " max_time=50\n", - " num_trials=1\n", - " timeout=2\n", - "\n", - " #Zombie model\n", - " bite_prob=0.01 # 0-1\n", - " heal_prob=0.01 # 0-1\n", - "\n", - " #Bass model\n", - " innovation_prob=0.001\n", - " imitation_prob=0.005\n", - "\n", - " #Sentiment Correlation model\n", - " outside_effects_prob = 0.2\n", - " anger_prob = 0.06\n", - " joy_prob = 0.05\n", - " sadness_prob = 0.02\n", - " disgust_prob = 0.02\n", - "\n", - " #Big Market model\n", - " ##Names\n", - " enterprises = [\"BBVA\",\"Santander\", \"Bankia\"]\n", - " ##Users\n", - " tweet_probability_users = 0.44\n", - " tweet_relevant_probability = 0.25\n", - " tweet_probability_about = [0.15, 0.15, 0.15]\n", - " sentiment_about = [0, 0, 0] #Valores por defecto\n", - " ##Enterprises\n", - " tweet_probability_enterprises = [0.3, 0.3, 0.3]\n", - "\n", - " #SISa\n", - " neutral_discontent_spon_prob = 0.04\n", - " neutral_discontent_infected_prob = 0.04\n", - " neutral_content_spon_prob = 0.18\n", - " neutral_content_infected_prob = 0.02\n", - "\n", - " discontent_neutral = 0.13\n", - " discontent_content = 0.07\n", - " variance_d_c = 0.02\n", - "\n", - " content_discontent = 0.009\n", - " variance_c_d = 0.003\n", - " content_neutral = 0.088\n", - "\n", - " standard_variance = 0.055\n", - "\n", - " #Spread Model M2 and Control Model M2\n", - " prob_neutral_making_denier = 0.035\n", - "\n", - " prob_infect = 0.075\n", - "\n", - " prob_cured_healing_infected = 0.035\n", - " prob_cured_vaccinate_neutral = 0.035\n", - "\n", - " prob_vaccinated_healing_infected = 0.035\n", - " prob_vaccinated_vaccinate_neutral = 0.035\n", - " prob_generate_anti_rumor = 0.035\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] } ], "metadata": {